# S7/S7comm data to mindconnect node format?

**URL:** https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987
**Category:** Industrial
**Created:** [28 October 2020 22:03 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987 "2020-10-28T22:03:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sunny\_Z](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Sunny\_Z](https://discourse.nodered.org/u/Sunny_Z)
#### Post date: [28 October 2020 22:03 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/1 "2020-10-28T22:03:03Z")

</div>

Hi, how is everyone?

So I'm trying to read some data from a S1200 PLC via either an S7 (node-red-contrib-s7) or S7comm (node-red-contrib-s7comm) node (which works fine). I'm also supposed to forward that data to MindSphere via the mindconnect (node-red-contrib-mindconnect) node. I am not entirely sure on how the data has to be formatted in a function node to be accepted by it. The data is only for a demo, and its only a handful of variables.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f5ede4ce2751f023d4ba4234b198bde9142ba8a8.png)  
Variables from the S7 node

---

<div class="post-metadata">

### Author: ![Cristiano](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@Cristiano](https://discourse.nodered.org/u/Cristiano)
#### Post date: [28 October 2020 23:15 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/2 "2020-10-28T23:15:06Z")

</div>

you can read that table ? without any problem ?

check this link you examples how to send data to mind [https://playground.mindconnect.rocks/](https://playground.mindconnect.rocks/)

---

<div class="post-metadata">

### Author: ![Sunny\_Z](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Sunny\_Z](https://discourse.nodered.org/u/Sunny_Z)
#### Post date: [28 October 2020 23:46 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/3 "2020-10-28T23:46:44Z")

</div>

Ye the table is fine it doesn't throw any errors, and both S7/S7comm nodes goes online, at the beginning I had problems with the addressing but after following this guide it was fine:

> **[node-red-contrib-s7](https://flows.nodered.org/node/node-red-contrib-s7)**
>
> A Node-RED node to interact with Siemens S7 PLCs

I already tried reusing the conversion format of #WaterPumps and #Weather flows from the link you sent, the one bellow is from the #WaterPumps conversion function node.

```auto
const data = msg.payload;

const values = [
    { "dataPointId": "1527772747303", "qualityCode": "1", "value": data.Flow.toString() },
    { "dataPointId": "1527772772534", "qualityCode": "1", "value": data.Motor_Current.toString()},
    { "dataPointId": "1527772793837", "qualityCode": "1", "value": data.Pressure_In.toString() },
    { "dataPointId": "1527772806720", "qualityCode": "1", "value": data.Pressure_Out.toString() },
    { "dataPointId": "1527772829740", "qualityCode": "1", "value": data.Stuffing_Box_Temp.toString() }
];
msg._time = new Date();
msg.payload = values;  

return msg;

```

I replaced the data point id's and values with mine but ended up throwing errors:

```auto
const data = msg.payload;

const values = [
    { "dataPointId": "DP-JUICER_AD", "qualityCode": "1", "value": data.JUICER_AD.ToString() },
    { "dataPointId": "DP-JUICER_CYCL", "qualityCode": "1", "value": data.JUICER_CYCL.ToString() },
    { "dataPointId": "DP-JUICER_POW", "qualityCode": "1", "value": data.JUICER_POW.ToString() },
    { "dataPointId": "DP-JUICER_STAT", "qualityCode": "1", "value": data.JUICER_STAT.ToString() },
    { "dataPointId": "DP-JUICER_TSALE", "qualityCode": "1", "value": data.JUICER_TSALE.ToString() },
    { "dataPointId": "DP-JUICER_UPTIME", "qualityCode": "1", "value": data.JUICER_UPTIME.ToString() },
    { "dataPointId": "DP-JUICER_YSALE", "qualityCode": "1", "value": data.JUICER_YSALE.ToString() }
];
msg._time = new Date();
msg.payload = values;  

return msg;

```

---

<div class="post-metadata">

### Author: ![Cristiano](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@Cristiano](https://discourse.nodered.org/u/Cristiano)
#### Post date: [29 October 2020 11:11 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/4 "2020-10-29T11:11:36Z")

</div>

make a screenshoot of the error and also you can try like this:

```auto
..........."qualityCode": "1", "value": (data.JUICER_YSALE).ToString() }

```

---

<div class="post-metadata">

### Author: ![Sunny\_Z](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Sunny\_Z](https://discourse.nodered.org/u/Sunny_Z)
#### Post date: [29 October 2020 20:27 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/5 "2020-10-29T20:27:39Z")

</div>

I tried that format in your screenshot already, and it gives the same error.  
So for both:

`....."qualityCode": "1", "value": data.JUICER_POW.toString() },`

&

`......"qualityCode": "1", "value": (data.JUICER_POW).toString() },`

It gives the same following error:

`TypeError: Cannot read property 'toString' of undefined`

I also tried this format:

`.... "qualityCode": "1", "value": String(data.JUICER_POW) },`

But then I get this error message:

`Error: Data doesn't match the configuration! Errors: [{"keyword":"str_integer","dataPath":".value","schemaPath":"#/items/select","params":{"keyword":"str_integer"},"message":"should pass \"str_integer\" keyword validation"},{"keyword":"str_integer","dataPath":".value","schemaPath":"#/items/select","params":{"keyword":"str_integer"},"message":"should pass \"str_integer\" keyword validation"},{"keyword":"str_integer","dataPath":".value","schemaPath":"#/items/select","params":{"keyword":"str_integer"},"message":"should pass \"str_integer\" keyword validation"},{"keyword":"str_integer","dataPath":".value","schemaPath":"#/items/select","params":{"keyword":"str_integer"},"message":"should pass \"str_integer\" keyword validation"},{"keyword":"str_integer","dataPath":".value","schemaPath":"#/items/select","params":{"keyword":"str_integer"},"message":"should pass \"str_integer\" keyword validation"},{"keyword":"str_integer","dataPath":".value","schemaPath":"#/items/select","params":{"keyword":"str_integer"},"message":"should pass \"str_integer\" keyword validation"}]`

---

<div class="post-metadata">

### Author: ![sn0wcat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sn0wcat/32/5027_2.png) [@sn0wcat](https://discourse.nodered.org/u/sn0wcat)
#### Post date: [2 November 2020 08:40 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/6 "2020-11-02T08:40:18Z")

</div>

The problem is most probably that you have undefined / empty values in your original data: the `data.JUICER_POW` is probably undefined and this is why the conversion with toString() method is not working. Unfortunately, MindSphere expects empty strings when the data is not defined.

You should use the following format for your strings:

```javascript
`${data.JUICER_POW}`

// for example
 { "dataPointId": "DP-JUICER_POW", "qualityCode": "1", "value": `${data.JUICER_POW}` },
    

```

This works around the encoding problem by sending empty strings to MindSphere when the data is missing. This is also the format the most of the playground examples are using and I will add an example to the generated code in the template in the next version of the node 🙂 )

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/2009b1d1a3f631bebbe7722f8a83c551c1cfd151.png)

If your data is of double/integer type, the agent data conversion in MindSphere will drop the data for the empty data points. This can be observed in the Agent Diagnostic app in the MindSphere. (Click on the stethoscope icon in the MindConnect node and register your agent for diagnostic)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a22eff62209c5efd93ea560968f66194b176a18.png)

If you would rather have default values when there is no data in your original data set you can set them in your code like this

```javascript
// if JUICER POW is undefined send 0 instead
`${data.JUICER_POW || 0}`

```

The syntax above is called javascript template literals (also template strings) , here is a bit more about it:

> **[Template literals (Template strings)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)**
>
> Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 January 2021 08:40 UTC](https://discourse.nodered.org/t/s7-s7comm-data-to-mindconnect-node-format/34987/7 "2021-01-01T08:40:43Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
