S7/S7comm data to mindconnect node format?

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.


Variables from the S7 node

you can read that table ? without any problem ?

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

2 Likes

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:

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.

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:

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;

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

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

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"}]

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:

`${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 :slight_smile: )

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)

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

// 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:

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