Sumar variables de dos contadores modbus

Buenos dias, necesito sumar dos variables de dos contadores modbus diferentes pero no se como hacerlo. adjunto instruccion. Un saludo

[{"id":"27195760.addd28","type":"modbus-read","z":"db2fd8f9.a97c98","name":"Contador General","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"HoldingRegister","adr":"14","quantity":"1","rate":"10","rateUnit":"s","delayOnStart":true,"startDelayTime":"6","server":"f4de446a.47c808","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":250,"y":1220,"wires":[["35a5b3f4.5cdc3c"],]},{"id":"35a5b3f4.5cdc3c","type":"function","z":"db2fd8f9.a97c98","name":"","func":"\n\nobj = {}\nobj.payload = {};\nobj.payload.W=(msg.payload[0]/1 << 16) >> 16;\nreturn obj;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":1220,"wires":[["52ae5c23.54faf4"]]},{"id":"190e3cb0.0defe3","type":"modbus-read","z":"db2fd8f9.a97c98","name":"Contador Solar","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"3","dataType":"HoldingRegister","adr":"14","quantity":"1","rate":"10","rateUnit":"s","delayOnStart":true,"startDelayTime":"7","server":"f4de446a.47c808","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":240,"y":1320,"wires":[["35a5b3f4.5cdc3c"],]},{"id":"52ae5c23.54faf4","type":"debug","z":"db2fd8f9.a97c98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":1220,"wires":},{"id":"f4de446a.47c808","type":"modbus-client","name":"General","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.11","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"3","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

Hi first welcome.

The flow you posted is corrupt you need to follow these instructions to post code. How to share code or flow json

To access your 2 modbus readings you will need to join the messages, so both readings are in the same message. There is an example in the node-red cookbook Create a single message from separate streams of messages : Node-RED

As @E1cid says, your flow cannot be imported because you have not correctly formatted it in the forum

As far as I can see, you have 2 separate modbus reads from the same modbus device then you try to use both?

It is FAR better to read all registers in one go then all data will be in the same msg

The buffer-parser node is very useful for selecting values from the modbus data and setting the correct data types - works very well with modbus nodes.


[{"id":"27195760.addd28","type":"modbus-read","z":"db2fd8f9.a97c98","name":"Contador General","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"HoldingRegister","adr":"14","quantity":"1","rate":"10","rateUnit":"s","delayOnStart":true,"startDelayTime":"6","server":"f4de446a.47c808","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":250,"y":1200,"wires":[["35a5b3f4.5cdc3c"],[]]},{"id":"35a5b3f4.5cdc3c","type":"function","z":"db2fd8f9.a97c98","name":"","func":"\n\nobj = {}\nobj.payload = {};\nobj.payload.W=(msg.payload[0]/1 << 16) >> 16;\nreturn obj;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":1200,"wires":[["52ae5c23.54faf4"]]},{"id":"190e3cb0.0defe3","type":"modbus-read","z":"db2fd8f9.a97c98","name":"Contador Solar","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"3","dataType":"HoldingRegister","adr":"14","quantity":"1","rate":"10","rateUnit":"s","delayOnStart":true,"startDelayTime":"7","server":"f4de446a.47c808","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":240,"y":1300,"wires":[["35a5b3f4.5cdc3c"],[]]},{"id":"52ae5c23.54faf4","type":"debug","z":"db2fd8f9.a97c98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":1200,"wires":[]},{"id":"f4de446a.47c808","type":"modbus-client","name":"General","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.11","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"3","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

Yo quiero sumar los dos valores que se obtienen en la funcion.

El problema, es que los valores a sumar corresponden a dos contadores modbus diferentes.

Try this...

[{"id":"27195760.addd28","type":"modbus-read","z":"f3939210.feec5","name":"Contador General","topic":"unit1","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"HoldingRegister","adr":"14","quantity":"1","rate":"10","rateUnit":"s","delayOnStart":true,"startDelayTime":"6","server":"f4de446a.47c808","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":810,"y":280,"wires":[["fe029515.d2f938"],[]]},{"id":"190e3cb0.0defe3","type":"modbus-read","z":"f3939210.feec5","name":"Contador Solar","topic":"unit3","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"3","dataType":"HoldingRegister","adr":"14","quantity":"1","rate":"10","rateUnit":"s","delayOnStart":true,"startDelayTime":"7","server":"","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":820,"y":340,"wires":[["fe029515.d2f938"],[]]},{"id":"52ae5c23.54faf4","type":"debug","z":"f3939210.feec5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":300,"wires":[]},{"id":"fe029515.d2f938","type":"join","z":"f3939210.feec5","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1030,"y":300,"wires":[["52ae5c23.54faf4"]]},{"id":"f4de446a.47c808","type":"modbus-client","name":"General","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.11","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"3","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

Look in the debug output - you should have both values in payload.

Then the docs can will explain how to use the debug panel to find the right path to any data item.

https://nodered.org/docs/user-guide/messages

Pay particular attention to the bit about the copy path button that appears when you hover over the item in the debug window.

la respuesta es:
16/2/2021 17:46:22[node: 90559441.d2ba88](http://192.168.1.166:1880
/#)unit3 : msg.payload : Object

{ unit1: array[1], unit3: array[1] }

Ok, so now you have both values in the same message.

16/2/2021 17:49:13[node: 90559441.d2ba88
unit3 : msg.payload : Object

object

unit1: array[1]

unit3: array[1]

pero tiene que se un valor numérico W

So move the array element [0] to wherever you need it.

What do you really need the output to look like?

Also, post a screenshot of the debug output with all elements and properties expanded

Uploading: WhatsApp Image 2021-02-16 at 18.03.37.jpeg...

You didn't say what you expect the output to be and you didn't expand all the properties/elements

so your values will be at
msg.payload.unit1[0]
and
msg.payload.unit3[0]
Use them in your function
e.g.
obj.payload.W=(msg.payload.unit1[0]/1 << 16) >> 16;

Uploading: WhatsApp Image 2021-02-16 at 18.03.37.jpeg...

Disculpa pero soy muy nuevo en este tipo de programacion. no entiendo

In your original function you used msg.payload[0] in
obj.payload.W=(msg.payload[0]/1 << 16) >> 16; to access the buffer.
After the join node both device buffers are at
msg.payload.unit1[0] one buffer from sensor 1
and
msg.payload.unit3[0] one bffer from sensor 2

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