fix: store simu data in NVS to prevent readings to go down after restart
This commit is contained in:
parent
410ff8fb7d
commit
a2ae8c0beb
2 changed files with 25 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include <SimuGaz.h>
|
#include <SimuGaz.h>
|
||||||
|
#include <Preferences.h>
|
||||||
|
|
||||||
#define INITIAL_CONSUMPTION 1594.87f
|
#define INITIAL_CONSUMPTION 1594.87f
|
||||||
#define INITIAL_SECONDS 11462400 // date initiale = 13/05/2026 16:00
|
#define INITIAL_SECONDS 11462400 // date initiale = 13/05/2026 16:00
|
||||||
|
|
@ -21,15 +22,32 @@ static const float GRDF_MONTHLY_COEFF[12] = {
|
||||||
2.11f, // Décembre
|
2.11f, // Décembre
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Preferences prefs;
|
||||||
|
|
||||||
// Base annuelle : 972 m³/an pour 100m² (CRE)
|
// Base annuelle : 972 m³/an pour 100m² (CRE)
|
||||||
// - base mensuelle moyenne = 81 m³/mois
|
// - base mensuelle moyenne = 81 m³/mois
|
||||||
// - base journalière moyenne = 2.66 m³/j
|
// - base journalière moyenne = 2.66 m³/j
|
||||||
|
|
||||||
RTC_DATA_ATTR float consumptionM3 = INITIAL_CONSUMPTION;
|
float consumptionM3;
|
||||||
RTC_DATA_ATTR uint32_t totalSeconds = INITIAL_SECONDS;
|
uint32_t totalSeconds;
|
||||||
|
|
||||||
|
void get_stored_values(){
|
||||||
|
prefs.begin("simugaz");
|
||||||
|
consumptionM3 = prefs.getFloat("consumption_m3", INITIAL_CONSUMPTION);
|
||||||
|
totalSeconds = prefs.getUInt("seconds", INITIAL_SECONDS);
|
||||||
|
prefs.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void store_values(){
|
||||||
|
prefs.begin("simugaz");
|
||||||
|
prefs.putFloat("consumption_m3", consumptionM3);
|
||||||
|
prefs.putUInt("seconds", totalSeconds);
|
||||||
|
prefs.end();
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t simulateGasPulses(uint32_t intervalSeconds)
|
uint32_t simulateGasPulses(uint32_t intervalSeconds)
|
||||||
{
|
{
|
||||||
|
get_stored_values();
|
||||||
totalSeconds += intervalSeconds;
|
totalSeconds += intervalSeconds;
|
||||||
|
|
||||||
uint32_t month = (totalSeconds / (86400UL * 30UL)) % 12;
|
uint32_t month = (totalSeconds / (86400UL * 30UL)) % 12;
|
||||||
|
|
@ -45,6 +63,8 @@ uint32_t simulateGasPulses(uint32_t intervalSeconds)
|
||||||
uint32_t pulseCount = (uint32_t)(consumptionM3 / 0.010f);
|
uint32_t pulseCount = (uint32_t)(consumptionM3 / 0.010f);
|
||||||
uint32_t incrementPulses = (uint32_t)(incrementM3 / 0.010f);
|
uint32_t incrementPulses = (uint32_t)(incrementM3 / 0.010f);
|
||||||
|
|
||||||
|
store_values();
|
||||||
|
|
||||||
Serial.printf("[GAZ] Incrément de %lu impulsions - Total : %lu impulsions (%.3f m³)\n", incrementPulses, pulseCount, pulseCount * 0.010f);
|
Serial.printf("[GAZ] Incrément de %lu impulsions - Total : %lu impulsions (%.3f m³)\n", incrementPulses, pulseCount, pulseCount * 0.010f);
|
||||||
return pulseCount;
|
return pulseCount;
|
||||||
}
|
}
|
||||||
|
|
@ -2,4 +2,6 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
uint32_t simulateGasPulses(uint32_t intervalSeconds = 86400);
|
uint32_t simulateGasPulses(uint32_t intervalSeconds = 86400);
|
||||||
|
void get_stored_values();
|
||||||
|
void store_values();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue