1
0
Fork 0
Browse Source

remove 60 sec. delay at startup and add add new (cli) exception message.

The removal of the delay is in preparation of moving the program to a
Systemd service -- instead of a '@reboot' cronjob. By doing that, the need
to wait for the network stack on the Raspberry Pi to start is a built-in
feature.

The change to Systemd is becuase the program would terminate when it hits
the 'max. requests exceeded' exception in the 'requests' module (Python).
Having spoke to Nic (lead artist), she has stated she has a preference for
the program to be requesting the latest light readings or nothing at all.
The 'backoff' features which come with the 'requests' module will stop the
program from crashing but at the possibility of the having the Relays be
out-of-sync -- whilst still looking like it's working -- with the latest
light readings produced by the Light Meters in the factory and what's been
delivered to the server (Midpoint).

To be fair, this problem only arose when I ran the two gallery Relays, one
Light Meter and one instance of Eyes and Ears from the same location (my
flat). This wouldn't be the case in the when the exhibiton is live. Either
way, Systemd it is.

The natural process of waiting for the program to restart (with added delay
in Systemd service file if wanted) naturally allows the system to 'backoff'
but it keeps the all-or-nothing aspect Nic prefers.

The exception message is a minor change. It's there just to make it easier
to determine if the program is terminating because of the 'max. requests
exceeded' exception. I added it to the generic exception for ease more than
anything else. I can catch other exceptions whilst expecting the 'max.
requests' one. This is not the best approach to programming but the
trade-off between project goals and budget make me think this is ok (for
now). It is what it is.
unstable
gallery2 3 years ago
parent
commit
3a28c3b001
  1. 11
      relay.py
  2. 2
      startup.sh

11
relay.py

@ -35,18 +35,19 @@ def main():
# print(the_reading) # For testing.
if the_reading > 48:
# Print for testing.
# print(f"[INFO] Light is on -- {the_reading}.")
print(f"[INFO] Light is on -- {the_reading}.")
GPIO.output(relay_pin, GPIO.HIGH)
else:
# Print for testing.
# print(f"[INFO] Light is off -- {the_reading}.")
GPIO.output(relay_pin, GPIO.LOW)
except KeyboardInterrupt:
print("Keyboard Interrupt: quitting program.")
except:
print("Error updating light reading...")
print("[INFO] KEYBOARD INTERRUPT: quitting program.")
except Exception as e:
print(f"[ERROR] GENERAL EXCEPTION: {e}")
finally:
print("Cleaning up GPIO before closing...")
print("[INFO] Terminating relay.py...")
print("[INFO] Cleaning up GPIO before closing...")
GPIO.cleanup()
if __name__ == "__main__" :

2
startup.sh

@ -19,7 +19,7 @@
# reliable/consistent behaviour is my preference over "fast start-up
# times".
sleep 60
#sleep 60
logDate=$(date '+%Y-%m-%dT%TZ')
logFile="/home/rtrp/logs/startup-logs.txt"