Contents
Cirrus Link Resources
Cirrus Link Website
Contact Us (Sales/Support)
Forum
Cirrus Link Modules Docs for Ignition 7.9.x
Inductive Resources
Ignition User Manual
Knowledge Base Articles
Inductive University
Forum
One common question is how to use the MQTT message's payload timestamp property rather than the time that the message arrives on the broker or received by Ignition.
There are two approaches here: parsing as JSON or parsing as a STRING.
Including the timestamp key value/pair in the JSON will result in a tag created at MQTT Engine.
Let say we have a publish received on the topic "test/data/json" with a JSON payload '{ "folderTag" : { "intTag" : 1, "boolTag" : true, "ts" : "2023-07-11T13:10:33.629078" } }'.
MQTT Engine will create a three folders "test", "data" and "json" followed by a tag/folder structure representing the JSON value of the payload:
Let say we have a publish received on the topic "test/data/point" with a payload "28;2023-07-11;16:09:33".
MQTT Engine will create a two folders "test" and "data" and a tag "point" with the value of "28;2023-07-11;16:09:33".
We can then use an Ignition Tag Change Event Script on the tag to parse out the required elements of the text string and write a Fully Qualified Value to a tag in a non managed tag provider.
For example:
from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue, QualityCode from datetime import datetime def convertString(string): value = int(string.split(";")[0]) year = int(string.split(";")[1].split("-")[0]) month = int(string.split(";")[1].split("-")[1]) day = int(string.split(";")[1].split("-")[2]) hours = int(string.split(";")[2].split(":")[0]) mins = int(string.split(";")[2].split(":")[1]) seconds = int(string.split(";")[2].split(":")[2]) date = system.date.getDate(year,month-1,day) date = system.date.setTime(date,hours, mins, seconds) return value, date #parse MQTT Engine string tag path = "[MQTT Engine]test/data/point" value,timestamp = convertString(system.tag.readBlocking([path])[0].value) #set quality quality = QualityCode.Good #set Basic Qualified Value bqv = BasicQualifiedValue(value,quality,timestamp) #set new tag path newpath = "[MQTT Tags]test/data/point" #write Basic Qualified Value system.tag.writeBlocking(newpath,bqv)