Move Arduino_JSON to AirGradient libries

This commit is contained in:
Phat Nguyen
2024-04-11 09:29:29 +07:00
parent bd1197971f
commit 1d6a0a06c0
24 changed files with 5411 additions and 41 deletions

View File

@ -12,9 +12,6 @@ Outdoor Monitor: https://www.airgradient.com/outdoor/
Build Instructions:
https://www.airgradient.com/documentation/diy-v4/
Following libraries need to be installed:
"Arduino_JSON" by Arduino version 0.2.0
Please make sure you have esp8266 board manager installed. Tested with
version 3.1.2.
@ -35,7 +32,6 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#include "AgSchedule.h"
#include "AgWiFiConnector.h"
#include <AirGradient.h>
#include <Arduino_JSON.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
@ -166,12 +162,8 @@ void loop() {
}
static void sendDataToAg() {
JSONVar root;
root["wifi"] = WiFi.RSSI();
root["boot"] = 0;
// delay(1500);
if (apiClient.postToServer(JSON.stringify(root))) {
if (apiClient.sendPing(wifiConnector.RSSI(), 0)) {
// Ping Server succses
} else {
// Ping server failed
@ -327,22 +319,22 @@ static void tempHumUpdate() {
}
static void sendDataToServer() {
JSONVar root;
root["wifi"] = WiFi.RSSI();
if (co2Ppm >= 0) {
root["rco2"] = co2Ppm;
String wifi = "\"wifi\":" + String(WiFi.RSSI());
String rco2 = "";
if(co2Ppm >= 0){
rco2 = ",\"rco2\":" + String(co2Ppm);
}
if (pm25 >= 0) {
root["pm02"] = pm25;
String pm02 = "";
if(pm25) {
pm02 = ",\"pm02\":" + String(pm25);
}
if (temp > -1001) {
root["atmp"] = ag.round2(temp);
}
if (hum >= 0) {
root["rhum"] = hum;
String rhum = "";
if(hum >= 0){
rhum = ",\"rhum\":" + String(rhum);
}
String payload = "{" + wifi + rco2 + pm02 + rhum + "}";
if (apiClient.postToServer(JSON.stringify(root)) == false) {
if (apiClient.postToServer(payload) == false) {
Serial.println("Post to server failed");
}
}

View File

@ -14,9 +14,6 @@ https://www.airgradient.com/documentation/one-v9/ Build Instructions:
AirGradient Open Air:
https://www.airgradient.com/documentation/open-air-pst-kit-1-3/
The codes needs the following libraries installed:
"Arduino_JSON" by Arduino version 0.2.0
Please make sure you have esp32 board manager installed. Tested with
version 2.0.11.
@ -53,7 +50,6 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#include "OpenMetrics.h"
#include "WebServer.h"
#include <AirGradient.h>
#include <Arduino_JSON.h>
#include <WebServer.h>
#define LED_BAR_ANIMATION_PERIOD 100 /** ms */
@ -416,10 +412,6 @@ static void ledBarEnabledUpdate(void) {
}
static void sendDataToAg() {
JSONVar root;
root["wifi"] = wifiConnector.RSSI();
root["boot"] = measurements.bootCount;
/** Change oledDisplay and led state */
if (ag->isOne()) {
stateMachine.displayHandle(AgStateMachineWiFiOkServerConnecting);
@ -443,7 +435,7 @@ static void sendDataToAg() {
"task_led", 2048, NULL, 5, NULL);
delay(1500);
if (apiClient.postToServer(JSON.stringify(root))) {
if (apiClient.sendPing(wifiConnector.RSSI(), measurements.bootCount)) {
if (ag->isOne()) {
stateMachine.displayHandle(AgStateMachineWiFiOkServerConnected);
}