enviroplus-python
enviroplus-python copied to clipboard
Update luftdaten.py with better error handling and logging
I can see a few improvements to luftdaten.py which may be worth incorporating:
- Moving
update_time = time.time()to beforesend_to_luftdatenso 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. - 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
- 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.