# Cannot read data by MODBUS RTU

**URL:** <https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840>\
**Category:** Hardware\
**Created:** [28 July 2020 19:02 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840 "2020-07-28T19:02:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrino1000](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mrino1000](https://discourse.nodered.org/u/mrino1000)\
**Post date:** [28 July 2020 19:02 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/1 "2020-07-28T19:02:00Z")

</div>

[Sensor manual](https://innovatorsguru.com/wp-content/uploads/2019/06/PZEM-004T-V3.0-Datasheet-User-Manual.pdf)

The sensor manual is shared above. I want to communicate with it through Modbus RTU node. My code is given below:

`[{"id":"5f61c311.3e5d1c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b3e619e4.41ca08","type":"modbus-read","z":"5f61c311.3e5d1c","name":"","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"unitid":"1","dataType":"InputRegister","adr":"1","quantity":"1","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"1c521864.046078","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":340,"y":140,"wires":[["94edf5aa.8613a8"],["3bf738d0.3f1648"]]},{"id":"3bf738d0.3f1648","type":"debug","z":"5f61c311.3e5d1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":750,"y":140,"wires":[]},{"id":"94edf5aa.8613a8","type":"modbus-response","z":"5f61c311.3e5d1c","name":"","registerShowMax":"10","x":660,"y":40,"wires":[]},{"id":"1c521864.046078","type":"modbus-client","z":"","name":"","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":true,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":false,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]`

I am getting error message which says: Error: Data length error, expected 7 got 2

Please help me out!! 😢 😢

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [28 July 2020 20:49 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/2 "2020-07-28T20:49:05Z")

</div>

I was playing with a PZEM-016 last Saturday. It was pretty straightforward to enable the communication. I still could make a quick dashboard (a couple of errors pending to correct though) to make it more fun. I will check your flow tomorrow (going out in few minutes). Please edit your message to reformat the code between backticks ([click this link for instructions](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)), otherwise i wont be able to test.

 ![ameter-03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a9e78a375429731f4434df62916d68bcbe7d53ed.jpeg)

![energy-meter](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/076a105840cf6a974335492f9bd574b58f2f42c8.png)

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [29 July 2020 02:09 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/3 "2020-07-29T02:09:10Z")

</div>

Can't import your 'server' settings. What are your serial settings?

---

<div class="post-metadata">

**Author:** ![mrino1000](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mrino1000](https://discourse.nodered.org/u/mrino1000)\
**Post date:** [29 July 2020 02:16 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/4 "2020-07-29T02:16:50Z")

</div>

```auto
[{"id":"76274d8e.fd5214","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"174978cb.b7da67","type":"modbus-read","z":"76274d8e.fd5214","name":"","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"unitid":"1","dataType":"InputRegister","adr":"1","quantity":"1","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"4099da6.7419b24","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":340,"y":140,"wires":[["e4d6becf.7d167"],["942f710f.4b0c1"]]},{"id":"942f710f.4b0c1","type":"debug","z":"76274d8e.fd5214","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":140,"wires":[]},{"id":"e4d6becf.7d167","type":"modbus-response","z":"76274d8e.fd5214","name":"","registerShowMax":"10","x":660,"y":40,"wires":[]},{"id":"4099da6.7419b24","type":"modbus-client","z":"","name":"","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":true,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":false,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

```

---

<div class="post-metadata">

**Author:** ![mrino1000](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mrino1000](https://discourse.nodered.org/u/mrino1000)\
**Post date:** [29 July 2020 02:18 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/5 "2020-07-29T02:18:35Z")

</div>

I have tried with T/x and R/x opposite connection. T/x and R/x LED are also blinking in both side

---

<div class="post-metadata">

**Author:** ![mrino1000](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mrino1000](https://discourse.nodered.org/u/mrino1000)\
**Post date:** [29 July 2020 02:19 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/6 "2020-07-29T02:19:17Z")

</div>

i have uploaded the flow

---

<div class="post-metadata">

**Author:** ![mrino1000](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mrino1000](https://discourse.nodered.org/u/mrino1000)\
**Post date:** [29 July 2020 02:19 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/7 "2020-07-29T02:19:43Z")

</div>

I have uploaded the flow

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [29 July 2020 02:41 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/8 "2020-07-29T02:41:28Z")

</div>

> [@mrino1000](#):
>
> Error: Data length error, expected 7 got

I can´t see what is wrong. I share my config and suggest you to change the serial mode in the server config from RTU to RTU-Buffered, for testing purposes.

 ![mod-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93be38cb1f738672d2961c1a46badfa6776ce4a7.png)

 ![mod-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8e5227a0c68dbe867a05357eb5197aa38d4c0225.png)

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [29 July 2020 03:38 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/9 "2020-07-29T03:38:13Z")

</div>

In the last flow you included, you are reading only 1 register, but it looks like they need to be read in pairs at least. I'd just read all the registers every poll. Without that specific device, it's hard to say what the issue may be. I know my most recent install had a long, less than ideal serial bus. I had to increase the queue delay (for multiple reads on the same slave) to account for some delay time on the bus response. Another thing that gets overlooked, grounding. You NEED to have a good ground, using a 3rd conductor that is not a shield. For short cables, you generally don't need a shield or can use a shield for ground.

---

<div class="post-metadata">

**Author:** ![mrino1000](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@mrino1000](https://discourse.nodered.org/u/mrino1000)\
**Post date:** [29 July 2020 07:10 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/10 "2020-07-29T07:10:44Z")

</div>

I couldn't fix the issue with the MODBUS node and PZE004T.  
So to fix it, i have written a program in python using modbus library. And the executed the program in powershell node of node red. I is working fine and i am getting the data..

Can anyone help me with resetting the energy value of PZE004T??

---

<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:** [27 September 2020 07:10 UTC](https://discourse.nodered.org/t/cannot-read-data-by-modbus-rtu/30840/11 "2020-09-27T07:10:44Z")

</div>

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