Jul-17-2023, 08:39 PM
(This post was last modified: Jul-17-2023, 08:39 PM by deanhystad.)
I think you want to move this outside the loop.
I also think you should remove this from the loop and have it only happen when the loop is done.
I don't know what you want to do with the LED's, so I turn them on for as long as the program is running.
ch = thingspeak.Channel(channel_id, api_key)I wouldn't be surprised if disposing of a channel object is messing up your connection.
I also think you should remove this from the loop and have it only happen when the loop is done.
leds.off()You should also put the keyboard interrupt exception handler back in.
I don't know what you want to do with the LED's, so I turn them on for as long as the program is running.
#!/usr/local/bin/python3 from envirophat import light, motion, weather, leds import thingspeak from datetime import datetime import time channel_id="123" api_key="456" ch = thingspeak.Channel(channel_id, api_key) leds.on() # ?? try: while True: cas = datetime.now().isoformat() lux = light.light() print(cas, lux) print(ch.update({'field1': cas, 'field2': lux})) # Maybe the reply has useful info time.sleep(20) # Speed up for testing except KeyboardInterrupt: pass leds.off()