-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.py
65 lines (32 loc) · 1015 Bytes
/
upload.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import sys
import datetime
from SDSLinux import *
AQI = loop(USBPORT)
sample = open('/home/pi/data/airquality.txt', 'a')
print(str(datetime.datetime.now()) + " PM2.5: "+str(AQI[0])," PM10: "+str(AQI[1]), file = sample)
sample.close()
sensorReadings = [
{'specie':'pm25', 'value': AQI[0]},
{'specie':'pm10', 'value': AQI[1]}
]
# Station parameter
station = {
'id': "SW-Karjat",
'name': "Still Waters",
'location': {
'latitude': 18.9323,
'longitude': 73.34170
}
}
# User parameter - get yours from https://aqicn.org/data-platform/token/
userToken = sys.argv[1]
# Then Upload the data
params = {'station':station,'readings':sensorReadings,'token':userToken}
request = requests.post( url = "https://aqicn.org/sensor/upload/", json = params)
#print(request.text)
data = request.json()
if data["status"]!="ok":
print("Something went wrong: %s" % data)
else:
print("Data successfully posted: %s"%data)