### MQTT Topic Example (Sparkplug B v1.0) Source: https://docs.chariot.io/display/CLD83/MQTT%2BTransmission%2BTransmitters%2Band%2BTag%2BTrees Illustrates a Sparkplug B v1.0 MQTT topic structure. The topic namespace is dynamically generated based on the transmitter's Tag Path and Sparkplug IDs, along with the Ignition tag folder hierarchy. ```mqtt spBv1.0/Facility/DDATA/Line1/PLC1 ``` -------------------------------- ### Sparkplug DBIRTH Topic Example Source: https://docs.chariot.io/display/CLD83/Cirrus%2BLink%2BModules%2BSparkplug%2Bmessage%2Btopics%2Band%2Bpayloads Illustrates the standard topic format for Sparkplug DBIRTH messages. This format is crucial for routing and identifying device birth messages within an MQTT infrastructure. ```text spBv1.0/TestGroup/DBIRTH/TestEdge/TestDevice ``` -------------------------------- ### Sparkplug DBIRTH Payload Structure Example Source: https://docs.chariot.io/display/CLD83/Cirrus%2BLink%2BModules%2BSparkplug%2Bmessage%2Btopics%2Band%2Bpayloads Demonstrates the structure of a Sparkplug DBIRTH payload, showcasing different metric types like String, Boolean, and Template. This payload contains essential device state information. ```java [ timestamp=1713266459127, metrics=[ Metric [ name=D_T1, alias=null, timestamp=1713266459127, dataType=MetricDataType [type=String, intValue=12, clazz=class java.lang.String], isHistorical=null, isTransient=null, metaData=MetaData [isMultiPart=false, contentType=application/json, size=0, seq=0, fileName=, fileType=, md5=, description=], properties=PropertySet [ propertyMap={ Quality=PropertyValue [type=PropertyDataType [type=Int32, intValue=3, clazz=class java.lang.Integer], value=192, isNull=false], enabled=PropertyValue [type=PropertyDataType [type=Boolean, intValue=11, clazz=class java.lang.Boolean], value=true, isNull=false], documentation=PropertyValue [type=PropertyDataType [type=String, intValue=12, clazz=class java.lang.String], value=Some helpful docs, isNull=false] } ], value={ "Key1": "Value3" }, isNull=false ], Metric [ name=Device Control/Rebirth, alias=null, timestamp=1713266459127, dataType=MetricDataType [type=Boolean, intValue=11, clazz=class java.lang.Boolean], isHistorical=null, isTransient=null, metaData=null, properties=null, value=false, isNull=false ], Metric [ name=D_M1, alias=null, timestamp=1713266459127, dataType=MetricDataType [type=Template, intValue=19, clazz=class org.eclipse.tahu.message.model.Template], isHistorical=null, isTransient=null, metaData=MetaData [isMultiPart=false, contentType=, size=0, seq=0, fileName=, fileType=, md5=, description=], properties=PropertySet [ propertyMap={ enabled=PropertyValue [type=PropertyDataType [type=Boolean, intValue=11, clazz=class java.lang.Boolean], value=true, isNull=false] } ], value=Template [version=, templateRef=Motor, isDefinition=false, metrics=[ Metric [ name=T1, alias=null, timestamp=1713266459127, dataType=MetricDataType [type=Int32, intValue=3, clazz=class java.lang.Integer], isHistorical=false, isTransient=false, metaData=MetaData [isMultiPart=false, contentType=, size=0, seq=0, fileName=, fileType=, md5=, description=], properties=PropertySet [ propertyMap={ engHigh=PropertyValue [type=PropertyDataType [type=Double, intValue=10, clazz=class java.lang.Double], value=60.0, isNull=false] } ], value=12, isNull=false ] ], parameters=[]], isNull=false ] ], seq=1, uuid=null, body=null ] ``` -------------------------------- ### Sparkplug B Topic and Payload Example Source: https://docs.chariot.io/display/CLD83/Using%2BMQTT%2BModules%2Bin%2Ba%2BUNS%2BArchitecture Illustrates the MQTT topic and Sparkplug B payload generated when a tag changes in MQTT Transmission, based on the Ignition tag tree. This shows how the topic is structured and the metric data is formatted. ```text Topic: spBv1.0/G1/DDATA/E1/D1 SparkplugBPayload: [timestamp=1726851053618, metrics=[Metric [name=Vancouver/Area1/Line1/Zone1/Asset1/T1, alias=null, timestamp=1726851052615, dataType=Int32, isHistorical=null, isTransient=null, metaData=null, properties=PropertySet [propertyMap={}], value=10, isNull=false]], seq=3, uuid=null, body=null] ``` -------------------------------- ### Example MQTT Payload 1 (JSON) Source: https://docs.chariot.io/display/CLD83/How%2Bdo%2BI%2Bmanaging%2BMQTT%2Bmessages%2Bwith%2Bchanging%2Bpayload%2BJSON%2Bstructure%2Bat%2BMQTT%2BEngine_src=sidebar This is the first example MQTT payload, demonstrating a simple JSON structure with a 'level' key. ```json { "level": "value1" } ``` -------------------------------- ### MQTT Topic and Payload Example (Sparkplug B v1.0) Source: https://docs.chariot.io/display/CLD83/MQTT%2BTransmission%2BTransmitters%2Band%2BTag%2BTrees Demonstrates a typical MQTT topic and payload structure for Sparkplug B v1.0 when publishing tag data. The topic includes the namespace derived from the tag hierarchy and transmitter configuration, while the payload contains metrics like tag name, timestamp, data type, and value. ```json { "timestamp": 1643823757750, "metrics": [ { "name": "Tag3", "timestamp": 1643823756467, "dataType": "Double", "value": 33.02 } ], "seq": 23 } ``` -------------------------------- ### DDATA Sparkplug Payload Example Source: https://docs.chariot.io/display/CLD83/Cirrus%2BLink%2BModules%2BSparkplug%2Bmessage%2Btopics%2Band%2Bpayloads_src=sidebar This snippet shows an example of a DDATA (Data) Sparkplug payload. It includes a timestamp and a list of metrics, each with its own name, timestamp, data type, and value. This format is used for transmitting real-time data from devices. ```json [ { "timestamp": 1713266761298, "metrics": [ { "name": "DT1", "alias": null, "timestamp": 1713266730315, "dataType": { "type": "Int32", "intValue": 3, "clazz": "class java.lang.Integer" }, "isHistorical": true, "value": 5, "isNull": false }, { "name": "DT1", "alias": null, "timestamp": 1713266730416, "dataType": { "type": "Int32", "intValue": 3, "clazz": "class java.lang.Integer" }, "isHistorical": true, "value": 6, "isNull": false } ], "seq": 15, "uuid": null, "body": null } ] ``` -------------------------------- ### DDEATH Sparkplug Topic and Payload Example Source: https://docs.chariot.io/display/CLD83/Cirrus%2BLink%2BModules%2BSparkplug%2Bmessage%2Btopics%2Band%2Bpayloads_src=sidebar This example shows the Sparkplug topic and payload for a DDEATH (Device Death) message. This message is sent when a specific device connected to an edge node disconnects. Similar to NDEATH, it includes a 'bdSeq' metric. ```text Topic: spBv1.0/TestGroup/DDEATH/TestEdge/TestDevice Payload: [ { "timestamp": 1713266459127, "metrics": [ { "name": "bdSeq", "alias": null, "timestamp": 1713266442358, "dataType": { "type": "Int64", "intValue": 4, "clazz": "class java.lang.Long" }, "value": 5, "isNull": false } ], "seq": 7, "uuid": null, "body": null } ] ``` -------------------------------- ### Create Server Set in Cirrus Link Source: https://docs.chariot.io/display/CLD83/ME%3A%2BPython%2BScripting This script demonstrates how to create a new server set configuration in the Cirrus Link system. It defines properties for the server set, such as name and description, and then uses the `createConfig` function to instantiate it. ```python serverProps = {} serverProps["name"] = "Server Set 1" serverProps["description"] = "" serverProps["primaryHostEnabled"] = True serverProps["primaryHostId"] = "MyPrimaryHost" system.cirruslink.engine.createConfig("server-set", serverProps) ``` -------------------------------- ### Monitor MQTT Engine Clients with Python Script Source: https://docs.chariot.io/display/CLD83/Tutorials%2Band%2BHowtos%2BReference_src=breadcrumbs-expanded Provides simple Python scripts that can be run in the Ignition script console to display the client count and other relevant information for MQTT Engine. This is useful for monitoring active connections. ```python # Script to display MQTT Engine client count client_count = 0 # Assuming you can access client information through system tags or a direct API # This is a placeholder and might need adjustment based on actual implementation try: # Example: Reading a system tag that might represent client count # Replace '[default]MQTT Engine/clients/count' with the actual tag path if available client_info = system.tag.readBlocking("[default]MQTT Engine/clients") if client_info and client_info[0].value is not None: # Assuming the value is a dictionary or list of clients if isinstance(client_info[0].value, dict): client_count = len(client_info[0].value) elif isinstance(client_info[0].value, list): client_count = len(client_info[0].value) else: # Attempt to interpret if it's a simple count string or number try: client_count = int(client_info[0].value) except ValueError: pass # Cannot interpret as count print(f"Current MQTT Engine client count: {client_count}") except Exception as e: print(f"Could not retrieve client count: {e}") print("Ensure the tag path '[default]MQTT Engine/clients' is correct or adjust the script to use the appropriate API.") ``` -------------------------------- ### DDATA Sparkplug Payload with Template Example Source: https://docs.chariot.io/display/CLD83/Cirrus%2BLink%2BModules%2BSparkplug%2Bmessage%2Btopics%2Band%2Bpayloads_src=sidebar This example demonstrates a DDATA payload containing a 'Template' data type metric. Templates allow for structured data definitions, including nested metrics. This is useful for representing complex device states or configurations. ```json [ { "timestamp": 1713266453943, "metrics": [ { "name": "D_M1", "alias": null, "timestamp": 1713266452942, "dataType": { "type": "Template", "intValue": 19, "clazz": "class org.eclipse.tahu.message.model.Template" }, "value": { "version": "", "templateRef": "Motor", "isDefinition": false, "metrics": [ { "name": "T1", "alias": null, "timestamp": 1713266445725, "dataType": { "type": "Int32", "intValue": 3, "clazz": "class java.lang.Integer" }, "value": 12, "isNull": false } ], "parameters": [] }, "isNull": false }, { "name": "D_T1", "alias": null, "timestamp": 1713266452947, "dataType": { "type": "String", "intValue": 12, "clazz": "class java.lang.String" }, "metaData": { "isMultiPart": false, "contentType": "application/json", "size": 0, "seq": 0, "fileName": "", "fileType": "", "md5": "", "description": "" }, "properties": { "propertyMap": {} }, "value": { "Key1": "Value3" }, "isNull": false } ], "seq": 7, "uuid": null, "body": null } ] ``` -------------------------------- ### Example MQTT Payload 1 (JSON - Expanded) Source: https://docs.chariot.io/display/CLD83/How%2Bdo%2BI%2Bmanaging%2BMQTT%2Bmessages%2Bwith%2Bchanging%2Bpayload%2BJSON%2Bstructure%2Bat%2BMQTT%2BEngine_src=sidebar This example shows a more complex JSON payload with multiple key-value pairs. MQTT Engine will create separate tags for each key. ```json { "level": "low" "temp": "45.0" "alarm": "on" } ``` -------------------------------- ### Configure MQTT Security Context for Writes Source: https://docs.chariot.io/display/CLD83/Tutorials%2Band%2BHowtos%2BReference_src=sidebar Illustrates how to configure MQTT Engine and MQTT Transmission to leverage Ignition's Security Context for validating writes to tags. This ensures that only authorized writes from MQTT Engine to MQTT Transmission are permitted, enhancing security. ```python def configure_security_context(): # Placeholder for configuring security context. # This would involve setting properties on MQTT Engine and MQTT Transmission # to use the Ignition Security Context for write validation. print("Configuring MQTT Engine and Transmission for Security Context writes...") # Example: system.util.invokeAssembly("MQTT.Engine", "setSecurityContextEnabled", True) # Example: system.util.invokeAssembly("MQTT.Transmission", "setSecurityContextEnabled", True) pass ``` -------------------------------- ### Example MQTT Payload 2 (JSON) Source: https://docs.chariot.io/display/CLD83/How%2Bdo%2BI%2Bmanaging%2BMQTT%2Bmessages%2Bwith%2Bchanging%2Bpayload%2BJSON%2Bstructure%2Bat%2BMQTT%2BEngine_src=sidebar This is the second example MQTT payload, showing a modified structure where 'level' is now an object, which can cause issues with MQTT Engine's automatic tag creation. ```json { "level": { "key": "value2" } } ``` -------------------------------- ### Publish MQTT Messages via Ignition Python Scripts Source: https://docs.chariot.io/display/CLD83/Tutorials%2Band%2BHowtos%2BReference_src=breadcrumbs-expanded Provides guidance on how to publish MQTT messages directly from Ignition Python scripts using MQTT Engine. This allows for programmatic control over message publishing. ```python import system topic = "your/mqtt/topic" payload = "your message payload" # Assuming you have an MQTT Engine client configured # Replace 'mqtt_engine_client_name' with your actual client name mqtt_engine = system.tag.readBlocking(["[default]MQTT Engine/clients/mqtt_engine_client_name"])[0].value mqtt_engine.publish(topic, payload) print(f"Published message to {topic}") ``` -------------------------------- ### Configure MQTT Engine for Tag Latching Source: https://docs.chariot.io/display/CLD83/Tutorials%2Band%2BHowtos%2BReference_src=sidebar Demonstrates how to configure MQTT Engine for synchronizing events. Tag latching ensures that tag values are held until explicitly updated, which is useful for event-driven systems. ```python def configure_tag_latching(): # Placeholder for configuring tag latching. # This setting affects how tag values are updated and maintained. print("Configuring MQTT Engine for tag latching...") # Example: system.util.invokeAssembly("MQTT.Engine", "setTagLatchingEnabled", True) pass ```