Data from an edge device publishing MQTT payloads with binary data can be parsed at Ignition using an MQTT Engine Custom Namespace and an Ignition script.

The tutorial below will walk through the steps using MQTT Transmission to publish the MQTT message from the Edge device.

Install the MQTT Modules

Install MQTT Distributor, MQTT Engine and MQTT Transmission.

MQTT Engine Configuration

From the left hand menu bar, navigate to MQTT ENGINE > Settings > Namespaces > Custom and setup an custom namespace as shown below setting the Encoding Charset to ISO_8859_1:


Publish MQTT message

Follow the steps in the MQTT Publishing via Transmission to publish an MQTT message with a topic of a/b and a payload of [30, 32, 32, 34, 41]

The form of the publish method is as follows:

system.cirruslink.transmission.publish(String serverName, String mqttTopic, byte[] payload, int qos, boolean retain)


When using the default MQTT module configuration for MQTT Distributor and MQTT Engine, your arguments will look like:

system.cirruslink.transmission.publish("Chariot SCADA", "a/b", [30, 32, 32, 34, 41], 0, False)


When the MQTT message is received and parsed by MQTT Engine, a tag will be create containing the binary data as shown below:


Create a Value Changed script on the tag

To parse the binary tag data we will now create a Value Changed script on the tag.

Follow the steps in the Ignition Tag Event Scripts documentation to create a Value Change script on the tag and copy the code below which will parse through the binary data and make the bytes available for use as needed.  

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	#setup logging
	#######################################################################
    from org.slf4j import LoggerFactory
    from ch.qos.logback.classic import Logger
    from ch.qos.logback.classic import Level
    from ch.qos.logback.classic import LoggerContext as LoggerContext
    logger = system.util.logger("com.cirruslink.test.binarymessageconvert")
 	####################################################################### 

    newByteArray = bytearray(str(currentValue.value), "ISO-8859-1");
    for b in newByteArray:
        logger.info("Byte: " + str(b))


On saving this script, the logger will show the parsed binary payload:



Verify tag changes are evaluated

Modify the payload, publish the MQTT message and review the logs to see the changing data values:

system.cirruslink.transmission.publish("Chariot SCADA", "a/b", [1, 2, 3, 4, 5, 6], 0, False)






Additional Resources


  • No labels