The first step is to get a token from data-platform page.
Once you have your own token, you can use the following script to upload your data. After you upload your first station data, go to aqicn.org/data-feed/verification/ to configure your stations and verify the uploaded data.
Sample code (python)
import requests
# Sensor parameter
sensorReadings = [
{'specie':'pm25', 'value': 393.3},
{'specie':'pm10', 'value': 109.3}
]
# Station parameter
station = {
'id': "iitk-station-01",
'name': "IIT Kanpur - Hall 1",
'location': {
'latitude': 28.7501,
'longitude': 77.1177
}
}
# User parameter - get yours from https://aqicn.org/data-platform/token/
userToken = "dummy-token-for-test-purpose-only"
# 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)
Sample code (curl)
curl -X POST https://aqicn.org/sensor/upload -H 'Content-Type: application/json' --data '{\
"token": "dummy-token-for-test-purpose-only",\
"station": { "id": "outdoor-station-01", },\
"readings": [{"specie":"pm2.5", "value": 393.3}]\
}'
API Options
Parameter | Type | Optional/Mandatory | Explanations |
---|---|---|---|
token | string | mandatory | Get your own token from aqicn.org/data-platform/token. |
station | |||
station.id | string | mandatory | Unique station ID - you can select any name with max 128 characters. This name is only used internally for you. No one else will see this ID |
station.name | string | optional | Name of the station - could be for instance the name of your building, the name of a street, the name of a university departement, the code of your personal weather station. This name will be used as the suffix for your station URL. |
station.latitude | float | optional | Longitude of your station |
station.longitude | float | optional | Latitude of your station |
organization | |||
org.website | string | optional | If you have a website with more information about your station/sensor, we will add this link on our map when used see your station |
org.name | string | optional | If you specify a website, this "organization name" will be associated to the website. |
readings | |||
readings[*].specie | string | mandatory | Name of the pollutant your are reporting. For gas sensors, use: "pm2.5", "pm10", "pm1.0", ... For gaz sensor, use: "co2", "no2", "o3", ... For weather sensor, use: "temp", "humidity", "pressure", "wind speed", "wind gust", "wind direction", .. You can actually use any specie name you want. When you station is validated, the names will be normalized in our system. |
readings[*].value | float | mandatory | If your sensor is producing values every second, and you only upload every minute, this value should be the average of all the values read during the past minute. |
readings[*].unit | string | optional | Unit of the value. Eg "mg/m3" for dust sensor, ppb for gas sensors, C for temp sensor.. |
readings[*].time | string | optional | Date and Time of the reading in ISO 8601 format |
readings[*].min | float | optional | If the reading values are based on the averaging of several values, then this correspond to the min value of all values used for the averaging. |
readings[*].max | float | optional | If the reading values are based on the averaging of several values, then this correspond to the max value of all values used for the averaging. |
readings[*].median | float | optional | If the reading values are based on the averaging of several values, then this correspond to the median value of all values used for the averaging. |
readings[*].stddev | float | optional | If the reading values are based on the averaging of several values, then this correspond to the standard deviation of all values used for the averaging. |
readings[*].averaging | float | optional | If the above values are based on the averaging of several values, then this correspond to the duration, in seconds, of the averaging period. For instance, use 60 for a minute average data and 3600 for hourly average. |
Example 1
{
"token": "......",
"station": {
"id": "outdoor-station-01",
"name": "HCPA Santa Cecília",
"latitude": 103.37893,
"longitude": 43.17108,
},
"org": {
"website":"https://pacto.upsensor.com/",
"name":"Porto Ar Alegre",
},
"readings": [
{"time":"2022-06-25T08:34:06+09:00","specie":"pm2.5", "value": 393.3, "unit":"mg/m3", "min":390.3, "max": 402.3, "stddev": 0.332},
{"time":"2022-06-25T08:34:06+09:00","specie":"pm10", "value": 109.3, "unit":"mg/m3"},
{"time":"2022-06-25T08:34:06+09:00","specie":"co2", "value": 459.3, "unit":"ppb"},
{"time":"2022-06-25T08:34:06+09:00","specie":"temp", "value": 26.8, "unit":"C"},
]
}
Example 2
{
"token": "......",
"station": {
"id": "outdoor-station-01",
},
"readings": [
{"specie":"pm2.5", "value": 393.3}
]
}