thermferm/thermferm.c

changeset 675
825210ba2707
parent 669
daa22055cd3d
child 678
cc49115e769e
--- a/thermferm/thermferm.c	Thu Apr 11 15:58:49 2024 +0200
+++ b/thermferm/thermferm.c	Sat Apr 13 16:50:26 2024 +0200
@@ -37,6 +37,7 @@
 #include "pid.h"
 #include "mqtt.h"
 #include "statetbl.h"
+#include "websocket.h"
 
 
 int			my_shutdown = FALSE;
@@ -57,6 +58,8 @@
 extern int		my_panel_shutdown;
 extern int		my_server_state;
 extern int		my_server_shutdown;
+extern int		my_ws_state;
+extern int		my_ws_shutdown;
 extern int		my_simulator_state;
 #ifdef USE_SIMULATOR
 extern int		my_simulator_shutdown;
@@ -71,6 +74,7 @@
 pthread_t		my_devices_thread;
 pthread_t		my_panel_thread;
 pthread_t		my_server_thread;
+pthread_t		my_ws_thread;
 #ifdef USE_SIMULATOR
 pthread_t		my_simulator_thread;
 #endif
@@ -1843,7 +1847,9 @@
     if (key != KEY_NONE)
 	panel_key_events(key);
 
-    mDelay(50);
+    mDelay(25);
+    ws_check();
+    mDelay(25);
     SM_PROCEED(CheckRun);
 
 SM_END
@@ -1879,8 +1885,8 @@
     slcdCharDef(slcdHandle, 6, RevHeatONOFF);
 
     my_shutdown = my_reboot = FALSE;
-    my_devices_shutdown = my_panel_shutdown = my_server_shutdown = my_one_wire_shutdown = 0;
-    my_devices_state = my_panel_state = my_server_state = my_one_wire_state = 0;
+    my_devices_shutdown = my_panel_shutdown = my_server_shutdown = my_ws_shutdown = my_one_wire_shutdown = 0;
+    my_devices_state = my_panel_state = my_server_state = my_ws_state = my_one_wire_state = 0;
     my_simulator_state = 0;
 #ifdef USE_SIMULATOR
     my_simulator_shutdown = 0;
@@ -1892,7 +1898,18 @@
     mqtt_connect();
 
     /*
-     * First scan the one-wire bus
+     * Start websockets first.
+     */
+    rc = pthread_create(&my_ws_thread, NULL, my_ws_loop, (void *)t );
+    if (rc) {
+        fprintf(stderr, "my_ws_loop thread didn't start rc=%d\n", rc);
+        syslog(LOG_NOTICE, "my_ws_loop thread didn't start rc=%d", rc);
+    } else {
+        t++;
+    }
+
+    /*
+     * Next scan the one-wire bus
      */
     rc = pthread_create(&my_one_wire_thread, NULL, my_one_wire_loop, (void *)t );
     if (rc) {
@@ -2052,7 +2069,8 @@
     while (my_devices_state) { mDelay(50); };
     my_one_wire_shutdown = 1;
     while (my_one_wire_state) { mDelay(50); };
-
+    my_ws_shutdown = 1;
+    while (my_ws_state) { mDelay(50); };
     mqtt_disconnect();
 
     stopLCD();

mercurial