enviroplus-python icon indicating copy to clipboard operation
enviroplus-python copied to clipboard

Update luftdaten.py with better error handling and logging

Open Gadgetoid opened this issue 5 years ago • 0 comments

I can see a few improvements to luftdaten.py which may be worth incorporating:

  1. Moving update_time = time.time() to before send_to_luftdaten so the data sending function has the full 145??? seconds to retry sending the values. Though I can't see any fearture for sending a timestamp to luftdaten.
  2. Adding python logging, so we can log success/failure states and other info with timestamps, this is illustrated nicely here: https://github.com/pimoroni/enviroplus-python/blob/7452b88562c25344ecf9e8eed9b13325d4aef4e6/examples/all-in-one-no-pm.py#L22-L31
  3. Catch exceptions when posting data to luftdaten as raised in #79 - should attempt to send data multiple times (with a small delay) and output a log entry in case of failure.

Need to ensure instructions aren't broken: https://learn.pimoroni.com/tutorial/sandyj/enviro-plus-and-luftdaten-air-quality-station

Should probably attempt to log to /tmp/luftdaten.log since the instructions linked above do not pipe error output anywhere useful.

Additionally it might be worth authoring a systemd unit for running and maintaining the script.

Gadgetoid avatar Aug 05 '20 11:08 Gadgetoid