Bufferparser with U64 Modbus

you made my day :kissing_heart:
I almost had it, only the offset was wrong. :unamused: :smirk:

1 Like

After I got the new Node Red I´m able to use the 64bit buffer parser, but my function node don´t like it:
grafik

[{"id":"484de3fc.dbd88c","type":"function","z":"9f6752b0.b55988","name":"Lad","func":"msg.payload = msg.payload.BattLad / 1000;\nmsg.topic = \"BattLad\";\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":2600,"wires":[["6b32c16d.b6668","51829bda.9ae57c"]]},{"id":"eebff845.4ef8e","type":"function","z":"9f6752b0.b55988","name":"Ent","func":"msg.payload = msg.payload.BattEnt / 1000;\nmsg.topic = \"BattEnt\";\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":2660,"wires":[["51829bda.9ae57c","d08f2090.47383"]]},{"id":"a328886e.cec65","type":"ui_text","z":"9f6752b0.b55988","group":"d5972738.a29c7","order":3,"width":0,"height":0,"name":"Ladung gesamt","label":"Ladung gesamt","format":"{{msg.payload}} kWh","layout":"row-spread","x":1100,"y":2600,"wires":[]},{"id":"d9e56ae3.ad8488","type":"ui_text","z":"9f6752b0.b55988","group":"d5972738.a29c7","order":4,"width":0,"height":0,"name":"Entladung gesamt","label":"Entladung gesamt","format":"{{msg.payload}} kWh","layout":"row-spread","x":1110,"y":2660,"wires":[]},{"id":"6b32c16d.b6668","type":"function","z":"9f6752b0.b55988","name":". zu ,","func":"msg.payload = msg.payload.toFixed(2).replace('.', ',');\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":2600,"wires":[["a328886e.cec65"]]},{"id":"d08f2090.47383","type":"function","z":"9f6752b0.b55988","name":". zu ,","func":"msg.payload = msg.payload.toFixed(2).replace('.', ',');\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":2660,"wires":[["d9e56ae3.ad8488"]]},{"id":"7c44097e.a01888","type":"buffer-parser","z":"9f6752b0.b55988","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"biguint64be","name":"BattEnt","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":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":570,"y":2600,"wires":[["484de3fc.dbd88c","eebff845.4ef8e"]]},{"id":"d5972738.a29c7","type":"ui_group","name":"SBS 2.5","tab":"69ee5cda.ec1a2c","order":2,"disp":true,"width":"5","collapse":false},{"id":"69ee5cda.ec1a2c","type":"ui_tab","name":"Batterie","icon":"fa-battery-half","order":2,"disabled":false,"hidden":false}]

what must I do with the function node ?

Could you provide sample buffer of data to test?

I seen this a while back but thought I had handled it.

Also, what version of buffer parser you using?


EDIT...

Never mind, it is your function at error.

{"topic":"cd1d4476.573438","messageId":"5fe0f1369fefd7c3f6a4f86f","payload":{"BattLad":"76122","BattEnt":"64273"},"queueLengthByUnitId":{"unitId":3,"queueLength":0},"queueUnitId":3,"unitId":3,"modbusRequest":{"value":{"IS":0},"unitid":"3","fc":4,"address":"31397","quantity":"8","messageId":"5fe0f1369fefd7c3f6a4f86f"},"responseBuffer":{"data":[0,0,1,10586,0,0,0,64273],"buffer":[0,0,0,0,0,1,41,90,0,0,0,0,0,0,251,17]},"_msgid":"dd0262c0.2811","originalPayload":[0,0,1,10586,0,0,0,64273],"specification":{"options":{"byteSwap":[],"resultType":"keyvalue","singleResult":true,"msgProperty":"payload","setTopic":true},"items":[{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"","id":0,"value":"76122"},{"type":"biguint64be","name":"BattEnt","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":"","id":1,"value":"64273"}]},"values":["76122","64273"],"objectResults":{"BattLad":{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"","id":0,"value":"76122"},"BattEnt":{"type":"biguint64be","name":"BattEnt","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":"","id":1,"value":"64273"}},"keyvalues":{"BattLad":"76122","BattEnt":"64273"},"arrayResults":[{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"","id":0,"value":"76122"},{"type":"biguint64be","name":"BattEnt","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":"","id":1,"value":"64273"}],"buffer":[0,0,0,0,0,1,41,90,0,0,0,0,0,0,251,17]}

