"TypeError: Cannot read property 'toString' of undefined"

I’ll get back to you in a bit. I have an 8 month old asleep on my chest.

1 Like

@swanside

send me a copy of the output from your modbus node

Add a debug node here
image

& set to show complete message
image

then click "copy value" on the object in the debug window
image

and paste it into a reply between ``` backticks.

When you get a chance to send a copy of your modbus message (as requested in my previous post) I will show you how to change this...


into this...

image

[{"id":"1c1f2a8f.ec9285","type":"function","z":"6d01e3e4.6003b4","name":"modbus data (simulated)","func":"msg.responseBuffer = { \n        \"data\": [3067, 135, 5244, 0, 2760, 190, 5244, 0, 2760, 1, 0, 0, 0, 0, 0, 0, 0], \n        \"buffer\": Buffer.from([11, 251, 0, 135, 20, 124, 0, 0, 10, 200, 0, 190, 20, 124, 0, 0, 10, 200, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2130,"y":780,"wires":[["78acbacb.8326a4"]]},{"id":"d2509826.7e7458","type":"inject","z":"6d01e3e4.6003b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":2080,"y":720,"wires":[["1c1f2a8f.ec9285"]]},{"id":"30eef1da.d3dc3e","type":"debug","z":"6d01e3e4.6003b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2450,"y":660,"wires":[]},{"id":"78acbacb.8326a4","type":"buffer-parser","z":"6d01e3e4.6003b4","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"SolarVoltage","offset":0,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"SolarCurrant","offset":2,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int32be","name":"SolarPower","offset":4,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"BatteryVoltage","offset":8,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"BatteryCurrant","offset":10,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int32be","name":"BatteryPower","offset":12,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"LoadVoltage","offset":16,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"LoadCurrant","offset":18,"length":1,"offsetbit":0,"scale":"/ 100","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":2210,"y":840,"wires":[["30eef1da.d3dc3e","a2a3fce8.faef6","ca93dd3e.17247","5549bbda.a33264","9245dcaf.db116","a007ba18.f83b18","8640147a.9e1de8","7fa59870.f678c8","35a35bc1.d3ab74"]]},{"id":"a2a3fce8.faef6","type":"ui_text","z":"6d01e3e4.6003b4","group":"3bf43a81.2b807e","order":2,"width":0,"height":0,"name":"SolarVoltage","label":"Solar Voltage (V)","format":"{{msg.payload.SolarVoltage}}","layout":"col-center","x":2450,"y":720,"wires":[]},{"id":"ca93dd3e.17247","type":"ui_text","z":"6d01e3e4.6003b4","group":"3bf43a81.2b807e","order":1,"width":0,"height":0,"name":"SolarCurrant","label":"Solar Currant (A)","format":"{{msg.payload.SolarCurrant}}","layout":"col-center","x":2450,"y":760,"wires":[]},{"id":"5549bbda.a33264","type":"ui_text","z":"6d01e3e4.6003b4","group":"92374fdb.9d242","order":2,"width":5,"height":1,"name":"BatteryVoltage","label":"Battery Voltage (V)","format":"{{msg.payload.BatteryVoltage}}","layout":"col-center","x":2460,"y":840,"wires":[]},{"id":"9245dcaf.db116","type":"ui_text","z":"6d01e3e4.6003b4","group":"92374fdb.9d242","order":1,"width":5,"height":1,"name":"BatteryCurrant","label":"Battery Currant (A)","format":"{{msg.payload.BatteryCurrant}}","layout":"col-center","x":2460,"y":880,"wires":[]},{"id":"8640147a.9e1de8","type":"ui_text","z":"6d01e3e4.6003b4","group":"d0e60a67.4d8d6","order":1,"width":5,"height":1,"name":"LoadCurrant","label":"Load Currant (A)","format":"{{msg.payload.LoadCurrant}}","layout":"col-center","x":2450,"y":1000,"wires":[]},{"id":"a007ba18.f83b18","type":"ui_text","z":"6d01e3e4.6003b4","group":"d0e60a67.4d8d6","order":2,"width":5,"height":1,"name":"LoadVoltage","label":"Load Voltage (V)","format":"{{msg.payload.LoadVoltage}}","layout":"col-center","x":2450,"y":960,"wires":[]},{"id":"7fa59870.f678c8","type":"ui_text","z":"6d01e3e4.6003b4","group":"92374fdb.9d242","order":5,"width":5,"height":1,"name":"BatteryPower","label":"Battery Power (W)","format":"{{msg.payload.BatteryPower}}","layout":"col-center","x":2460,"y":920,"wires":[]},{"id":"35a35bc1.d3ab74","type":"ui_text","z":"6d01e3e4.6003b4","group":"3bf43a81.2b807e","order":3,"width":0,"height":0,"name":"SolarPower","label":"Solar Power (W)","format":"{{msg.payload.SolarPower}}","layout":"col-center","x":2450,"y":800,"wires":[]},{"id":"3bf43a81.2b807e","type":"ui_group","name":"Solar Information","tab":"28c10730.74ad38","order":1,"disp":true,"width":5,"collapse":true},{"id":"92374fdb.9d242","type":"ui_group","name":"Battery Information","tab":"28c10730.74ad38","order":2,"disp":true,"width":5,"collapse":false},{"id":"d0e60a67.4d8d6","type":"ui_group","name":"DC Load Information","tab":"28c10730.74ad38","order":3,"disp":true,"width":5,"collapse":false},{"id":"28c10730.74ad38","type":"ui_tab","name":"Solar PV Equipment","icon":"dashboard","disabled":false,"hidden":false}]

or this if you prefer...

image

[{"id":"86b69c2.13b806","type":"buffer-parser","z":"6d01e3e4.6003b4","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"SolarVoltage","offset":0,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"SolarCurrant","offset":2,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int32be","name":"SolarPower","offset":4,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"BatteryVoltage","offset":8,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"BatteryCurrant","offset":10,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int32be","name":"BatteryPower","offset":12,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"LoadVoltage","offset":16,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"LoadCurrant","offset":18,"length":1,"offsetbit":0,"scale":"/ 100","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":true,"setTopic":true,"outputs":8,"x":2230,"y":1240,"wires":[["34e923b2.b70ddc"],["9a7c954e.630648"],["8a9b8518.d2c828"],["47bf6dd3.0d5914"],["5f356d06.8ec164"],["a138ac27.5e428"],["2c61bd87.973f32"],["b0357751.cec228"]]},{"id":"34e923b2.b70ddc","type":"ui_text","z":"6d01e3e4.6003b4","group":"3bf43a81.2b807e","order":2,"width":0,"height":0,"name":"SolarVoltage","label":"Solar Voltage (V)","format":"{{msg.payload}}","layout":"col-center","x":2450,"y":1100,"wires":[]},{"id":"9a7c954e.630648","type":"ui_text","z":"6d01e3e4.6003b4","group":"3bf43a81.2b807e","order":1,"width":0,"height":0,"name":"SolarCurrant","label":"Solar Currant (A)","format":"{{msg.payload}}","layout":"col-center","x":2450,"y":1140,"wires":[]},{"id":"47bf6dd3.0d5914","type":"ui_text","z":"6d01e3e4.6003b4","group":"92374fdb.9d242","order":2,"width":5,"height":1,"name":"BatteryVoltage","label":"Battery Voltage (V)","format":"{{msg.payload}}","layout":"col-center","x":2460,"y":1220,"wires":[]},{"id":"5f356d06.8ec164","type":"ui_text","z":"6d01e3e4.6003b4","group":"92374fdb.9d242","order":1,"width":5,"height":1,"name":"BatteryCurrant","label":"Battery Currant (A)","format":"{{msg.payload}}","layout":"col-center","x":2460,"y":1260,"wires":[]},{"id":"b0357751.cec228","type":"ui_text","z":"6d01e3e4.6003b4","group":"d0e60a67.4d8d6","order":1,"width":5,"height":1,"name":"LoadCurrant","label":"Load Currant (A)","format":"{{msg.payload}}","layout":"col-center","x":2450,"y":1380,"wires":[]},{"id":"2c61bd87.973f32","type":"ui_text","z":"6d01e3e4.6003b4","group":"d0e60a67.4d8d6","order":2,"width":5,"height":1,"name":"LoadVoltage","label":"Load Voltage (V)","format":"{{msg.payload}}","layout":"col-center","x":2450,"y":1340,"wires":[]},{"id":"8a9b8518.d2c828","type":"ui_text","z":"6d01e3e4.6003b4","group":"3bf43a81.2b807e","order":3,"width":0,"height":0,"name":"SolarPower","label":"Solar Power (W)","format":"{{msg}}","layout":"col-center","x":2450,"y":1180,"wires":[]},{"id":"a138ac27.5e428","type":"ui_text","z":"6d01e3e4.6003b4","group":"92374fdb.9d242","order":5,"width":5,"height":1,"name":"BatteryPower","label":"Battery Power (W)","format":"{{msg.payload}}","layout":"col-center","x":2460,"y":1300,"wires":[]},{"id":"d3fcfa11.a265b8","type":"function","z":"6d01e3e4.6003b4","name":"modbus data (simulated)","func":"msg.responseBuffer = { \n        \"data\": [3067, 135, 5244, 0, 2760, 190, 5244, 0, 2760, 1, 0, 0, 0, 0, 0, 0, 0], \n        \"buffer\": Buffer.from([11, 251, 0, 135, 20, 124, 0, 0, 10, 200, 0, 190, 20, 124, 0, 0, 10, 200, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2130,"y":1140,"wires":[["86b69c2.13b806"]]},{"id":"ee7de627.aef7b8","type":"inject","z":"6d01e3e4.6003b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":2080,"y":1080,"wires":[["d3fcfa11.a265b8"]]},{"id":"3bf43a81.2b807e","type":"ui_group","name":"Solar Information","tab":"28c10730.74ad38","order":1,"disp":true,"width":5,"collapse":true},{"id":"92374fdb.9d242","type":"ui_group","name":"Battery Information","tab":"28c10730.74ad38","order":2,"disp":true,"width":5,"collapse":false},{"id":"d0e60a67.4d8d6","type":"ui_group","name":"DC Load Information","tab":"28c10730.74ad38","order":3,"disp":true,"width":5,"collapse":false},{"id":"28c10730.74ad38","type":"ui_tab","name":"Solar PV Equipment","icon":"dashboard","disabled":false,"hidden":false}]

Cheers pal.

{"topic":"livestats","messageId":"60aa5b1e01097b3a141c90af","payload":[3829,107,4104,0,2755,149,4104,0,2755,0,0,0,2755,0,0,0,1295,1923],"queueLengthByUnitId":{"unitId":2,"queueLength":0},"queueUnitId":2,"unitId":2,"modbusRequest":{"unitid":2,"fc":4,"address":12544,"quantity":18,"emptyMsgOnFail":false,"keepMsgProperties":false,"messageId":"60aa5b1e01097b3a141c90af"},"responseBuffer":{"data":[3829,107,4104,0,2755,149,4104,0,2755,0,0,0,2755,0,0,0,1295,1923],"buffer":[14,245,0,107,16,8,0,0,10,195,0,149,16,8,0,0,10,195,0,0,0,0,0,0,10,195,0,0,0,0,0,0,5,15,7,131]},"_msgid":"80ecd545.37ef48"}

@swanside Your switch is testing msg.parts.index but checking for strings but msg.parts.index is a numeric. In addition, instead of checking for 10 and 11 you check for E and F.

However the real issue is the join. The msgs passed to the join have a msg.parts.index of 2 and 3. Then you join them into an array and it does what you have told it to do. It sticks those two msgs into the array at position 2 and 3 but since an array atarts at 0, you get an array with two undefined entries.

While there might be other ways to fix this, you could add a change node to the output of switch 2 and set msg.part.index to 0 and another change node to the output of switch 3 and set msg.part.index to 1

Note: this issue will also crop up in the other join nodes after the switch.

For that data, from what I can see from your flow, these are the values i get...

image

Do they ↑ look correct?


Do you have a manual or specification - something like...

register name type example value unit
3100 Solar voltage int16 x100 38.2 v
3101 Solar current int16 x100 1.0 v
3102 etc etc etc etc
3103 etc etc etc etc

Yep. They doo look right.





Hi, looking at those screenshots, I doubt what I or you have was correct.

  • You are reading 18 values from modbus address 0x3100 - you will never reach values in 3200 or 3300 range.
  • Address 310C (Load voltage) is actually at decimal address 12556 (in the 12th element of the array)
  • Also, addresses 3102/3103 were being arranged as Big Endian (i believe they should be Little Endian)

Anyhow, I will show you how to use buffer-parser to get all the values you need.

NOTE ON BUFFER-PARSER:
If you READ a quantity of 18 values from from modbus address 0x3100 (AKA address 12544) then you will get 18 INT16 values from 0x3100 ~ 0x3112 - in terms of a buffer, that is 36 bytes.
the first 2 bytes will be the value of 0x3100. Bytes 2&3 will be the value of address 0x3101 etc

In the below example, you can see address 3102 is found in the buffer at BYTE 4 and it is set to be read as an INT32LE

Below is an export of the buffer parser with columns set to match your documentation (for the items in address range 0x3100) - you will need to do a separate 2nd and 3rd modbus read for addresses 0x3200 and 0x3300 + fill in the buffer parser as I have shown

[{"id":"6db47ce1.1a1c04","type":"buffer-parser","z":"6d01e3e4.6003b4","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"SolarVoltage","offset":0,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"SolarCurrant","offset":2,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int32le","name":"SolarPower","offset":4,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"LoadVoltage","offset":20,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"LoadCurrant","offset":22,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int32le","name":"LoadPower","offset":24,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"BatteryTemperature","offset":34,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"int16be","name":"CaseTemperature","offset":36,"length":1,"offsetbit":0,"scale":"/ 100","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":true,"setTopic":true,"outputs":8,"x":2210,"y":760,"wires":[["30eef1da.d3dc3e"],[],[],[],[],[],[],[]]}]
1 Like

Thank you.
I really appreciate that, will give me something to work on now.
Thanks again
Paul.

Just one more thing.. Sorry about this, but getting a scale.matchall is not a function on the buffer?
Thanks

What version node are you running?

Open a terminal, enter node -v

1 Like

Sorry pal. Yep just ran a full upgrade.
When I ran this
node -v I got v10.24.0
npm -v I got 5.8.0

Ran this bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

node -v I got v12.22.1
npm -v I got 6.14.12

I then got an error on the buffer, something about offset needs to be >0 and less than 34 received 36, so I deleted the last offset and now I am getting values.
Thank you so much for your help. Will expand on this now to get everything.

1 Like

So, and sorry ask, but When I am reading a L and a H, such as in this, I have 0x3304 (13060 Dec) and 0x3305 (13061 Dec) But the Buffer Start Byte for 3304 I am guessing will be 8, and as its an int32, it will pick up the L and the H as it is displaying 7.68 which I would say is Wattage? Have I got this or am I completely off track?
Cheers
image

image

If you read (for example) a quantity of 18 values from modbus address 0x3300 then yes, your spreadsheet table is correct and 0x3304 will be at byte 8. By asking buffer-parser to read an int32le/be (4 bytes) starting at offset 8 you WILL get the registers 0x3304 and 0x3305

Is that what you are asking?

It was. Thanks. Starting to get my head around it now. Cheers

1 Like

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