Modbus status undefined?

I have a node red project that involves reading modbus TCP and placing values onto the dashboard. I can take up to 8 devices. I would like node red to pickup whether certain connections are made or not, so I can hide certain UIs. I'm trying to use the status node picking up the modbus status, but I get a msg.payload: undefined message.

Its not really picking up the message. If I plug in the device, I get the above undefined message. If I disconnect my device, nothing is displayed on the debugger.

[{"id":"6a32a593.d9b52c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a1fd77d0.490458","type":"inject","z":"6a32a593.d9b52c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":140,"wires":[[]]},{"id":"225234a4.132d5c","type":"debug","z":"6a32a593.d9b52c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":180,"wires":[]},{"id":"82bb4739.b043b8","type":"modbus-read","z":"6a32a593.d9b52c","name":"PLC-READ","topic":"READ","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"HoldingRegister","adr":"0","quantity":"2","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"bf81420f.323c4","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":181,"y":240,"wires":[["b2d35631.464c18","7f181b91.59cbe4"],[]]},{"id":"cafe3433.e338d8","type":"debug","z":"6a32a593.d9b52c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":360,"wires":[]},{"id":"ba97a54c.ea82d8","type":"modbus-read","z":"6a32a593.d9b52c","name":"HMI-READ","topic":"READ","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"0","dataType":"HoldingRegister","adr":"1","quantity":"2","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"fdbc6bac.988e58","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":180,"y":360,"wires":[["cafe3433.e338d8","9311b4e6.1dd268"],[]]},{"id":"9311b4e6.1dd268","type":"ui_text","z":"6a32a593.d9b52c","group":"88145eb0.23895","order":3,"width":"2","height":"2","name":"","label":"text-hmi","format":"{{msg.payload}}","layout":"row-spread","x":535,"y":420,"wires":[]},{"id":"7d8565bb.920d8c","type":"ui_text","z":"6a32a593.d9b52c","group":"88145eb0.23895","order":1,"width":"2","height":"2","name":"","label":"pos1","format":"{{msg.payload}}","layout":"row-spread","x":770,"y":120,"wires":[]},{"id":"7f181b91.59cbe4","type":"function","z":"6a32a593.d9b52c","name":"","func":"var x = [0,0];\nvar msg_o = [msg, msg];\n\nfor(i=0; i<2; i++){\n//    x[i] = msg.payload[i];\n    msg_o[i] = {payload: msg.payload[i]}\n    \n}\n\nreturn msg_o;","outputs":2,"noerr":0,"initialize":"","finalize":"","x":520,"y":180,"wires":[["7d8565bb.920d8c","225234a4.132d5c"],["5cef744a.69db9c","8938d39a.55f92"]]},{"id":"8938d39a.55f92","type":"debug","z":"6a32a593.d9b52c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":280,"wires":[]},{"id":"b2d35631.464c18","type":"debug","z":"6a32a593.d9b52c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":220,"wires":[]},{"id":"5cef744a.69db9c","type":"ui_text","z":"6a32a593.d9b52c","group":"88145eb0.23895","order":2,"width":"2","height":"2","name":"","label":"pos2","format":"{{msg.payload}}","layout":"row-spread","x":750,"y":220,"wires":[]},{"id":"61c04ecc.1e882","type":"status","z":"6a32a593.d9b52c","name":"Modbus plc","scope":["82bb4739.b043b8"],"x":170,"y":500,"wires":[["234ee9b1.8941e6"]]},{"id":"234ee9b1.8941e6","type":"debug","z":"6a32a593.d9b52c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":500,"wires":[]},{"id":"bf81420f.323c4","type":"modbus-client","name":"PLC","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.31","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"fdbc6bac.988e58","type":"modbus-client","name":"HMI","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.50","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"88145eb0.23895","type":"ui_group","name":"hmi read","tab":"7353d1a6.00acc","order":1,"disp":true,"width":"6","collapse":false},{"id":"7353d1a6.00acc","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Hi,

I had the same issue with those Modbus nodes also and i couldnt figure out how to make it work using a Status node.

What i did in the end is :

  1. Changed the Optionals setting in the read nodes to send an empty msg on fail.
    image

  2. After the modbus read node I used a Function node so when a failure occurs i would check for the empty msg. The Function has two outputs. On failure it outputs from the second output and if the msg is ok from the first. (but its up to you how you handle it)

image


if (msg.payload == "" || msg.hasOwnProperty('error')) {
   
global.set("Status.Device_31", "Disconnected")
node.status({fill:"red",shape:"ring",text:`Last Disconnected ... time`});

// do some other stuff and return message from second function output
    
return [null, msg]
}

else {
// do some other stuff and return message from 1st function output

    global.set("Status.Device_31", "Connected")
return [msg, null];
}

[EDIT]

After looking at your flow a bit closer .. the reason you get undefined for the output of your Status node is because you have the Debug node connected to it set to msg.payload.
But as the Help tab for the Status node says .. the Status node does not output a payload but

image

Set the Debug node to complete message.

image

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