-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cloud.py
29 lines (27 loc) · 947 Bytes
/
Cloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#This code performs the operation of sending the data to the cloud by retriving the data from the raspberry-pi
from delimiter import *
import http.client
import urllib.request,urllib.parse,urllib.error
import time
key = "5K4XG9COY42DGYAC"
a=data[0]
b=data[1]
c=price
def billing():
while True:
global a,b,c
values = {'field1':a,'field2':b,'field3':c,'key':'5K4XG9COY42DGYAC'}
params = urllib.parse.urlencode(values)
headers = {"Content-typZZe": "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()
data = response.read()
conn.close()
except:
print("connection failed")
break
if __name__ == "__main__":
while True:
billing()