Modbus tcp readout

Hi - very basic newbie question

goal is to read-out an energy meter via modbus tcp with node-red and dispaly results in a dahsboard

  • energy meter has proper IP-adress and works well with another modbus read-out tool.

I installed node-red (Node-RED version: v3.1.3 Node.js version: v20.10.0) localy on a windows computer and run in firefox using http://localhost:1880/

I added "node-red-contrib-modbus" (v5.27.2), used "modbus-read" and entered all required inputs (ip-adress, register,... same data as I used for the other modbus-tool mentioned above).

After hitting deploy, I see the message "reconnecting after 2000ms" below the modbus-read icon. Unfortunately I don't find any other error-messages or warning...

Can somone please advice, where to start searching systematically? Bellow are the outputs from the cmd-shell. If there other information, which I need to provide, plase let me know.

best regards
egge

Welcome to Node-RED
===================

5 Jan 10:22:44 - [info] Node-RED version: v3.1.3
5 Jan 10:22:44 - [info] Node.js  version: v20.10.0
5 Jan 10:22:44 - [info] Windows_NT 10.0.19045 x64 LE
5 Jan 10:22:45 - [info] Loading palette nodes
5 Jan 10:22:45 - [info] Settings file  : C:\Users\lede\.node-red\settings.js
5 Jan 10:22:45 - [info] Context store  : 'default' [module=memory]
5 Jan 10:22:45 - [info] User directory : \Users\lede\.node-red
5 Jan 10:22:45 - [warn] Projects disabled : editorTheme.projects.enabled=false
5 Jan 10:22:45 - [info] Flows file     : \Users\lede\.node-red\flows.json
5 Jan 10:22:45 - [info] Server now running at http://127.0.0.1:1880/
5 Jan 10:22:45 - [warn] Using unencrypted credentials
5 Jan 10:22:45 - [info] Starting flows
5 Jan 10:22:45 - [info] Started flows
5 Jan 10:23:35 - [info] Stopping flows
5 Jan 10:23:35 - [info] Stopped flows
5 Jan 10:23:35 - [info] Updated flows
5 Jan 10:23:35 - [info] Starting flows
5 Jan 10:23:35 - [info] Started flows

