# I want to send Data from PLC to an API

**URL:** <https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855>\
**Category:** General\
**Created:** [12 February 2021 07:30 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855 "2021-02-12T07:30:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 07:30 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/1 "2021-02-12T07:30:19Z")

</div>

I want to send data on an API from my PLC.

Here is my flow:

[{"id":"4fe68f34.52a3a","type":"function","z":"787783f2.48923c","name":"Send Data to API ","func":"msg.method = "GET";\nmsg.url = "https:/xyz.net/app/storeData?param1=" +(msg.payload.MoistureatReel)+"&param2=param2value&param3=param3value&param4=param4value&param5=param5value&param6=param6value&param7=param7value&param8=param8value&param9=param9value&param10=param10value";\nreturn msg; ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":366,"y":252,"wires":[["2bb41ad7.354706"]]}]

* * *

Instead of msg.payload.MoistureatReel what should I write/change so that the value at that PLC Variable we get here in that API.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 09:57 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/2 "2021-02-12T09:57:19Z")

</div>

Some info required to answer question  
what api?  
what plc?  
what is the incomming or input data?  
what should the finished url look like, is there an example?  
what values does the api take in the url?  
where is your flow? as you just supplied a single node.

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:15 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/3 "2021-02-12T10:15:08Z")

</div>

> [@E1cid](#):
>
> what api?

The values coming out of PLC are as shown in image below. PLC I am using is Siemens 1200, Input. It takes Data in any format i have manually wriiten values and send it but what should i write in place of **" +String(msg.payload.MoistureatReel)+ "** so that my value coming at parameter \*\* ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9c11eabb8a2d5483af6957377e13739d69864b3.png) ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/128a6d541f1581ac01709bbc9ff4347eca92e4b8.png) \*\* reflects when i update this API.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:18 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/4 "2021-02-12T10:18:54Z")

</div>

> [@Swapnil](#):
>
> **" +String(msg.payload.MoistureatReel)+ "**

`msg.payload["Moisture at Reel"]`

as there are spaces in the name.

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:20 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/5 "2021-02-12T10:20:35Z")

</div>

> [@Swapnil](#):
>
> " +String(msg.payload.MoistureatReel)+ "

I have tried this but doesn't work

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:21 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/6 "2021-02-12T10:21:45Z")

</div>

Try the format i showed below the quote.

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:24 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/7 "2021-02-12T10:24:10Z")

</div>

> [@E1cid](#):
>
> msg.payload["Moisture at Reel"]

It shows undefined

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:27 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/8 "2021-02-12T10:27:23Z")

</div>

> [@Swapnil](#):
>
> parameter \*\* ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9c11eabb8a2d5483af6957377e13739d69864b3.png)

Not according to your image. You must have over written it. add debug before function to check it exists. I can not say more as i have no more info.

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:33 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/9 "2021-02-12T10:33:38Z")

</div>

![7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/270c619eec20d247d19e6f8077a3635b6a6cfcf2.png)

 ![5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c0f560ded1ba9bb36a08d246393c92f22738036d.png) ![6|480x344]

When i use like this "+context.global.MoistureatReel+" this thing works but i need to individually take 50 S7 Nodes 50 Function Nodes and write in the function nodes individually context.global.xxx

which is not a feasable solution if there are more parameters to transfer

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:34 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/10 "2021-02-12T10:34:31Z")

</div>

![6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de1cc3d209290923ad24ed7f6e6c9511669a0494.png)

Image of S7 Node

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:36 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/11 "2021-02-12T10:36:59Z")

</div>

Again i ask for a debug from just before function showing complete message object.

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:38 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/12 "2021-02-12T10:38:24Z")

</div>

> [@E1cid](#):
>
> function sh

Means after the timestamp node?

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:43 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/13 "2021-02-12T10:43:06Z")

</div>

I am new to this Node red. I am not getting what you are saying.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:43 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/14 "2021-02-12T10:43:51Z")

</div>

How would i know after which node, you still have not supplied a flow. I require a debug of info that goes into function, which ever node is before it is the one you should add the debug to, and do make sure it's the complete message object.

You should read this and watch the videos it will help you understand more.  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:47 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/15 "2021-02-12T10:47:05Z")

</div>

> [@E1cid](#):
>
> ad this and watch the videos it will help you understan

I will share you the flow

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:48 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/16 "2021-02-12T10:48:53Z")

