From bc399e0044f09e7346e89e1fa5cf7440642ef31e Mon Sep 17 00:00:00 2001 From: ms Date: Sun, 15 Feb 2026 00:29:54 +0100 Subject: [PATCH] =?UTF-8?q?Po=20up=C5=82ywie=20HIGH=5FFREQ=5FMODE=5FDURATI?= =?UTF-8?q?ON=20sekund=20od=20wykrycia=20fluktuacji=20napi=C4=99cia:=20=20?= =?UTF-8?q?=20-=20Wysy=C5=82any=20jest=20komunikat=20MQTT=20na=20topic=20/?= =?UTF-8?q?energy/orno/fluct=20z=20warto=C5=9Bci=C4=85=20"off"=20=20=20-?= =?UTF-8?q?=20Wysy=C5=82any=20jest=20zapis=20do=20InfluxDB=20z=20tagiem=20?= =?UTF-8?q?highfluct=3Dend=20i=20warto=C5=9Bci=C4=85=20highfluct=3D0=20=20?= =?UTF-8?q?=20-=20Flaga=20jest=20resetowana,=20aby=20powiadomienie=20wys?= =?UTF-8?q?=C5=82a=C5=82o=20si=C4=99=20tylko=20raz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modb_orno3.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modb_orno3.c b/modb_orno3.c index 5e6bba0..47f105a 100644 --- a/modb_orno3.c +++ b/modb_orno3.c @@ -535,6 +535,7 @@ int main(int argc, char *argv[]) int voltage_buffer_index = 0; int voltage_buffer_items = 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; struct tm *timeinfo; @@ -674,8 +675,9 @@ int main(int argc, char *argv[]) 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); 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_active = 1; } @@ -1050,6 +1052,13 @@ int main(int argc, char *argv[]) if (time(NULL) < high_frequency_mode_end_time) { usleep(10000); // 10ms } 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 } }