Perhaps worth to add a timeout parameter to the requests.post
https://requests.readthedocs.io/en/late ... /#timeouts
This should avoid the problem: 'when it does fail to send the requests.post. My old router would jam up sometimes'
Next I would run the code only once, started by systemd. In the code, use a scheduler to run your jobs.
https://apscheduler.readthedocs.io/en/3.x/
Here an untested sample
https://requests.readthedocs.io/en/late ... /#timeouts
This should avoid the problem: 'when it does fail to send the requests.post. My old router would jam up sometimes'
Next I would run the code only once, started by systemd. In the code, use a scheduler to run your jobs.
https://apscheduler.readthedocs.io/en/3.x/
Here an untested sample
Code:
# removed some import for clarityimport threadingtry: import apscheduler.schedulers.backgroundexcept ModuleNotFoundError : print( "install apscheduler !!! pip install apscheduler")LED2 = LED(26) # Red LED to indicate low level.LED1 = LED(16) # Green LED to indicate high level.def measure_weight(): # shortened passif __name__ == "__main__": # initial execution immediate after starting the code measure_weight() scheduler = apscheduler.schedulers.background.BackgroundScheduler() scheduler.start() job = scheduler.add_job(measure_weight, 'cron', minute=0) wait = threading.Event() try: wait.wait() except KeyboardInterrupt: pass scheduler.shutdown() LED2.off() LED1.off()Statistics: Posted by ghp — Wed Mar 12, 2025 6:19 pm