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);
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";
@ -125,20 +125,14 @@ typedef struct RainPickerDataArray5 {
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;
long time;
RainPickerDataArray24 PAQI;
RainPickerDataArray1 AQI_max;
RainPickerDataArray1 pollen_max;
RainPickerDataArray24 AQI;
RainPickerDataArray24 pollen;
RainPickerDataArray5 UVI;
RainPickerDataArray24 precipitation;
} RainpickerData;
@ -173,14 +167,24 @@ void parseJson(String * payload)
n = n + 1;
}
if (doc.containsKey("AQI_max")) {
rainpickerData.AQI_max.time[0] = doc["AQI_max"]["time"];
rainpickerData.AQI_max.value[0] = doc["AQI_max"]["value"];
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;
}
if (doc.containsKey("pollen_max")) {
rainpickerData.pollen_max.time[0] = doc["pollen_max"]["time"];
rainpickerData.pollen_max.value[0] = doc["pollen_max"]["value"];
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;
}
n = 0;
@ -754,7 +758,27 @@ static void updateLeds(void) {
}
#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;
g = (color & 0x00FF00) >> 8;
@ -764,7 +788,21 @@ static void updateLeds(void) {
#endif
#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;
g = (color & 0x00FF00) >> 8;