Hello Egge and welcome to the forum,

  1. Can you share a small Flow to see how you have configured the Modbus nodes ?
  2. That other modbus-tool you used, that worked, was it run from the same system as node-red ?
    ( share a screenshot of the other modbus-tool's connection settings )
  3. Can you ping the Energy meter's IP address from the node-red system ?

Try enabling some of the Optionals in the Modbus config node to get more detailed status reports

image

thanks for quick reply...

here is a screenshots regarding your question - more details in next post (since forum-post is limited to 2 screenshots)

yes, other tool was testet on same computer
ping on energy-meter gives this:

C:\Users\lede>ping 172.20.44.18

Ping wird ausgefĂĽhrt fĂĽr 172.20.44.18 mit 32 Bytes Daten:
Antwort von 172.20.44.18: Bytes=32 Zeit<1ms TTL=64
Antwort von 172.20.44.18: Bytes=32 Zeit<1ms TTL=64
Antwort von 172.20.44.18: Bytes=32 Zeit<1ms TTL=64
Antwort von 172.20.44.18: Bytes=32 Zeit<1ms TTL=64

Ping-Statistik fĂĽr 172.20.44.18:
    Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
    (0% Verlust),
Ca. Zeitangaben in Millisek.:
    Minimum = 0ms, Maximum = 0ms, Mittelwert = 0ms

other modbus tool gives this (red circle is value, what I want to read out)

There is the issue

image

Shouldn't that be 172.20.44.18

you were right, thanks a lot...

stupid typo

1 Like

if you are planning to convert to the modbus result to Float values, i recommend the
node-red-contrib-buffer-parser nodes. Makes the conversion a lot easier.

Dear UnborN,

thanks again... also here you are absolutly right... this was my next challenge... Yesterday I spent hours in trying to read out big endians and convert them to numbers...
I managed to do it with functions.... probably a lucky punch, since I'm not familar at all with this... at bottom I attached my code, since I can not add *.json files to this post...
I also tried node-red-contrib-buffer-parser, but with this I didn't get good results (yet)... probably because I didn't spent enought time with it...

It looks that you are quite experienced with modbus... would you be willing to share some examples or even a complete application to read out modbus, data storage on hard-disk/cloud and visualize it? do you have experience with Janitza UMG 66RM?

cheers
egge

[
    {
        "id": "2e2ed7e132dcaa18",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f76f854f304be489",
        "type": "modbus-read",
        "z": "2e2ed7e132dcaa18",
        "name": "Voltage L1",
        "topic": "",
        "showStatusActivities": true,
        "logIOActivities": false,
        "showErrors": true,
        "showWarnings": true,
        "unitid": "",
        "dataType": "InputRegister",
        "adr": "19000",
        "quantity": "12",
        "rate": "2",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "9782f823cc54f17a",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 100,
        "y": 120,
        "wires": [
            [],
            [
                "654b2c5abf458514",
                "d813348d0378e334"
            ]
        ]
    },
    {
        "id": "654b2c5abf458514",
        "type": "function",
        "z": "2e2ed7e132dcaa18",
        "name": "function 1",
        "func": "let voltageL1 = msg.payload.buffer.readFloatBE(0, 4) // 1,2\n\n\nreturn [\n    {\n        payload: voltageL1\n        \n    }\n];",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 140,
        "wires": [
            [
                "aad085ee0e4b2a5f",
                "d4c0680ab99c95cb"
            ]
        ]
    },
    {
        "id": "aad085ee0e4b2a5f",
        "type": "debug",
        "z": "2e2ed7e132dcaa18",
        "name": "debug 6",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 500,
        "y": 40,
        "wires": []
    },
    {
        "id": "d4c0680ab99c95cb",
        "type": "function",
        "z": "2e2ed7e132dcaa18",
        "name": "function 5",
        "func": "msg.payload = Math.round((msg.payload) * 10) / 10;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 700,
        "y": 240,
        "wires": [
            [
                "a6aeabb3eefa8847"
            ]
        ]
    },
    {
        "id": "a6aeabb3eefa8847",
        "type": "debug",
        "z": "2e2ed7e132dcaa18",
        "name": "debug 7",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 240,
        "wires": []
    },
    {
        "id": "d813348d0378e334",
        "type": "function",
        "z": "2e2ed7e132dcaa18",
        "name": "function 6",
        "func": "let voltageL1 = msg.payload.buffer.readFloatBE(0, 4) // 1,2\n\npayload: voltageL1\n\nreturn msg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 380,
        "wires": [
            [
                "401ea0800f9ccf46"
            ]
        ]
    },
    {
        "id": "401ea0800f9ccf46",
        "type": "debug",
        "z": "2e2ed7e132dcaa18",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 560,
        "y": 380,
        "wires": []
    },
    {
        "id": "9782f823cc54f17a",
        "type": "modbus-client",
        "name": "Janitza_Test",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "172.20.44.18",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true,
        "showWarnings": true,
        "showLogs": true
    }
]```

What have you tried ?
If your register values are floatbe you set that as the type in buffer parser.

image

The offset defines how many bytes to offset from the initial read register 16000
and since you have enough data in the buffer (because i see you are reading 12 registers)
you can convert many registers all at once and name them with the convenience of buffer-parser.

( One 32bit float value needs 2 x 16bit registers hence the offset 4 bytes)
read this post that better explains offset calculations (link)

Flow :

[{"id":"17b04ff71b9b3717","type":"modbus-read","z":"2e2ed7e132dcaa18","name":"Voltage","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"showWarnings":true,"unitid":"","dataType":"InputRegister","adr":"19000","quantity":"12","rate":"2","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"9782f823cc54f17a","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":230,"y":560,"wires":[["92737732fdc11aa6"],[]]},{"id":"92737732fdc11aa6","type":"buffer-parser","z":"2e2ed7e132dcaa18","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"Voltage L1-N","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"Voltage L2-N","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"Voltage L3-N","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":430,"y":560,"wires":[["5b47032292f14787"]]},{"id":"5b47032292f14787","type":"debug","z":"2e2ed7e132dcaa18","name":"debug 60","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":560,"wires":[]},{"id":"9782f823cc54f17a","type":"modbus-client","name":"Janitza_Test","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"172.20.44.18","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true}]

Regarding storage solutions there are many databases and some very good nodes like sqlite, mysql, mongodb, influxdb. I use sqlite in my project with node-red-node-sqlite. its simple and lightweight.

Hi UnborN,

thanks again... indeed this works perfect! and very easy to collect many data. As you mentioned, it is essential to know, what to read out...

I will continue now "try & error", since now the data are in an object and I still don't know how to manipulate them (e.g. rounding) and/or storing in databse.

For visualization I use node-red-dashboard. With the functions in my previous post, I managed already to have graphical output, however for the object-based output of buffer-parser it looks more complex...

best regards
egge

You can do the rounding of the value directly in the ui_text node with something called Angular directives.
{{ msg.payload.Voltage_L1_N | number:2 }}

Here is an example based on the previous flow and also an example Function that prepares an Sql Insert query that can be wired to an mysql or sqlite db. It can be used to insert the data in a Table called Volts and as long as you have prepared its Columns to be dt for date timestamp, Voltage_L1_N, Voltage_L2_N, Voltage_L3_N for the respective modbus values.

[{"id":"050ac9e17b369797","type":"ui_text","z":"54efb553244c241f","group":"1d36cefd3fc95bb2","order":1,"width":0,"height":0,"name":"","label":"Voltage_L1_N","format":"{{ msg.payload.Voltage_L1_N | number:2 }}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":800,"y":3120,"wires":[]},{"id":"c578b60831dd386f","type":"ui_text","z":"54efb553244c241f","group":"1d36cefd3fc95bb2","order":2,"width":0,"height":0,"name":"","label":"Voltage_L2_N","format":"{{ msg.payload.Voltage_L2_N | number:2 }}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":800,"y":3180,"wires":[]},{"id":"c45e18453f0fbebc","type":"ui_text","z":"54efb553244c241f","group":"1d36cefd3fc95bb2","order":3,"width":0,"height":0,"name":"","label":"Voltage_L3_N","format":"{{ msg.payload.Voltage_L3_N | number:2 }}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":800,"y":3240,"wires":[]},{"id":"17b04ff71b9b3717","type":"modbus-read","z":"54efb553244c241f","name":"Voltage","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"showWarnings":true,"unitid":"","dataType":"InputRegister","adr":"19000","quantity":"12","rate":"2","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"9782f823cc54f17a","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":270,"y":3160,"wires":[["92737732fdc11aa6"],[]]},{"id":"92737732fdc11aa6","type":"buffer-parser","z":"54efb553244c241f","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"Voltage_L1_N","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"Voltage_L2_N","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"Voltage_L3_N","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":470,"y":3180,"wires":[["050ac9e17b369797","c578b60831dd386f","c45e18453f0fbebc","5b47032292f14787","c9d76cdce7e3eb1b"]]},{"id":"5b47032292f14787","type":"debug","z":"54efb553244c241f","name":"debug 60","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":565,"y":3120,"wires":[],"l":false},{"id":"c9d76cdce7e3eb1b","type":"function","z":"54efb553244c241f","name":"prepare SQL","func":"let Voltage_L1_N = msg.payload.Voltage_L1_N\nlet Voltage_L2_N = msg.payload.Voltage_L2_N\nlet Voltage_L3_N = msg.payload.Voltage_L3_N\n\nmsg.topic =  `INSERT INTO Volts (dt, 'Voltage_L1_N', 'Voltage_L2_N', 'Voltage_L3_N') VALUES (datetime('now', 'localtime'), ${Voltage_L1_N}, ${Voltage_L2_N}, ${Voltage_L3_N})`;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":790,"y":3360,"wires":[["1c096f3f80da4000"]]},{"id":"1c096f3f80da4000","type":"debug","z":"54efb553244c241f","name":"to DB node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":980,"y":3360,"wires":[]},{"id":"1d36cefd3fc95bb2","type":"ui_group","name":"Voltage","tab":"647eed3084182c30","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"9782f823cc54f17a","type":"modbus-client","name":"Janitza_Test","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"172.20.44.18","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true},{"id":"647eed3084182c30","type":"ui_tab","name":"Power analyser","icon":"dashboard","disabled":false,"hidden":false}]

Dear UnborN,

thanks again... after lots of try and error, I managed to set up the database using DB browser for SQLite... and it works... next step is visualization...

1 Like

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