Bufferparser with U64 Modbus

Can you show us what you get from this (its a small flow built from your modbus data...

image

[{"id":"744c02e3.3e785c","type":"inject","z":"f0c54878.b7be68","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1160,"y":80,"wires":[["61ef089f.2338a8"]]},{"id":"61ef089f.2338a8","type":"function","z":"f0c54878.b7be68","name":"modbus data","func":"\nreturn { \"topic\": \"bc57293c.b45d5\", \n\"messageId\": \"5fcd1a9b7eae09b6296c0167\", \n\"payload\": [0, 0, 0, 53199, 0, 0, 0, 46520], \n\"queueLengthByUnitId\": { \"unitId\": 3, \"queueLength\": 0 }, \n\"queueUnitId\": 3, \"unitId\": 3, \n\"modbusRequest\": { \n    \"value\": { \"T3\": 28.8 }, \"unitid\": \"3\", \"fc\": 4, \"address\": \"31397\", \"quantity\": \"8\", \"messageId\": \"5fcd1a9b7eae09b6296c0167\" }, \"responseBuffer\": { \"data\": [0, 0, 0, 53199, 0, 0, 0, 46520],\n     \"buffer\": Buffer.from([0, 0, 0, 0, 0, 0, 207, 207, 0, 0, 0, 0, 0, 0, 181, 184]) }, \n\"_msgid\": \"61620b69.6a03b4\" };","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1170,"y":140,"wires":[["b0563f39.60a0d"]]},{"id":"b0563f39.60a0d","type":"buffer-parser","z":"f0c54878.b7be68","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"bigint64le","name":"bigint64le","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"bigint64be","name":"bigint64be","offset":0,"length":1,"offsetbit":0,"scale":"1","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":1190,"y":200,"wires":[["42c0eecc.55333"]]},{"id":"42c0eecc.55333","type":"debug","z":"f0c54878.b7be68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1220,"y":260,"wires":[]}]

TypeError: Cannot read property 'bind' of undefined

:nauseated_face: :roll_eyes:

whats wrong with my NR - I see, its working at your NR

the OS is old, 9 (Stretch) :woozy_face:

hmmmm

:thinking:

Can you add a catch and link it to a debug node set to show complete message and paste the content of that msg in a reply please?

catch ? Don´t know how to

image

[{"id":"87dc0eac.9baeb","type":"catch","z":"f0c54878.b7be68","name":"","scope":null,"uncaught":false,"x":1090,"y":360,"wires":[["62ec60f.62ed9a"]]},{"id":"62ec60f.62ed9a","type":"debug","z":"f0c54878.b7be68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1240,"y":360,"wires":[]}]

In this thread Nick mentions that reading 64bit ints from buffer was added in Node 12

It might be a factor but MDN says otherwise

maybe this ? v12 and v10.20

Not sure what you mean @UnborN

If you select the V10 dropdown on the nodejs docs & look at API for node buffer it does support the bigint functions

got it:

{"topic":"bc57293c.b45d5","messageId":"5fcd1a9b7eae09b6296c0167","payload":[0,0,0,53199,0,0,0,46520],"queueLengthByUnitId":{"unitId":3,"queueLength":0},"queueUnitId":3,"unitId":3,"modbusRequest":{"value":{"T3":28.8},"unitid":"3","fc":4,"address":"31397","quantity":"8","messageId":"5fcd1a9b7eae09b6296c0167"},"responseBuffer":{"data":[0,0,0,53199,0,0,0,46520],"buffer":[0,0,0,0,0,0,207,207,0,0,0,0,0,0,181,184]},"_msgid":"ad050b0c.bb6fb8","originalPayload":[0,0,0,53199,0,0,0,46520],"error":{"message":"TypeError: Cannot read property 'bind' of undefined","source":{"id":"b0563f39.60a0d","type":"buffer-parser","count":1},"stack":"TypeError: Cannot read property 'bind' of undefined\n    at dataGetter (/home/pi/.node-red/node_modules/node-red-contrib-buffer-parser/buffer-parser.js:373:49)\n    at itemReader (/home/pi/.node-red/node_modules/node-red-contrib-buffer-parser/buffer-parser.js:338:30)\n    at parser (/home/pi/.node-red/node_modules/node-red-contrib-buffer-parser/buffer-parser.js:461:25)\n    at bufferParserNode._inputCallback (/home/pi/.node-red/node_modules/node-red-contrib-buffer-parser/buffer-parser.js:786:31)\n    at hooks.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:203:26)\n    at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/hooks.js:113:9)\n    at bufferParserNode.Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:195:11)\n    at bufferParserNode.Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:179:25)\n    at bufferParserNode.Node.receive..."}}

Can the old OS (Strech) be to blame?

I mean maybe there is a difference between defining/using a bigint as a variable and converting it from buffer
I dunno internally what you use in Buffer-parser but if its the buf.readBigInt that was introduced in node v10.20 and Becker is using

Ah - ok, i see where you are going with that (I missed the small print Added in: v10.20.0).

so yes, it is that. And is confirmed by the caught message...

TypeError: Cannot read property 'bind' of undefined\n at dataGetter (/home/pi/.node-red/node_modules/node-red-contrib-buffer-parser/buffer-parser.js:373:49)

var fn = buffer[bufferFunction].bind(buffer);

^ this attempts to bind the selected function (in this case readBigInt64BE). I will look to update the node to better report the issue but the only solution for BigInt is to update node.js to a newer version.

so, @Becker - it looks like you need to update node.js


NOTE: I do suspect the the value is less than 32bit MAX so you could likely just grab the 32bits...

but as node 10 is EOL in 4 months - might be a good time to jump to node 12 or better still node 14.

running the script should update your node version :

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

Installing and Upgrading Node-RED

I did, but it doesn´t update:

==> v10.16.3

I don't think the script updates from V10 (only < 10).

If you were to uninstall node& npm manually and run it again, it will work.

but then the "NibePi" will be destroyed maybe :roll_eyes:
I got an image: https://github.com/anerdins/node-red-contrib-nibepi/
"nibepi_1.1_clean.rar" with integrated Node RED, what I've built everything on!

I´ve no idea to make a clean basic installation with NibePi.

My wish would be to install the latest Raspbian, then install the latest NR and install NibePi in the NR myself. I have to speak to the developer of NibePi...

For a clean install, first backup your flows, update os, install node-red via the script, install nibepi like you would any other node, import your flows.

If you have a spare SD CARD, use that - it might save you if you forget something.

NibePi is not just a flow, it is "deeper". It simulates a Modbus Gateway over RS485 (https://www.nibe.eu/assets/documents/24801/031725-10.pdf) - i have no idea to "save" and reinstall.

Yes, I agree. It would be safer to talk to the manufacturer of this device and let them issue a new image. In the meantime maybe do as Steve suggested earlier and do 2 32bit reads.

1 Like

Hi all,

I was reading about this node version update/downgrade manager program called n.
would it be safe if Becker installed n, update to the minor node 10.20 version and test if bigInts work.
With n he'll have the option to revert back to older version in case something breaks with NibePi?!

Command to Intall n globally
sudo npm install -g n

Install node version 10.20 using n
sudo n 10.20.0

Check node version
node -v

Option to choose different node red version that was installed
n

Has anyone used it ? .. any implications with installation paths etc ?