Revert using AQI_max and pollen_max

When using AQI_max and pollen_max, the server currently returns the max of the complete set, but we're only displaying the next 12 hours. Also: when not calculating AQI_max and pollen_max ourselves we must have an internet connection always when refreshing the LEDs, otherwise the max values might not be valid anymore.
This commit is contained in:
Admar Schoonen 2022-05-20 20:15:34 +02:00
parent dd69819f38
commit 67760a854c
1 changed files with 56 additions and 18 deletions

View File

@ -75,7 +75,7 @@ unsigned long CCS811_new_state_time = 0;
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
static HTTPClient http; static HTTPClient http;
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=UVI"; static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
static const String baseUrlPrecipitation = "http://target.luon.net:2356//forecast?metrics=precipitation"; static const String baseUrlPrecipitation = "http://target.luon.net:2356//forecast?metrics=precipitation";
@ -125,20 +125,14 @@ typedef struct RainPickerDataArray5 {
float value[5]; float value[5];
} RainPickerDataArray5; } RainPickerDataArray5;
typedef struct RainPickerDataArray1 {
const int len = 1;
long time[1];
float value[1];
} RainPickerDataArray1;
typedef struct RainpickerData { typedef struct RainpickerData {
float lat; float lat;
float lon; float lon;
long time; long time;
RainPickerDataArray24 PAQI; RainPickerDataArray24 PAQI;
RainPickerDataArray1 AQI_max; RainPickerDataArray24 AQI;
RainPickerDataArray1 pollen_max; RainPickerDataArray24 pollen;
RainPickerDataArray5 UVI; RainPickerDataArray5 UVI;
RainPickerDataArray24 precipitation; RainPickerDataArray24 precipitation;
} RainpickerData; } RainpickerData;
@ -173,14 +167,24 @@ void parseJson(String * payload)
n = n + 1; n = n + 1;
} }
if (doc.containsKey("AQI_max")) { n = 0;
rainpickerData.AQI_max.time[0] = doc["AQI_max"]["time"]; for (JsonObject elem : doc["AQI"].as<JsonArray>()) {
rainpickerData.AQI_max.value[0] = doc["AQI_max"]["value"]; if (n >= rainpickerData.AQI.len) {
break;
}
rainpickerData.AQI.time[n] = elem["time"];
rainpickerData.AQI.value[n] = elem["value"];
n = n + 1;
} }
if (doc.containsKey("pollen_max")) { n = 0;
rainpickerData.pollen_max.time[0] = doc["pollen_max"]["time"]; for (JsonObject elem : doc["pollen"].as<JsonArray>()) {
rainpickerData.pollen_max.value[0] = doc["pollen_max"]["value"]; if (n >= rainpickerData.pollen.len) {
break;
}
rainpickerData.pollen.time[n] = elem["time"];
rainpickerData.pollen.value[n] = elem["value"];
n = n + 1;
} }
n = 0; n = 0;
@ -754,7 +758,27 @@ static void updateLeds(void) {
} }
#ifdef SHOW_AQI_LED #ifdef SHOW_AQI_LED
color = colormap(rainpickerData.AQI_max.value[0]); // 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);
r = (color & 0xFF0000) >> 16; r = (color & 0xFF0000) >> 16;
g = (color & 0x00FF00) >> 8; g = (color & 0x00FF00) >> 8;
@ -764,7 +788,21 @@ static void updateLeds(void) {
#endif #endif
#ifdef SHOW_POLLEN_LED #ifdef SHOW_POLLEN_LED
color = colormap(rainpickerData.pollen_max.value[0]); // 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);
r = (color & 0xFF0000) >> 16; r = (color & 0xFF0000) >> 16;
g = (color & 0x00FF00) >> 8; g = (color & 0x00FF00) >> 8;