the value will rise about +2000kWh = 2.000.000Wh every year

After a liftime of the inverter it can be at 100.000.000Wh

OK, so first up, bigint number constants should be specified with an n e.g. 1000n

Basically, you cannot mix bigint and numbers (Im sure I mentioned difficulties with bigint earlier?)

any how, this is the error...

function Lad

msg.payload = msg.payload.BattLad / 1000; //<<<< 1000 is an int!

should be ...

msg.payload = msg.payload.BattLad / 1000n; /// <<< 1000 as a bigint

BUT - that is not the end of the problem.

When you come to use the payload in the next nodes downstream probably, they likely wont like bigint either!

The only solution is to cast the bigint into a number type & hope (or check) that it isnt > max safe integer

I propose wherever you have a bigint, that you do this....

msg.payload = Number(msg.payload.BattLad / 1000n);
1 Like

hmm


now its rounded:
grafik

got it:

msg.payload = Number(msg.payload.BattLad / 1n)
msg.payload = msg.payload / 1000
msg.topic = "BattLad";
return msg;

Use this instead...

msg.payload = Number(msg.payload.BattEnt) / 1000;

Also, delete the functions that call toFixed and use angular formatting...
image

1 Like

better :grinning:

i use the , for . function
msg.payload = msg.payload.toFixed(2).replace('.', ',');

because I like the comma between numbers.
Is there a "angular formatting" for . to , ?

There is i18n formatting for angular but I dont think it is included with dashboard.

Anyhow, if you are using NODE -v 14 or greater, you can use...
number.toLocaleString("de-DE", {minimumFractionDigits: 2});

e.g...

var n = Number(msg.payload.BattEnt) / 1000;
msg.payload = n.toLocaleString("de-DE", {minimumFractionDigits: 2}));

however, any US or English folk will be very confused :stuck_out_tongue_winking_eye:

toLocaleString does´t work.
I installed NR yesterday !
v12.20.0 :fearful:

by the way, can I affect the socketid ? --> "IP:1880/ui/#!/0?socketid=AnUFbQQ1zxQzKf9sAAAL"
can I change "AnUFbQQ1zxQzKf9sAAAL" to a name that I determine ?

I don't know. Best start a new thread with appropriate title.

where do I get Node V 14?

How did you install nodejs in the first place?

Did you apt install nodejs?

If you use the official node-red script to install node-red you should get node 14 (I think) but nodejs installation will be skipped if you already installed it.

What does
apt-cache policy nodejs
show?

I installed Node Red as suggested:

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

grafik

:face_with_monocle:

The script sees version 12.20 as a valid version and will not upgrade.
The same we saw with version 10 that was untouched.

I believe you have to first remove node js
sudo apt remove nodejs

then following this Article download and install Node.js v14.x :

Using Debian, as root ( use sudo )

curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs

Do another backup and you may need to possibly clean node js cache also.
Somebody with more experience with the procedure can advice you more

1 Like

Alternatively you should just be able to edit the file /etc/apt/sources.list.d/nodesource.list and change all the 12.x in there to 14.x then run
sudo apt update
sudo apt full-upgrade
which should upgrade nodejs to 14.x as well as upgrading anything else in the system that needs upgrading.

Once you have upgraded nodejs either by this method or the post above then run the install script again as you need to re-install node-red and rebuild any nodes already configured. The script will not downgrade nodejs.

1 Like

is there a reason why it installs 12, x instead of 14,x ?
Isn´t it stable ??

When a new version of nodejs is released there are always some nodes, mostly contrib nodes, that require some work to make them compatible, for that reason the script tends to lag behind a bit in order to allow time for the nodes to catch up. I believe that 14 will become the recommended version fairly soon.

1 Like

thanks, I have contrib :smile:
I´ll wait