MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
authorEdouard Tisserant <edouard@beremiz.fr>
Mon, 30 Sep 2024 16:21:11 +0200
changeset 4023 b344393859df
parent 4022 dee0efbf8452
child 4024 f9c6bbf66eea
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
mqtt/client.py
mqtt/mqtt_template.c
--- a/mqtt/client.py	Thu Sep 26 15:28:10 2024 +0200
+++ b/mqtt/client.py	Mon Sep 30 16:21:11 2024 +0200
@@ -4,6 +4,7 @@
 
 import os
 import re
+import wx
 
 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
 from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT
@@ -26,9 +27,11 @@
 
 class MQTTClientEditor(ConfTreeNodeEditor):
     CONFNODEEDITOR_TABS = [
-        (_("MQTT Client"), "CreateMQTTClient_UI")]
+        (_("MQTT Client"), "CreateMQTTClient_UI"),
+        (_("Info"), "CreateInfo_UI")]
 
     MQTTClient_UI = None
+    Info_UI = None
 
     def Log(self, msg):
         self.Controler.GetCTRoot().logger.write(msg)
@@ -41,6 +44,15 @@
             self.Controler.GetTypes)
         return self.MQTTClient_UI
 
+    def CreateInfo_UI(self, parent):
+        location_str = "_".join(map(str, self.Controler.GetCurrentLocation()))
+        information=("Connection status GLOBAL VAR is:\n\n\tMQTT_STATUS_"+location_str
+                    +", of type INT.\n\t"
+                    +"0 is disconnected\n\t"
+                    +"1 is connected\n")
+        self.Info_UI = wx.StaticText(parent, label = information)
+        return self.Info_UI
+
     def RefreshView(self):
         if(self.MQTTClient_UI):
             self.MQTTClient_UI.RefreshView()
@@ -224,6 +236,7 @@
 
     def CTNGlobalInstances(self):
         location_str = "_".join(map(str, self.GetCurrentLocation()))
-        return [("MQTT_HAPPY_"+location_str, "DINT", "")]
-
-
+        return [("MQTT_STATUS_"+location_str, "INT", ""),
+               ]
+
+
--- a/mqtt/mqtt_template.c	Thu Sep 26 15:28:10 2024 +0200
+++ b/mqtt/mqtt_template.c	Mon Sep 30 16:21:11 2024 +0200
@@ -44,6 +44,8 @@
 #define CHANGED 1
 #define UNCHANGED 0
 
+extern INT CONFIG__MQTT_STATUS_{locstr};
+
 #define DECL_VAR(iec_type, C_type, c_loc_name)                                                     \
 static C_type PLC_##c_loc_name##_buf;                                                              \
 static C_type MQTT_##c_loc_name##_buf;                                                             \
@@ -557,6 +559,7 @@
 void __retrieve_{locstr}(void)
 {{
     if (pthread_mutex_trylock(&MQTT_retrieve_mutex) == 0){{
+        CONFIG__MQTT_STATUS_{locstr} = MQTT_is_disconnected ? 0 : 1;
 {retrieve}
         pthread_mutex_unlock(&MQTT_retrieve_mutex);
     }}