Browse Source

reboot on error, fwupgrade first

main
Hendrik Langer 5 years ago
parent
commit
eb4a13a205
  1. 21
      src/main.cpp
  2. 2
      src/main.h

21
src/main.cpp

@ -226,6 +226,8 @@ void ICACHE_FLASH_ATTR getValuesJSON(char* buffer, const size_t buf_len, int for
}
void ICACHE_FLASH_ATTR sendValues() {
int errors = 0;
sd.temperature = dht.readTemperature();
sd.humidity = dht.readHumidity();
@ -334,6 +336,14 @@ void ICACHE_FLASH_ATTR sendValues() {
sd.rssi = WiFi.RSSI();
loop_count++;
if (loop_count == 1) {
XD0OTA ota;
ota.update();
} else if (loop_count > 720) { // do an update every 12h
loop_count = 0;
}
int httpCode = 0;
for (int tries=0; tries<3 && httpCode != HTTP_CODE_CREATED; tries++) {
@ -359,6 +369,7 @@ void ICACHE_FLASH_ATTR sendValues() {
httpclient.end();
}
if (httpCode != HTTP_CODE_CREATED) errors++;
net.setInsecure();
mqttclient.begin(mqttserver, 8883, net);
@ -375,6 +386,7 @@ void ICACHE_FLASH_ATTR sendValues() {
DEBUG_MSG("mqtt done\n");
} else {
DEBUG_MSG("mqtt failed\n");
errors++;
}
mqttclient.loop();
mqttclient.disconnect();
@ -383,13 +395,10 @@ void ICACHE_FLASH_ATTR sendValues() {
sd.rssi = WiFi.RSSI();
}
if (loop_count == 1) {
XD0OTA ota;
ota.update();
} else if (loop_count > 720) { // do an update every 12h
loop_count = 0;
if (errors >= 2) {
DEBUG_MSG("[ERROR] could not send any values\nRebooting..\n");
ESP.restart();
}
loop_count++;
net.stop();
WiFi.disconnect(true);

2
src/main.h

@ -7,6 +7,6 @@
#define DEBUG_MSG(...)
#endif
#define FW_VERSION 35
#define FW_VERSION 37
#endif /* _MAIN_H */

Loading…
Cancel
Save