# MQTT ---\> S7 PLC (node-red-contrib-s7comm)

**URL:** https://discourse.nodered.org/t/mqtt-s7-plc-node-red-contrib-s7comm/11868
**Category:** General
**Created:** [5 June 2019 13:39 UTC](https://discourse.nodered.org/t/mqtt-s7-plc-node-red-contrib-s7comm/11868 "2019-06-05T13:39:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![msw](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@msw](https://discourse.nodered.org/u/msw)
#### Post date: [5 June 2019 13:39 UTC](https://discourse.nodered.org/t/mqtt-s7-plc-node-red-contrib-s7comm/11868/1 "2019-06-05T13:39:35Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e1560765f6d137a3ed2560562364a1bc019a9ef4.png)

Project purpose: To receive MQTT payload and write each msg element to a S7 PLC tag.

Payload  
data - STRING[22]  
datetime - STRING[20]  
devaddr - STRING[8]  
fcnt - REAL  
port - REAL  
rssi - REAL

I have been able to inject json string and real values in to the S7 PLC (see debug messages 3 & 4). However, I am having trouble writing each of the objects from debug message 1 in to the S7 PLC. I used a json & function node to isolate the data string and that doesn't work either.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ef3050bf29dbb566af7d943fee29dc5a6e056d2d.png)

Any advice on the correct format which I should be sending this data through the flow so it will be accepted by the s7comm:write node would be greatly appreciated.

Thanks.

---

<div class="post-metadata">

### Author: ![msw](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@msw](https://discourse.nodered.org/u/msw)
#### Post date: [11 June 2019 08:13 UTC](https://discourse.nodered.org/t/mqtt-s7-plc-node-red-contrib-s7comm/11868/2 "2019-06-11T08:13:17Z")

</div>

Solved!

The issue was the format in which the MQTT message was split and sent to the PLC. S7 PLC requires the message as a javascript object within an array.

The important line was msg.payload = json.stringify(data);

Previously I wasn't changing the payload to a json string properly before it flowed through the json node to convert to javascript object.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f14cc2be54d876225f77d9867d2034f217e9c6d6.png)

Debug window showing correct format of message.

\*\* ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d1295a4ce4c1b27c842260f866ee6d725a035c5e.png) \*\*
