Use AQI_max and pollen_max (untested)

This commit is contained in:
Admar Schoonen 2022-05-15 07:45:31 +02:00
parent 031bce3ae3
commit 20557e019c
1 changed files with 17 additions and 68 deletions

View File

@ -75,9 +75,7 @@ unsigned long CCS811_new_state_time = 0;
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
static HTTPClient http;
//static const String baseUrlAQI = "http://luon.net:2355/forecast?formula=[\"PAQI\",\"AQI\",\"pollen\",\"UVI\"]";
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
//static const String baseUrlPrecipitation = "http://luon.net:2355/forecast?formula=[\"precipitation\"]";
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=UVI";
static const String baseUrlPrecipitation = "http://target.luon.net:2356//forecast?metrics=precipitation";
@ -121,27 +119,26 @@ typedef struct RainPickerDataArray24 {
float value[24];
} RainPickerDataArray24;
typedef struct RainPickerDataArray12 {
const int len = 12;
long time[12];
float value[12];
} RainPickerDataArray12;
typedef struct RainPickerDataArray5 {
const int len = 5;
long time[5];
float value[5];
} RainPickerDataArray5;
typedef struct RainPickerDataArray1 {
const int len = 1;
long time[1];
float value[1];
} RainPickerDataArray1;
typedef struct RainpickerData {
float lat;
float lon;
float time;
long time;
RainPickerDataArray24 PAQI;
RainPickerDataArray24 AQI;
RainPickerDataArray24 pollen;
RainPickerDataArray1 AQI_max;
RainPickerDataArray1 pollen_max;
RainPickerDataArray5 UVI;
RainPickerDataArray24 precipitation;
} RainpickerData;
@ -176,26 +173,12 @@ void parseJson(String * payload)
n = n + 1;
}
n = 0;
for (JsonObject elem : doc["AQI"].as<JsonArray>()) {
if (n >= rainpickerData.AQI.len) {
break;
}
rainpickerData.AQI.time[n] = elem["time"];
rainpickerData.AQI.value[n] = elem["value"];
n = n + 1;
}
n = 0;
for (JsonObject elem : doc["pollen"].as<JsonArray>()) {
if (n >= rainpickerData.pollen.len) {
break;
}
rainpickerData.pollen.time[n] = elem["time"];
rainpickerData.pollen.value[n] = elem["value"];
n = n + 1;
}
rainpickerData.AQI_max.time[0] = doc["AQI_max"]["time"];
rainpickerData.AQI_max.value[0] = doc["AQI_max"]["value"];
rainpickerData.pollen_max.time[0] = doc["pollen"]["time"];
rainpickerData.pollen_max.value[0] = doc["pollen"]["value"];
n = 0;
for (JsonObject elem : doc["UVI"].as<JsonArray>()) {
if (n >= rainpickerData.UVI.len) {
@ -767,27 +750,7 @@ static void updateLeds(void) {
}
#ifdef SHOW_AQI_LED
// calculate AQI max value for next 12 hours
uint32_t AQI_max_value = 0;
//Serial.println("AQI:");
for (n = 0; n < rainpickerData.AQI.len; n++) {
/*Serial.print(" ");
Serial.print(rainpickerData.AQI.time[n]);
Serial.print(": ");
Serial.println(rainpickerData.AQI.value[n]);*/
if (rainpickerData.time - rainpickerData.AQI.time[n] >= 60 * 60) {
continue;
}
if (rainpickerData.AQI.time[n] >= rainpickerData.time + PAQI_NUM_LEDS * 60 * 60) {
break;
}
if (rainpickerData.AQI.value[n] > AQI_max_value) {
AQI_max_value = rainpickerData.AQI.value[n];
}
}
//Serial.print("AQI max value: ");
//Serial.println(AQI_max_value);
color = colormap(AQI_max_value);
color = colormap(rainpickerData.AQI_max.value[0]);
r = (color & 0xFF0000) >> 16;
g = (color & 0x00FF00) >> 8;
@ -797,21 +760,7 @@ static void updateLeds(void) {
#endif
#ifdef SHOW_POLLEN_LED
// calculate pollen max value for next 12 hours
uint32_t pollen_max_value = rainpickerData.pollen.value[0];
for (n = 0; n < rainpickerData.pollen.len; n++) {
if (rainpickerData.time - rainpickerData.pollen.time[n] >= 60 * 60) {
continue;
}
if (rainpickerData.pollen.time[n] >= rainpickerData.time + PAQI_NUM_LEDS * 60 * 60) {
break;
}
if (rainpickerData.pollen.value[n] > pollen_max_value) {
pollen_max_value = rainpickerData.pollen.value[n];
}
}
color = colormap(pollen_max_value);
color = colormap(rainpickerData.pollen_max.value[0]);
r = (color & 0xFF0000) >> 16;
g = (color & 0x00FF00) >> 8;