</div>

> [@E1cid](#):
>
> ld i know after which node, you still have not supplied a flow. I require a debug of info that goes into function, which ever node is before it is the one you should ad

* * *

[{"id":"5ad8f653.eb1298","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"9eafd082.f8802","type":"s7 in","z":"5ad8f653.eb1298","endpoint":"24609e1b.f132d2","mode":"all","variable":"MoistureatReel","diff":true,"name":"PLC Data","x":240,"y":84,"wires":[["bebafa0.2deaf08"]]},{"id":"bebafa0.2deaf08","type":"debug","z":"5ad8f653.eb1298","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":307,"y":175,"wires":},{"id":"4fbe13b6.a48dfc","type":"inject","z":"5ad8f653.eb1298","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":168,"y":288,"wires":[["cbdc8747.162cc8"]]},{"id":"a67295c4.a7a508","type":"http request","z":"5ad8f653.eb1298","name":"","method":"use","ret":"txt","paytoqs":false,"url":"","tls":"","proxy":"","authType":"","x":574,"y":288,"wires":[["cedf224e.58c2c"]]},{"id":"cedf224e.58c2c","type":"debug","z":"5ad8f653.eb1298","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":742,"y":288,"wires":},{"id":"cbdc8747.162cc8","type":"function","z":"5ad8f653.eb1298","name":"Send Data to API ","func":"msg.method = "GET";\nmsg.url = "[https://xyz.net/app/storeData?param1=\](https://xyz.net/app/storeData?param1=%5C)" +msg.payload.MoistureatReel+ "&param2=param2value&param3=param3value&param4=param4value&param5=param5value&param6=param6value&param7=param7value&param8=param8value&param9=param9value&param10=param10value";\nreturn msg; ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":378,"y":288,"wires":[["a67295c4.a7a508"]]},{"id":"24609e1b.f132d2","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.200.50","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"","vartable":[{"addr":"MR4","name":"MoistureatReel"},{"addr":"MR8","name":"Machine Speed"},{"addr":"MR12","name":"Storage Tower Level"},{"addr":"MR16","name":"Broke Tower Level"},{"addr":"MR20","name":"Turbine Inlet Pressure"},{"addr":"MR24","name":"Turbine Inlet Temperature"},{"addr":"MR28","name":"Bleed Flow"},{"addr":"MR32","name":"Extraction Flow"},{"addr":"MR68","name":"Paper at Size Press"},{"addr":"MR72","name":"Paper at Shoe Press"},{"addr":"MR76","name":"Paper at Dryer 1"},{"addr":"MR80","name":"Paper at Dryer 2"},{"addr":"MR84","name":"Paper at Dryer 3"}]}]

* * *

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:52 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/17 "2021-02-12T10:52:10Z")

</div>

Please read

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

Try importing the flow you just posted.

I asked for a debug, you post a flow, I can not help if you do not answer the questions and supply the info. I do not have access to the info(msg) even if i have a copy of the flow.

---

<div class="post-metadata">

**Author:** ![Swapnil](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Swapnil](https://discourse.nodered.org/u/Swapnil)\
**Post date:** [12 February 2021 10:56 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/18 "2021-02-12T10:56:08Z")

</div>

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506/1):
>
> o share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow jso

Please make me understand what is debug???

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 February 2021 10:59 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/19 "2021-02-12T10:59:08Z")

</div>

I supplied links if you had bothered to read them you would know what a debug is. please read and then post a debug of the incoming data  
[https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message](https://nodered.org/docs/user-guide/messages#understanding-the-structure-of-a-message)  
[https://nodered.org/docs/user-guide/nodes#debug](https://nodered.org/docs/user-guide/nodes#debug)

> [@Swapnil](#):
>
> ![5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c0f560ded1ba9bb36a08d246393c92f22738036d.png)

> [@Swapnil](#):
>
> parameter \*\* ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9c11eabb8a2d5483af6957377e13739d69864b3.png)

that image is from a debug node so you have used one before, and the green node in the first image is a debug node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 February 2021 11:20 UTC](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855/20 "2021-02-12T11:20:47Z")

</div>

Also watch this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

[Next page](https://discourse.nodered.org/t/i-want-to-send-data-from-plc-to-an-api/40855.md?page=2)
