Feed AQICN
Posted: Sat Dec 19, 2020 6:34 pm
Hi, i want to feed AQICN.org, but i dont know how, i think is possible trhough weatherlink API, but really dont know how to handle, either know if i can use any function of the MB? some ideas?
Code: Select all
#!/usr/bin/python -u
from __future__ import print_function
import struct, sys, time, json, subprocess
import requests
# This is the format of the AQI data required. I have PM2.5 and PM10 in an array called Values[].
sensorReadings = [ {'specie':'pm25', 'value': values[0]}, {'specie':'pm10', 'value': values[1]} ]
# Station parameter. This describes, and gives info, about your weather station
stationID = "your_StationID"
cityName = "your_City"
stationName = "your_StationName"
stationWebsite = "your_Website.com"
location = {'latitude': your_decimal_Latitude, 'longitude': your_decimal_Longitude}
station = {'id':stationID, 'city':cityName, 'station':stationName, 'location':location, 'website':stationWebsite}
# User parameter - get yours from https://aqicn.org/data-platform/token/
userToken = "your_stringofhexadecimalcharacters"
# Then Upload the data
params = {'station':station,'readings':sensorReadings,'token':userToken}
request = requests.post( url = "https://aqicn.org/sensor/upload/", json = params)
data = request.json()
if data["status"]!="ok":
print("AQICN.org Something went wrong: %s" % data)
else:
print("AQICN.org data successfully posted: %s, values: %s" % (data, sensorReadings))
quit()