|
10 | 10 | - WiFiManager: https://github.com/tzapu/WiFiManager |
11 | 11 | - ArduinoMqttClient (if MQTT is defined) |
12 | 12 | */ |
13 | | -#define VERSION "v4.5" |
| 13 | +#define VERSION "v4.6" |
14 | 14 |
|
15 | 15 | #define HEIGHT_ABOVE_SEA_LEVEL 50 // Berlin |
16 | 16 | #define TZ_DATA "CET-1CEST,M3.5.0,M10.5.0/3" // Europe/Berlin time zone from https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv |
@@ -84,7 +84,7 @@ SensirionI2CScd4x scd4x; |
84 | 84 |
|
85 | 85 | RTC_DATA_ATTR bool USB_ACTIVE = false, initDone = false, BatteryMode = false, comingFromDeepSleep = false; |
86 | 86 | RTC_DATA_ATTR bool LEDonBattery, LEDonUSB, useSmoothLEDcolor, invertDisplay, useFahrenheit, useWiFi, english; |
87 | | -RTC_DATA_ATTR int ledbrightness, HWSubRev, font; |
| 87 | +RTC_DATA_ATTR uint8_t ledbrightness, HWSubRev, font; |
88 | 88 | RTC_DATA_ATTR float maxBatteryVoltage; |
89 | 89 |
|
90 | 90 | /* TEST_MODE */ |
@@ -484,51 +484,24 @@ void rainbowMode() { |
484 | 484 |
|
485 | 485 | RTC_DATA_ATTR uint8_t hour = 0; |
486 | 486 | RTC_DATA_ATTR uint8_t halfminute = 0; |
487 | | -RTC_DATA_ATTR uint16_t measurements[24][120]; |
488 | | -void saveMeasurement(uint16_t co2) { |
| 487 | +#define NUM_HOURS 16 // ESP32-S2 slow RTC memory limitation |
| 488 | +RTC_DATA_ATTR SensorData measurements[NUM_HOURS][120]; |
| 489 | +void saveMeasurement(uint16_t co2, float temperature, float humidity) { |
489 | 490 | if (halfminute == 120) { |
490 | 491 | halfminute=0; |
491 | 492 | hour++; |
492 | 493 | } |
493 | | - if (hour == 24) { |
494 | | - for (int i=0; i<23; ++i) memcpy(measurements[i], measurements[i + 1], sizeof(uint16_t) * 120); |
495 | | - hour = 23; |
| 494 | + if (hour == NUM_HOURS) { |
| 495 | + for (int i=0; i<NUM_HOURS-1; ++i) memcpy(measurements[i], measurements[i + 1], sizeof(SensorData) * 120); // destination, source |
| 496 | + hour = NUM_HOURS-1; |
496 | 497 | } |
497 | 498 |
|
498 | | - measurements[hour][halfminute] = co2; |
| 499 | + measurements[hour][halfminute].co2 = co2; |
| 500 | + measurements[hour][halfminute].temperature = (uint16_t)temperature*10; |
| 501 | + measurements[hour][halfminute].humidity = (uint8_t)humidity; |
499 | 502 | halfminute++; |
500 | 503 | } |
501 | 504 |
|
502 | | -uint8_t qrcodeNumber = 0; |
503 | | -void history() { |
504 | | - // DEMO DATA: |
505 | | - /*hour = 2; |
506 | | - for (int i=0; i<120; i++) { |
507 | | - measurements[0][i] = 400+i; |
508 | | - measurements[1][i] = 520+i; |
509 | | - measurements[2][i] = 1000+i; |
510 | | - } |
511 | | - halfminute = 120;*/ |
512 | | - |
513 | | - if (halfminute == 0 && hour == 0) { // no history data |
514 | | - displayNoHistory(); |
515 | | - unsigned long StartTime = millis(); |
516 | | - for (;;) if ((millis() - StartTime) > 20000 || digitalRead(BUTTON) == 0) return; // wait for button press OR up to 20 sec |
517 | | - } |
518 | | - |
519 | | - qrcodeNumber = hour; // start at current hour |
520 | | - for (int i=0; i<200; i++) { |
521 | | - if (digitalRead(BUTTON) == 0) { // goto next qr code |
522 | | - displayHistory(measurements); |
523 | | - delay(500); |
524 | | - if (qrcodeNumber == hour) qrcodeNumber = 0; |
525 | | - else qrcodeNumber++; |
526 | | - i = 0; // display qrcode again for 20 sec |
527 | | - } |
528 | | - delay(100); |
529 | | - } |
530 | | -} |
531 | | - |
532 | 505 | void handleWiFiChange() { |
533 | 506 | scd4x.stopPeriodicMeasurement(); |
534 | 507 | scd4x.setTemperatureOffset(getTempOffset()); |
@@ -612,7 +585,7 @@ void startWiFi() { |
612 | 585 | float currentTemp = temperatureRead(); |
613 | 586 | RTC_DATA_ATTR float ESP32temps[10] = {currentTemp,currentTemp,currentTemp,currentTemp,currentTemp,currentTemp,currentTemp,currentTemp,currentTemp,currentTemp}; |
614 | 587 | RTC_DATA_ATTR float sumTemp = currentTemp * 10; |
615 | | -RTC_DATA_ATTR int indexTemp = 0; |
| 588 | +RTC_DATA_ATTR uint8_t indexTemp = 0; |
616 | 589 | void measureESP32temperature() { |
617 | 590 | currentTemp = temperatureRead(); |
618 | 591 | sumTemp -= ESP32temps[indexTemp]; |
@@ -694,7 +667,8 @@ void loop() { |
694 | 667 | errorToString(error, errorMessage, 256); |
695 | 668 | displayWriteError(errorMessage); |
696 | 669 | } else { |
697 | | - if (BatteryMode) saveMeasurement(new_co2); |
| 670 | + extern int refreshes; |
| 671 | + if (BatteryMode || (refreshes%6 == 1)) saveMeasurement(new_co2, new_temperature, humidity); |
698 | 672 | /* don't update in Battery mode, unless CO2 has changed by 3% or temperature by 0.5°C */ |
699 | 673 | if (!TEST_MODE && BatteryMode && comingFromDeepSleep) { |
700 | 674 | if ((abs(new_co2 - co2) < (0.03*co2)) && (fabs(new_temperature - temperature) < 0.5)) { |
|
0 commit comments