0

I'm trying to upload some data into thingspeak from DHT11 sensor.

Here is the code:

import sys
import Adafruit_DHT 
import urllib

while True:
   print("STARTS UPLOADING...")

   baseURL = "https://api.thingspeak.com/update?api_key=0SKA2NQJ31NBMJA1"

   try:
      humidity, temperature = Adafruit_DHT.read(11,4)
      hum = str(humidity)
      temp = str(temperature)
      f = urllib.urlopen(baseURL +"&field1="+temp+"&field2="+hum)
      print(f.read())
      print(temp+ " " + hum+ " " )
      f.close()
   except:
      print('exiting.')
      break

Whenever I execute this program, it does not enter the data into thingspeak. It just exits.

Need some immediate help.

1

Looking at the official documentation here and the example here I believe you need to perform a HTTP POST to upload the data rather than the default GET you have used.

There is a related question on stackoverflow

There appears to be a dedicated python library for thingspeak here which might be worth while checking out. The docs for that are here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.