feat: add display of counter value
This commit is contained in:
parent
9766a15a3a
commit
d6712d80d6
5 changed files with 115 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#define MAX_RESTART 3
|
||||
#define MAX_RESTART 1
|
||||
#define MAX_FATAL_RESTART 3
|
||||
|
||||
uint64_t joinEUI = 0x35f48318e1324e2e;
|
||||
uint64_t devEUI = 0x0586fe41112d83d9;
|
||||
|
|
|
|||
39
src/main.cpp
39
src/main.cpp
|
|
@ -1,8 +1,10 @@
|
|||
#include <Arduino.h>
|
||||
#include <LoRaTransmitter.h>
|
||||
#include <SimuGaz.h>
|
||||
#include <GazDisplay.h>
|
||||
#include "config.h"
|
||||
|
||||
RTC_DATA_ATTR uint8_t fatalRestartCount = 0;
|
||||
RTC_DATA_ATTR uint8_t restartCount = 0;
|
||||
|
||||
ITransmitter* transmitter = new LoRaTransmitter(
|
||||
|
|
@ -17,21 +19,34 @@ void fatalError(const char* msg){
|
|||
Serial.flush();
|
||||
delay(100);
|
||||
|
||||
if (restartCount < MAX_RESTART) {
|
||||
restartCount++;
|
||||
Serial.printf("[FATAL] Redémarrage %d/3\n", restartCount);
|
||||
if (fatalRestartCount < MAX_FATAL_RESTART) {
|
||||
fatalRestartCount++;
|
||||
Serial.printf("[FATAL] Redémarrage %d/3\n", fatalRestartCount);
|
||||
Serial.flush();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
Serial.printf("[FATAL] %d redémarrages : l'appareil entre en sommeil profond permanent\n", MAX_RESTART);
|
||||
Serial.printf("[FATAL] %d redémarrages : l'appareil entre en sommeil profond permanent\n", MAX_FATAL_RESTART);
|
||||
Serial.flush();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
void generateDailyGasPayload(uint8_t *payload){
|
||||
uint32_t pulses = simulateGasPulses(86400);
|
||||
void nonCriticalError(const char* msg){
|
||||
Serial.printf("[Error] %s\n", msg);
|
||||
Serial.flush();
|
||||
delay(100);
|
||||
|
||||
if (restartCount < MAX_RESTART) {
|
||||
restartCount++;
|
||||
Serial.printf("[Error] Tentative de redémarrage\n", restartCount);
|
||||
Serial.flush();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
Serial.printf("[Error] %d redémarrage : l'appareil continue en mode dégradé\n", MAX_RESTART);
|
||||
}
|
||||
|
||||
void generateDailyGasPayload(uint32_t pulses, uint8_t *payload){
|
||||
payload[0] = (pulses >> 24) & 0xFF;
|
||||
payload[1] = (pulses >> 16) & 0xFF;
|
||||
payload[2] = (pulses >> 8) & 0xFF;
|
||||
|
|
@ -41,6 +56,10 @@ void generateDailyGasPayload(uint8_t *payload){
|
|||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(2000);
|
||||
|
||||
if (displayInit() != DisplayError::OK){
|
||||
nonCriticalError("Initialisation du périphérique d'affichage échouée");
|
||||
}
|
||||
|
||||
if (transmitter->init() != TransmitError::OK){
|
||||
fatalError("Initialisation du périphérique radio échouée");
|
||||
|
|
@ -53,9 +72,15 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
uint8_t payload[4];
|
||||
generateDailyGasPayload(payload);
|
||||
uint32_t pulses = simulateGasPulses(86400);
|
||||
|
||||
displayGasIndex(pulses);
|
||||
|
||||
generateDailyGasPayload(pulses, payload);
|
||||
transmitter->send(payload, sizeof(payload));
|
||||
|
||||
Serial.flush();
|
||||
|
||||
delay(2000);
|
||||
esp_deep_sleep(60000000);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue