feat: improve error management to avoid infinite loop

The device goes in deep sleep after 3 restarts when connection is not
successful
This commit is contained in:
Alexis Fourmaux 2026-05-06 17:51:04 +02:00
parent 244d1eea21
commit 61b0b740d2
5 changed files with 53 additions and 20 deletions

View file

@ -1,5 +1,7 @@
#pragma once
#define MAX_RESTART 3
uint64_t joinEUI = 0x35f48318e1324e2e;
uint64_t devEUI = 0x0586fe41112d83d9;
uint8_t appKey[] = {

View file

@ -2,6 +2,8 @@
#include "LoRaTransmitter.h"
#include "config.h"
RTC_DATA_ATTR uint8_t restartCount = 0;
ITransmitter* transmitter = new LoRaTransmitter(
joinEUI,
devEUI,
@ -9,12 +11,34 @@ ITransmitter* transmitter = new LoRaTransmitter(
appKey
);
void fatalError(const char* msg){
Serial.printf("[FATAL] %s\n", msg);
Serial.flush();
delay(100);
if (restartCount < MAX_RESTART) {
restartCount++;
Serial.printf("[FATAL] Redémarrage %d/3\n", restartCount);
Serial.flush();
ESP.restart();
}
Serial.printf("[FATAL] %d redémarrages : l'appareil entre en sommeil profond permanent\n", MAX_RESTART);
Serial.flush();
esp_deep_sleep_start();
}
void setup() {
Serial.begin(115200);
delay(2000);
transmitter->init();
transmitter->join();
if (transmitter->init() != TransmitError::OK){
fatalError("Initialisation du périphérique radio échouée");
}
if (transmitter->join() != TransmitError::OK){
fatalError("Connexion au concentrateur LoRaWAN échouée");
}
restartCount = 0;
}
void loop() {