import http.client import urllib.parse import time
key = "WK3MUELXXVM8VE7F"
def thermometer(): while True:
temp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1000
params = urllib.parse.urlencode({'field1': temp, 'key': key})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = http.client.HTTPConnection("api.thingspeak.com:80")
try:
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
print(temp)
print(response.status, response.reason)
data = response.read()
conn.close()
except Exception as e:
print("Connection failed:", str(e))
time.sleep(15)
if name == " main ":
while True:
thermometer()