==== JSON formatted payload ==== It is widely used MQTT payload format JSON. Let’s write a small script which will use inbuild library to encode any WebHMI register values to JSON formatted strings. Here is the code example to encode a string type message with Amazon Web Services (AWS) [[https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-document-syntax.html|Thing Report Shadow]] JSON format. function main (userId) local decoded = { state = { reported = { timestamp = os.date("%Y-%m-%dT%H:%M:%S", os.time() - 3 * 60 * 60), message = "Hello, WebHMI!" } } } encoded = cjson.encode( decoded ) DEBUG(encoded) WriteReg("mqtt_publish", encoded); -- Test Publish (iot-test@MQTT WebHMI Client) end To check the result of script work let’s check “iot-test” subscribed topic in MQTT.fx. {{ iot:mqtt:client:json:протокол_связи_mqtt_на_webhmi_json_encode_test.png?direct |}} //Hint: There is drop-down list with MQTT payload format selector in the lower right corner.//