lpcmanager

Parents 37f7e851eae4
Children 2254d3e5e4c9
MQTT: Add ProjectID attribute to SmartehCloud configuration, to be used as a prefix with all topics.
  • +17 -2
    LPCMQTT.py
  • --- a/LPCMQTT.py Tue Apr 01 12:08:54 2025 +0200
    +++ b/LPCMQTT.py Fri Apr 18 15:00:12 2025 +0200
    @@ -1,5 +1,5 @@
    -from mqtt import MQTTClient, MQTTLibrary
    +from mqtt import MQTTClient, MQTTLibrary, mqtt_client_gen
    import os
    import re
    @@ -80,6 +80,17 @@
    MQTTClient.CTNGenerate_C = CTNGenerate_C
    +mqtt_client_gen.authParams["SmartehCloud"] = [
    + ("ProjectID", None)]
    +
    +prev_SanitizeTopic = mqtt_client_gen.MQTTClientModel.SanitizeTopic
    +def SanitizeTopic(self, config, Topic):
    + ProjectID = config.get("ProjectID", "")
    + if len(ProjectID)>0:
    + return "/"+ProjectID+"/"+Topic
    + return Topic
    +mqtt_client_gen.MQTTClientModel.SanitizeTopic = SanitizeTopic
    +
    orig___init__ = MQTTClient.__init__
    def __init__(self):
    if self.new_config:
    @@ -90,7 +101,11 @@
    xsd_frags = re.split(r'(choice[^>]*>)', MQTTClient.XSD, 1, re.DOTALL)
    xsd_frags.insert(-1, """
    - <xsd:element name="SmartehCloud"/>
    + <xsd:element name="SmartehCloud">
    + <xsd:complexType>
    + <xsd:attribute name="ProjectID" type="xsd:string" use="optional"/>
    + </xsd:complexType>
    + </xsd:element>
    """)
    MQTTClient.XSD = "".join(xsd_frags)