Python Forum
Python loop for posting data to web
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python loop for posting data to web
#2
I think you want to move this outside the loop.
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()
Reply


Messages In This Thread
Python loop for posting data to web - by marciokoko - Jul-17-2023, 07:33 PM
RE: Python loop for posting data to web - by deanhystad - Jul-17-2023, 08:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem posting image to clipboard noel 0 2,218 Sep-26-2020, 10:50 AM
Last Post: noel
  loop through python pandas data frame Johnse 4 2,920 Sep-02-2019, 01:45 AM
Last Post: Johnse
  module logging posting randomly DJ_Qu 2 2,257 May-14-2019, 06:41 AM
Last Post: DJ_Qu
  Posting zip file on HTTP network using Python2.7 deepti92 1 6,833 May-15-2018, 12:41 PM
Last Post: deepti92
  Need help with posting to API website pasi12 4 4,411 Feb-15-2017, 07:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020