Industrial Internet of Things in PLC Simatic S7-1x00 on the example of the MQTT protocol

Found in the Siemens Knowledge Base (SIOS) an interesting example of using S7-1200 and S7-1500 line controllers as a client of the MQTT protocol





Link to the source .





Follow the link to find the library itself with the MQTT_Client functional block (open source, by the way) and an explanatory note for example. The documentation itself is quite comprehensive, those who know English can safely follow the link and not read this article, thereby giving themselves several fascinating hours of engineering research. And for the rest, less experienced and / or more lazy, I will briefly tell you the main thing and demonstrate my example of a client's work, creatively reworked for more or less real application.





Briefly about the terms.





MQTT - message queuing telemetry transport. Telemetry protocol for messaging. I find it difficult to translate the name correctly into Russian.





Message - message. Directly, the transmitted data itself. The message consists of several parts:





  • Topic, the subject of the message. A character string limited to 200 characters in the original example. To receive messages, clients must first subscribe to a specific topic, i.e. topic





  • QoS, quality of service. An additional sign indicating whether to wait for confirmation of receipt of a message or not





  • Message text, message text. 500 character text string





The protocol is built on a subscriber / publisher model, the general logic of which is slightly different from the usual client-server model common in industrial protocols.





- , .. , . , . , . « Modbus». , .





-, MQTT, , (). . . , , , , . , .





, MQTT.





— publisher. , ( ) (topic).





— subscriber. , . .





. — .





MQTT , . , . .





, . . , , TCP/IP .





(. ) LMQTT_Client. , — Step 7. Options → Global Libraries → Open library. :









MQTT — S7-1200 S7-1500. , S7-1214. , S7-1500 , S7-1200 — ip-. LMQTT_Client Program Files . . MQTT_Client MQTTExchange:





, , . .





enable — MQTT, . .. TRUE





publishData — () . ( done error), , QoS





subscribeToTopic — , , (, ),





, : tcpConnParam mqttParam. OB100 . .









( « » ) . . ID , 64. Hardware ID .





— . TCP/IP, connection ID. 1 4096, , «», . - , «1»





— IP- , .





«» ip-. ip- . mosquitto Windows. .





, .





. ( ). mosquitto.exe, 1883 ( MQTT) .





, . 192.168.0. 192.168.1., — , , . , , ip-, , , ip.





, , « » «» ip-.





router address,





— , . , 1884, 1883. :





— . . S7-1214.





. , «SIMATIC» ( ). . , .





. Last will. — «» ( !). , . « » , . «» , .





. . . — .





activateSecureConn — , , . OPC UA . Open User Communications (SecOUC). . .





, , , . , , . enable LMQTT_Client:





, enable tcpEstablished mqttEstablished «», , . , — «» enable - . . , , . :





— 5 , , . 5 , . . .





, - , . , , . , — , , . , . . subscribeToTopic, , «» .





( , ) #SubscriveToTopics « » 1. , , , , ( ).





— «global». . (, , )





. « » = 1, …





… «», (global) «»





… «» , done error. done «» №2. — .





№2. . , «». , .





100 , ( â„–3).





№3 №1, . №3 « » (#SubscriveToTopics) « ».





.  mosquitto_pub.exe:





mosquitto_pub.exe -h myhost.mydomain.ru -t global -m «kill all humans»





,





myhost.mydomain.ru —





global — «global»,





kill all humans — global





subscriptionsMessage:





, global «kill all humans»





newMessageReceived . . , .





— . , . . , 10 , . 10 « » « » 1:





SCL, LAD. , — .





4 , , — . «» , personal0. . , REAL_TO_WSTRING . , , , — . — 500 , . , , . , . , , ( , ).





« » . , « » « ».





MQTT , personal0 ( ):





, . . personal0 exterminate, Q0.0 «».





:





mosquitto_pub.exe -h host.domain.ru -t personal0 -m «exterminate»





:





( newMessageReceived), . . , .





, . , , , . , , , , «» . , , . (, , , ) . , , — . GSM-, , , ip-. , , « ». , . ,





, , , , M2M (-). , .





, () . , , , WinCC Advanced.





Further research has shown excellent use of mqtt in conjunction with the Node-RED environment. A program was "drawn" on Node-RED that receives this data from the broker, parses the received string and writes all the information (timestamp, value) to the MariaDB database. She, the program on Node-RED made it possible to extract information for a specified time period, show it in the form of a table, graph and upload it as a .csv file.








All Articles