User Tools

Site Tools


iot:aws:json

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
iot:aws:json [2020/06/11 13:04] – created atolstoviot:aws:json [2020/06/12 10:05] (current) – ↷ Links adapted because of a move operation atolstov
Line 1: Line 1:
-json+==== 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. 
 + 
 +<code lua - AWS_thing_report.lua> 
 +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 
 + 
 +</code> 
 + 
 +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.// 
iot/aws/json.1591880669.txt.gz · Last modified: 2020/06/11 13:04 by atolstov

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki