ຂັ້ນຕອນທໍາອິດແມ່ນເພື່ອເອົາ token ຈາກ ຫນ້າ data-platform .
ເມື່ອທ່ານມີ token ຂອງທ່ານເອງ, ທ່ານສາມາດນໍາໃຊ້ສະຄິບຕໍ່ໄປນີ້ເພື່ອອັບໂຫລດຂໍ້ມູນຂອງທ່ານ. ຫຼັງຈາກທີ່ທ່ານອັບໂຫຼດຂໍ້ມູນສະຖານີທໍາອິດຂອງທ່ານ, ໄປທີ່ aqicn.org/data-feed/verification/ ເພື່ອກໍານົດຄ່າສະຖານີຂອງທ່ານແລະກວດສອບຂໍ້ມູນທີ່ອັບໂຫຼດໄດ້.
ເວທີຊອບແວທີ່ຮອງຮັບ:
ພວກເຮົາສະຫນອງຄວາມພ້ອມທີ່ຈະນໍາໃຊ້ຊອບແວສໍາລັບ 3 ເວທີທີ່:
- Arduino : ຖ້າທ່ານມີ CPU Arduino, ໃຫ້ໃຊ້ຊອຟແວທີ່ພ້ອມໃຊ້ແລ້ວໃນ github.com ທີ່ aqicn/gaia-a08-arduino .
- Python: ໃຊ້ code-snippet ຂ້າງລຸ່ມນີ້
- ເສັ້ນຄໍາສັ່ງ (CURL): ໃຊ້ລະຫັດ-snippet ຂ້າງລຸ່ມນີ້
ຖ້າຫາກວ່າທ່ານບໍ່ມີສະຖານີຕິດຕາມກວດກາໃດຫນຶ່ງ, ແລະຢາກຈະໄດ້ຮັບຫນຶ່ງ, ໃຫ້ກວດເບິ່ງສະຖານີຕິດຕາມຄຸນນະພາບອາກາດ GAIA ຂອງພວກເຮົາ.
ຖ້າທ່ານຕ້ອງການສະຖານີ DIY, ໃຫ້ກວດເບິ່ງ GAIA A08 .
--
ລະຫັດຕົວຢ່າງ (python)
import requests  
 
# Sensor parameter   
sensorReadings = [   
	{'specie':'pm25', 'value': 393.3},  
	{'specie':'pm10', 'value': 109.3}  
] 
 
# Station parameter   
station = { 
	'id':		"station-001",  
	'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) 
ລະຫັດຕົວຢ່າງ (curl)
curl -X POST https://aqicn.org/sensor/upload -H 'Content-Type: application/json' --data '{\ 
"token": "dummy-token-for-test-purpose-only",\ 
"station": { "id": "station-001" },\ 
"readings": [{"specie":"pm2.5", "value": 393.3}]\ 
}'ລະຫັດຕົວຢ່າງ (arduino)
#include <WiFi.h> 
#include <HTTPClient.h> 
#include <ArduinoJson.h> 
 
#define LATITUDE 28.7501 
#define LONGITUDE 77.1177 
 
void upload(float pm25_concentration, float pm10_concentration, const char * token) 
{ 
 
    static char stationID[32]; 
    uint64_t efuseMac = ESP.getEfuseMac(); 
    uint16_t chip = (uint16_t)(efuseMac >> 32); 
    snprintf(stationID, 32, "station-%x", chip); 
 
    doc["token"] = token; 
    doc["station"]["id"] = stationID; 
 
    doc["station"]["location"]["latitude"] = LATITUDE; 
    doc["station"]["location"]["longitude"] = LONGITUDE; 
 
    doc["readings"][0]["specie"] = "pm25"; 
    doc["readings"][0]["value"] = pm25_concentration; 
    doc["readings"][0]["unit"] = "µg/m3"; 
 
    doc["readings"][1]["specie"] = "pm10"; 
    doc["readings"][1]["value"] = pm10_concentration; 
    doc["readings"][1]["unit"] = "µg/m3"; 
 
    static char json_body[1024]; 
    serializeJson(doc, json_body); 
 
    HTTPClient http; 
    http.begin("https://aqicn.org/sensor/upload"); 
    http.addHeader("Content-Type", "application/json"); 
    int httpResponseCode = http.POST(json_body); 
 
    if (httpResponseCode > 0) 
    { 
 
        String response = http.getString(); 
        Serial.println(httpResponseCode); 
        Serial.println(response); 
    } 
    else 
    { 
 
        Serial.print("Error on sending POST: "); 
        Serial.println(httpResponseCode); 
    } 
 
    http.end(); 
} 
  
     