@@ -36,20 +36,21 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
36
36
37
37
*/
38
38
39
- #include < HardwareSerial.h>
40
- #include " AirGradient.h"
41
- #include " OtaHandler.h"
42
39
#include " AgApiClient.h"
43
40
#include " AgConfigure.h"
44
41
#include " AgSchedule.h"
45
42
#include " AgStateMachine.h"
46
43
#include " AgWiFiConnector.h"
44
+ #include " AirGradient.h"
47
45
#include " EEPROM.h"
48
46
#include " ESPmDNS.h"
49
47
#include " LocalServer.h"
50
48
#include " MqttClient.h"
51
49
#include " OpenMetrics.h"
50
+ #include " OtaHandler.h"
52
51
#include " WebServer.h"
52
+ #include " esp32c3/rom/rtc.h"
53
+ #include < HardwareSerial.h>
53
54
#include < WebServer.h>
54
55
#include < WiFi.h>
55
56
@@ -111,9 +112,8 @@ static void wdgFeedUpdate(void);
111
112
static void ledBarEnabledUpdate (void );
112
113
static bool sgp41Init (void );
113
114
static void firmwareCheckForUpdate (void );
114
- static void otaHandlerCallback (OtaState state, String mesasge);
115
- static void displayExecuteOta (OtaState state, String msg,
116
- int processing);
115
+ static void otaHandlerCallback (OtaHandler::OtaState state, String mesasge);
116
+ static void displayExecuteOta (OtaHandler::OtaState state, String msg, int processing);
117
117
static int calculateMaxPeriod (int updateInterval);
118
118
static void setMeasurementMaxPeriod ();
119
119
@@ -136,6 +136,10 @@ void setup() {
136
136
/* * Print device ID into log */
137
137
Serial.println (" Serial nr: " + ag->deviceId ());
138
138
139
+ // Set reason why esp is reset
140
+ esp_reset_reason_t reason = esp_reset_reason ();
141
+ measurements.setResetReason (reason);
142
+
139
143
/* * Initialize local configure */
140
144
configuration.begin ();
141
145
@@ -514,29 +518,27 @@ static void firmwareCheckForUpdate(void) {
514
518
Serial.println ();
515
519
}
516
520
517
- static void otaHandlerCallback (OtaState state, String mesasge ) {
518
- Serial.println (" OTA message: " + mesasge );
521
+ static void otaHandlerCallback (OtaHandler:: OtaState state, String message ) {
522
+ Serial.println (" OTA message: " + message );
519
523
switch (state) {
520
- case OtaState ::OTA_STATE_BEGIN:
524
+ case OtaHandler ::OTA_STATE_BEGIN:
521
525
displayExecuteOta (state, fwNewVersion, 0 );
522
526
break ;
523
- case OtaState ::OTA_STATE_FAIL:
527
+ case OtaHandler ::OTA_STATE_FAIL:
524
528
displayExecuteOta (state, " " , 0 );
525
529
break ;
526
- case OtaState::OTA_STATE_PROCESSING:
527
- displayExecuteOta (state, " " , mesasge.toInt ());
528
- break ;
529
- case OtaState::OTA_STATE_SUCCESS:
530
- displayExecuteOta (state, " " , mesasge.toInt ());
530
+ case OtaHandler::OTA_STATE_PROCESSING:
531
+ case OtaHandler::OTA_STATE_SUCCESS:
532
+ displayExecuteOta (state, " " , message.toInt ());
531
533
break ;
532
534
default :
533
535
break ;
534
536
}
535
537
}
536
538
537
- static void displayExecuteOta (OtaState state, String msg, int processing) {
539
+ static void displayExecuteOta (OtaHandler:: OtaState state, String msg, int processing) {
538
540
switch (state) {
539
- case OtaState ::OTA_STATE_BEGIN: {
541
+ case OtaHandler ::OTA_STATE_BEGIN: {
540
542
if (ag->isOne ()) {
541
543
oledDisplay.showFirmwareUpdateVersion (msg);
542
544
} else {
@@ -545,7 +547,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
545
547
delay (2500 );
546
548
break ;
547
549
}
548
- case OtaState ::OTA_STATE_FAIL: {
550
+ case OtaHandler ::OTA_STATE_FAIL: {
549
551
if (ag->isOne ()) {
550
552
oledDisplay.showFirmwareUpdateFailed ();
551
553
} else {
@@ -555,7 +557,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
555
557
delay (2500 );
556
558
break ;
557
559
}
558
- case OtaState ::OTA_STATE_SKIP: {
560
+ case OtaHandler ::OTA_STATE_SKIP: {
559
561
if (ag->isOne ()) {
560
562
oledDisplay.showFirmwareUpdateSkipped ();
561
563
} else {
@@ -565,7 +567,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
565
567
delay (2500 );
566
568
break ;
567
569
}
568
- case OtaState ::OTA_STATE_UP_TO_DATE: {
570
+ case OtaHandler ::OTA_STATE_UP_TO_DATE: {
569
571
if (ag->isOne ()) {
570
572
oledDisplay.showFirmwareUpdateUpToDate ();
571
573
} else {
@@ -575,7 +577,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
575
577
delay (2500 );
576
578
break ;
577
579
}
578
- case OtaState ::OTA_STATE_PROCESSING: {
580
+ case OtaHandler ::OTA_STATE_PROCESSING: {
579
581
if (ag->isOne ()) {
580
582
oledDisplay.showFirmwareUpdateProgress (processing);
581
583
} else {
@@ -584,7 +586,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
584
586
585
587
break ;
586
588
}
587
- case OtaState ::OTA_STATE_SUCCESS: {
589
+ case OtaHandler ::OTA_STATE_SUCCESS: {
588
590
int i = 6 ;
589
591
while (i != 0 ) {
590
592
i = i - 1 ;
@@ -634,7 +636,7 @@ static void sendDataToAg() {
634
636
" task_led" , 2048 , NULL , 5 , NULL );
635
637
636
638
delay (1500 );
637
- if (apiClient.sendPing (wifiConnector.RSSI (), measurements.bootCount )) {
639
+ if (apiClient.sendPing (wifiConnector.RSSI (), measurements.bootCount () )) {
638
640
if (ag->isOne ()) {
639
641
stateMachine.displayHandle (AgStateMachineWiFiOkServerConnected);
640
642
}
@@ -1135,7 +1137,8 @@ static void updatePm(void) {
1135
1137
1136
1138
static void sendDataToServer (void ) {
1137
1139
/* * Increment bootcount when send measurements data is scheduled */
1138
- measurements.bootCount ++;
1140
+ int bootCount = measurements.bootCount () + 1 ;
1141
+ measurements.setBootCount (bootCount);
1139
1142
1140
1143
/* * Ignore send data to server if postToAirGradient disabled */
1141
1144
if (configuration.isPostDataToAirGradient () == false || configuration.isOfflineMode ()) {
@@ -1149,6 +1152,9 @@ static void sendDataToServer(void) {
1149
1152
" Online mode and isPostToAirGradient = true: watchdog reset" );
1150
1153
Serial.println ();
1151
1154
}
1155
+
1156
+ /* * Log current free heap size */
1157
+ Serial.printf (" Free heap: %u\n " , ESP.getFreeHeap ());
1152
1158
}
1153
1159
1154
1160
static void tempHumUpdate (void ) {
0 commit comments