
kwaltzer (Customer) asked a question.
I have watched a few videos regarding the MQTT functions. We will be using the Node Red and Mosquitto broker for the data handling and directory to server.
My questions though are pertaining to the packing and unpacking of data to send via the MQTT. I need to send the follow points:
Send out / publish:
Cycle Count (integer)
4 different Temps (all integers)
Mold# (integer)
Material Type (string)
Downtime Category (integer)
Downtime start and end (integer)
Downtime description (string)
4 cycle times (all integers)
Notification to print part bin tag (0=no print 1=print unless i can figure out how to print from the serial com module with a QR code)
Receive / subscribe:
Use server as a data base for recipes
When mold number is entered or QR code is scanned, would load recipe parameters
mold# (integer)
material type (string)
2 cycle times (integers)
4 temps ( integers )
I need to make sure im thinking about it the right way from what I have seen. I will need to use the pack string instruction to create a payload for the broker topic, correct?
Some of the information will be sent at different times. For instance I will need the cycle count and cycle times to be sent at the end of every cycle, but downtime can be sent over only when there is downtime. Under the publisher parameters there is an enable and a publish rate. If i need data to be sent on a triggered basis, I will need to have the trigger the enable for that publisher and make the publish rate long so it only sends once while the enable is triggered?
When subscribing to a message I will need to use the unpack string, and or extract string to separate out the specific data integers or strings then assign them to there proper locations, correct?
The tag names will not be part of the payload, you'll specify the key names and use the tags as the values.
A PKS would look like this
"{"mold":" | 8
MoldTag | 4
","count":" | 9
CountTag | 5
"}" | 1
Note, additional quotes are shown as needed for Psuite literal strings. Fixed values are shown for lengths, use SLEN for strings of variable length and use the integer it returns in place of fixed length.
Don't forget to set the precision on Floats/Reals and remember the decimal itself counts as one char when setting the length (and some brokers are picky when there is not a number after a decimal).
You can add as many variables to a payload as practical, separate the key/value pairs with a comma. You can use multiple PKS to make a single payload if your data is concise and you haven't hit Psuite's 128char limit. You may find value in adding some data as context instead also, quite a few options you can explore on the web.
If you need to publish more than will fit into a 128char string, break it up into multiples. In your MQTT Setup, create a 2D array of 128char strings. MQTTPubPay(1),(1) is payload 1 for publisher 1. MQTTPubPay(3),(10) is payload 10 for publisher 10. Just an example, name as you see fit. You can publish up to 10, 128char strings at a time for each publisher. If you need to publish more than this, write your own queueing routine to build strings, publish them and then build the next set and publish. Etc.