# HG changeset patch # User Edouard Tisserant # Date 1727706071 -7200 # Node ID b344393859df4a7fe3adac4a7c5a934a61e5c649 # Parent dee0efbf8452f3cc5d20389ec12da5343a589fdc MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client diff -r dee0efbf8452 -r b344393859df mqtt/client.py --- 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", ""), + ] + + diff -r dee0efbf8452 -r b344393859df mqtt/mqtt_template.c --- 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); }}