Po upływie HIGH_FREQ_MODE_DURATION sekund od wykrycia fluktuacji napięcia:

- Wysyłany jest komunikat MQTT na topic /energy/orno/fluct z wartością "off"
  - Wysyłany jest zapis do InfluxDB z tagiem highfluct=end i wartością highfluct=0
  - Flaga jest resetowana, aby powiadomienie wysłało się tylko raz
This commit is contained in:
ms
2026-02-15 00:29:54 +01:00
parent ae444a10fc
commit bc399e0044

View File

@@ -535,6 +535,7 @@ int main(int argc, char *argv[])
int voltage_buffer_index = 0; int voltage_buffer_index = 0;
int voltage_buffer_items = 0; int voltage_buffer_items = 0;
time_t high_frequency_mode_end_time = 0; time_t high_frequency_mode_end_time = 0;
int high_frequency_mode_active = 0; /* Flag to track if we notified about high freq mode */
time_t rawtime; time_t rawtime;
struct tm *timeinfo; struct tm *timeinfo;
@@ -674,8 +675,9 @@ int main(int argc, char *argv[])
fabs(current_voltage.U3 - avg_L3) > avg_L3 * VOLTAGE_FLUCTUATION_THRESHOLD) { fabs(current_voltage.U3 - avg_L3) > avg_L3 * VOLTAGE_FLUCTUATION_THRESHOLD) {
printf("ORNO: Voltage fluctuation detected! Switching to high frequency polling for %d seconds.\n", HIGH_FREQ_MODE_DURATION); printf("ORNO: Voltage fluctuation detected! Switching to high frequency polling for %d seconds.\n", HIGH_FREQ_MODE_DURATION);
mqtt_send("/energy/orno/fluct", "on"); mqtt_send("/energy/orno/fluct", "on");
influx_send_post("orno,device=orno,highfluct=start highfluct=true"); influx_send_post("orno,device=orno,highfluct=start highfluct=1");
high_frequency_mode_end_time = time(NULL) + HIGH_FREQ_MODE_DURATION; high_frequency_mode_end_time = time(NULL) + HIGH_FREQ_MODE_DURATION;
high_frequency_mode_active = 1;
} }
@@ -1050,6 +1052,13 @@ int main(int argc, char *argv[])
if (time(NULL) < high_frequency_mode_end_time) { if (time(NULL) < high_frequency_mode_end_time) {
usleep(10000); // 10ms usleep(10000); // 10ms
} else { } else {
// Check if high frequency mode just ended - send notification
if (high_frequency_mode_active) {
printf("ORNO: High frequency mode ended after %d seconds.\n", HIGH_FREQ_MODE_DURATION);
mqtt_send("/energy/orno/fluct", "off");
influx_send_post("orno,device=orno,highfluct=end highfluct=0");
high_frequency_mode_active = 0;
}
sleep(5); // 5s sleep(5); // 5s
} }
} }