author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 08 Dec 2024 15:26:26 +0100 | |
changeset 4065 | d876242447da |
parent 4023 | b344393859df |
permissions | -rw-r--r-- |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
1 |
# mqtt/client.py |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
2 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
3 |
from __future__ import absolute_import |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
4 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
5 |
import os |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
6 |
import re |
4023
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
7 |
import wx |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
8 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
9 |
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
10 |
from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
11 |
from .mqtt_client_gen import MQTTClientPanel, MQTTClientModel, MQTT_IEC_types, authParams |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
12 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
13 |
import util.paths as paths |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
14 |
|
3984
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
15 |
|
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
16 |
# assumes that "build" directory was created in paho.mqtt.c source directory, |
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
17 |
# and cmake build was invoked from this directory |
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
18 |
PahoMqttCLibraryPath = paths.ThirdPartyPath("paho.mqtt.c", "build", "src") |
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
19 |
|
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
20 |
frozen_path = paths.ThirdPartyPath("frozen") |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
21 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
22 |
MqttCIncludePaths = [ |
3984
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
23 |
paths.ThirdPartyPath("paho.mqtt.c", "build"), # VersionInfo.h |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
24 |
paths.ThirdPartyPath("paho.mqtt.c", "src"), |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
25 |
frozen_path |
3984
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
26 |
] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
27 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
28 |
class MQTTClientEditor(ConfTreeNodeEditor): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
29 |
CONFNODEEDITOR_TABS = [ |
4023
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
30 |
(_("MQTT Client"), "CreateMQTTClient_UI"), |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
31 |
(_("Info"), "CreateInfo_UI")] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
32 |
|
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
33 |
MQTTClient_UI = None |
4023
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
34 |
Info_UI = None |
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
35 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
36 |
def Log(self, msg): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
37 |
self.Controler.GetCTRoot().logger.write(msg) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
38 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
39 |
def CreateMQTTClient_UI(self, parent): |
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
40 |
self.MQTTClient_UI = MQTTClientPanel( |
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
41 |
parent, |
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
42 |
self.Controler.GetModelData(), |
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
43 |
self.Log, |
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
44 |
self.Controler.GetTypes) |
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
45 |
return self.MQTTClient_UI |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
46 |
|
4023
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
47 |
def CreateInfo_UI(self, parent): |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
48 |
location_str = "_".join(map(str, self.Controler.GetCurrentLocation())) |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
49 |
information=("Connection status GLOBAL VAR is:\n\n\tMQTT_STATUS_"+location_str |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
50 |
+", of type INT.\n\t" |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
51 |
+"0 is disconnected\n\t" |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
52 |
+"1 is connected\n") |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
53 |
self.Info_UI = wx.StaticText(parent, label = information) |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
54 |
return self.Info_UI |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
55 |
|
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
56 |
def RefreshView(self): |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
57 |
if(self.MQTTClient_UI): |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
58 |
self.MQTTClient_UI.RefreshView() |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
59 |
return ConfTreeNodeEditor.RefreshView(self) |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4012
diff
changeset
|
60 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
61 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
62 |
class MQTTClient(object): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
63 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
64 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
65 |
<xsd:element name="MQTTClient"> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
66 |
<xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
67 |
<xsd:sequence> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
68 |
<xsd:element name="AuthType" minOccurs="0"> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
69 |
<xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
70 |
<xsd:choice minOccurs="0"> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
71 |
<xsd:element name="x509"> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
72 |
<xsd:complexType> |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
73 |
<xsd:attribute name="Client_certificate" type="xsd:string" use="optional" default="KeyStore.pem"/> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
74 |
<xsd:attribute name="Broker_certificate" type="xsd:string" use="optional" default="TrustStore.pem"/> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
75 |
<xsd:attribute name="Verify_hostname" type="xsd:boolean" use="optional" default="true"/> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
76 |
</xsd:complexType> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
77 |
</xsd:element> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
78 |
<xsd:element name="PSK"> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
79 |
<xsd:complexType> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
80 |
<xsd:attribute name="Secret" type="xsd:string" use="optional" default=""/> |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
81 |
<xsd:attribute name="ID" type="xsd:string" use="optional" default=""/> |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
82 |
</xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
83 |
</xsd:element> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
84 |
<xsd:element name="UserPassword"> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
85 |
<xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
86 |
<xsd:attribute name="User" type="xsd:string" use="optional"/> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
87 |
<xsd:attribute name="Password" type="xsd:string" use="optional"/> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
88 |
</xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
89 |
</xsd:element> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
90 |
</xsd:choice> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
91 |
</xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
92 |
</xsd:element> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
93 |
</xsd:sequence> |
3986
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3985
diff
changeset
|
94 |
<xsd:attribute name="Use_MQTT_5" type="xsd:boolean" use="optional" default="true"/> |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
95 |
<xsd:attribute name="Broker_URI" type="xsd:string" use="optional" default="ws://localhost:1883"/> |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
96 |
<xsd:attribute name="Client_ID" type="xsd:string" use="optional" default=""/> |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
97 |
</xsd:complexType> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
98 |
</xsd:element> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
99 |
</xsd:schema> |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
100 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
101 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
102 |
EditorType = MQTTClientEditor |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
103 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
104 |
def __init__(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
105 |
self.modeldata = MQTTClientModel(self.Log, self.CTNMarkModified) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
106 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
107 |
filepath = self.GetFileName() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
108 |
if os.path.isfile(filepath): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
109 |
self.modeldata.LoadCSV(filepath) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
110 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
111 |
def Log(self, msg): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
112 |
self.GetCTRoot().logger.write(msg) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
113 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
114 |
def GetModelData(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
115 |
return self.modeldata |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
116 |
|
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
117 |
def GetTypes(self): |
4022
dee0efbf8452
MQTT: strip unsupported types from type choice dropdown, better wrong type detection in build.
Edouard Tisserant <edouard@beremiz.fr>
parents:
4014
diff
changeset
|
118 |
datatype_candidates = self.GetCTRoot().GetDataTypes(basetypes=False, only_locatables=True) |
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
119 |
return datatype_candidates |
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
120 |
|
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
121 |
def GetDataTypeInfos(self, typename): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
122 |
tagname = "D::"+typename |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
123 |
return self.GetCTRoot().GetDataTypeInfos(tagname) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
124 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
125 |
def GetConfig(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
126 |
def cfg(path): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
127 |
try: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
128 |
attr=self.GetParamsAttributes("MQTTClient."+path) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
129 |
except ValueError: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
130 |
return None |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
131 |
return attr["value"] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
132 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
133 |
AuthType = cfg("AuthType") |
3986
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3985
diff
changeset
|
134 |
res = dict( |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3985
diff
changeset
|
135 |
URI=cfg("Broker_URI"), |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3985
diff
changeset
|
136 |
AuthType=AuthType, |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3985
diff
changeset
|
137 |
clientID=cfg("Client_ID"), |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3985
diff
changeset
|
138 |
UseMQTT5=cfg("Use_MQTT_5")) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
139 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
140 |
paramList = authParams.get(AuthType, None) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
141 |
if paramList: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
142 |
for name,default in paramList: |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
143 |
|
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
144 |
# Translate internal config naming into user config naming |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
145 |
displayed_name = {"KeyStore" : "Client_certificate", |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
146 |
"TrustStore" : "Broker_certificate", |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
147 |
"Verify" : "Verify_hostname"}.get(name, name) |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
148 |
|
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
149 |
value = cfg("AuthType." + displayed_name) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
150 |
if value == "" or value is None: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
151 |
value = default |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
152 |
|
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
153 |
if value is not None: |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
154 |
# cryptomaterial is expected to be in project's user provided file directory |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
155 |
|
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
156 |
# User input may contain char incompatible with C string literal escaping |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
157 |
if name in ["User","Password","TrustStore","KeyStore","Broker_URI","Client_ID"]: |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
158 |
value = re.sub(r'([\"\\])', r'\\\1', value) |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
4001
diff
changeset
|
159 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
160 |
res[name] = value |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
161 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
162 |
return res |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
163 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
164 |
def GetFileName(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
165 |
return os.path.join(self.CTNPath(), 'selected.csv') |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
166 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
167 |
def OnCTNSave(self, from_project_path=None): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
168 |
self.modeldata.SaveCSV(self.GetFileName()) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
169 |
return True |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
170 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
171 |
def CTNGenerate_C(self, buildpath, locations): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
172 |
current_location = self.GetCurrentLocation() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
173 |
locstr = "_".join(map(str, current_location)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
174 |
c_path = os.path.join(buildpath, "mqtt_client__%s.c" % locstr) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
175 |
|
3984
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
176 |
c_code = """ |
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
177 |
#include "iec_types_all.h" |
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
178 |
#include "beremiz.h" |
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
179 |
""" |
4001
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
180 |
config = self.GetConfig() |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
181 |
c_code += self.modeldata.GenerateC(c_path, locstr, config, self.GetDataTypeInfos) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
182 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
183 |
with open(c_path, 'w') as c_file: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
184 |
c_file.write(c_code) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
185 |
|
4001
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
186 |
if config["AuthType"] == "x509": |
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
187 |
static_lib = "libpaho-mqtt3cs.a" |
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
188 |
libs = ['-lssl', '-lcrypto'] |
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
189 |
else: |
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
190 |
static_lib = "libpaho-mqtt3c.a" |
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
191 |
libs = [] |
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
192 |
|
5e0660d394e3
MQTT: link to SSL only when needed.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3991
diff
changeset
|
193 |
LDFLAGS = [' "' + os.path.join(PahoMqttCLibraryPath, static_lib) + '"'] + libs |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
194 |
|
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
195 |
CFLAGS = ' '.join(['-I"' + path + '"' for path in MqttCIncludePaths]) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
196 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
197 |
# TODO: add frozen only if using JSON |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
198 |
frozen_c_path = os.path.join(frozen_path, "frozen.c") |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
199 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
200 |
return [(c_path, CFLAGS), (frozen_c_path, CFLAGS)], LDFLAGS, True |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
201 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
202 |
def GetVariableLocationTree(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
203 |
current_location = self.GetCurrentLocation() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
204 |
locstr = "_".join(map(str, current_location)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
205 |
name = self.BaseParams.getName() |
3991
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
206 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
207 |
entries = [] |
3991
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
208 |
children = [] |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
209 |
|
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
210 |
for row in self.modeldata["output"]: |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
211 |
Topic, QoS, _Retained, iec_type, iec_number = row |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
212 |
entries.append((Topic, QoS, iec_type, iec_number, "Q", LOCATION_VAR_OUTPUT)) |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
213 |
|
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
214 |
for row in self.modeldata["input"]: |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
215 |
Topic, QoS, iec_type, iec_number = row |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
216 |
entries.append((Topic, QoS, iec_type, iec_number, "I", LOCATION_VAR_INPUT)) |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
217 |
|
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
218 |
for Topic, QoS, iec_type, iec_number, iec_dir_prefix, loc_type in entries: |
4009
51272fe96999
MQTT+IDE: Allow user to associate IEC structure datatype to a topic.
Edouard Tisserant <edouard@beremiz.fr>
parents:
4005
diff
changeset
|
219 |
_C_type, iec_size_prefix = MQTT_IEC_types.get(iec_type,(None,"")) |
3991
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
220 |
c_loc_name = "__" + iec_dir_prefix + iec_size_prefix + locstr + "_" + str(iec_number) |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
221 |
children.append({ |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
222 |
"name": Topic, |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
223 |
"type": loc_type, |
4009
51272fe96999
MQTT+IDE: Allow user to associate IEC structure datatype to a topic.
Edouard Tisserant <edouard@beremiz.fr>
parents:
4005
diff
changeset
|
224 |
"size": {"X":1, "B":8, "W":16, "D":32, "L":64, "":None}[iec_size_prefix], |
3991
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
225 |
"IEC_type": iec_type, |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
226 |
"var_name": c_loc_name, |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
227 |
"location": "%" + iec_dir_prefix + iec_size_prefix + ".".join([str(i) for i in current_location]) + "." + str(iec_number), |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
228 |
"description": "", |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
229 |
"children": []}) |
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
230 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
231 |
return {"name": name, |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
232 |
"type": LOCATION_CONFNODE, |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
233 |
"location": ".".join([str(i) for i in current_location]) + ".x", |
3991
28354ba489b9
MQTT: Fix crash when browsing locations
Edouard Tisserant <edouard@beremiz.fr>
parents:
3986
diff
changeset
|
234 |
"children": children} |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
235 |
|
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
236 |
|
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
237 |
def CTNGlobalInstances(self): |
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4009
diff
changeset
|
238 |
location_str = "_".join(map(str, self.GetCurrentLocation())) |
4023
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
239 |
return [("MQTT_STATUS_"+location_str, "INT", ""), |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
240 |
] |
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
241 |
|
b344393859df
MQTT: Add status global variable MQTT_STATUS_n, one per MQTT client
Edouard Tisserant <edouard@beremiz.fr>
parents:
4022
diff
changeset
|
242 |