![]() The new variable ‘ TopicToPublishJson ‘ contains the topic we will public the JSON data on. TemperatureStructure:TemperatureStructure MessageToPublishJson : STRING(255) //String to send in JSON formatįbJsonDataType : FB_JsonReadWriteDataType TopicToPublishJson : STRING(255) := 'Temperatures_JSON' // Mqtt topic on which we will broadcast the acual temperatures in JSON format For this example we’ll use the the following STRUCT:Īfter adding the TemperatureStructure we need to add some variables to the main program: The message we are gonna publish will be a ST data structure (STRUCT). Readers note: This post continues where part 1 stopped so make sure you have read this before diving in to this topic. In this post I show how to publish and receive more complex data structures using JSON. Luckily we can make use of one of the world most popular data formats : ‘ JSON‘. Composing such strings is hard, but parsing it back to actual data is even harder. However in real life data soon becomes more complex than a single temperature and you quickly want to send more data and parameters in one message. ![]() In part 1 we published a simple string, indicating the room temperature. Secondly we read the messages with a smartphone. Using the Mosquitto broker and two PLC’s we were quickly able to exchange messages between the PLC’s. In TwinCAT and MQTT – Part 1 Getting started we covered the basics for MQTT in TwinCAT.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |