question

michael-protogerakis avatar image
michael-protogerakis asked

Gathering EM24 data via nodered

I have a EM24 Ethernet as part of an ESS. Is it possible to gather data from the EM24 via nodered through one of the Victron nodes?

If not, is there an example anywhere of how to poll data from the EM24 Ethernet in parallel to the GX via Modbus TCP from nodered?

ESSNode-REDem24
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

4 Answers
hominidae avatar image
hominidae answered ·

...most lightweight approach with node-red would be to use mqtt, as this comes natively with it.

Just enable mqtt in the GX and check, i.e. with mqttexplorer what the GX publishes to its broker and which topics you want to subscribe to.

Enable the GX to publish the required topics with keepalive.
See: https://github.com/victronenergy/dbus-mqtt#keep-alive

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

michael-protogerakis avatar image
michael-protogerakis answered ·

works perfect. thank you so much.


Using modbus tcp it would look like this

1685387030678.png


The left node is "Modbus-Read" is configured like in the picture below.

https://www.enika.eu/data/files/produkty/energy%20m/CP/em24%20ethernet%20cp.pdf describes the modbus registers to read. "Sum W" is under address 0028h which is 40 in decimal and consists of 2 16bit words.

1685387095067.png


Converting those two words to a valid 32bit Integer Value can be done like this in the JavaScript function block:

var rawData = new ArrayBuffer(4);
var intView = new Uint16Array(rawData);
var int32View = new Int32Array(rawData);


intView[0] = msg.payload[0]; //low
intView[1] = msg.payload[1]; //high


msg.payload = int32View[0].toFixed(1)/10.0;
msg.topic = "power";


node.status({fill:"blue",shape:"ring",text:msg.topic + ":" + msg.payload});    


return msg;


Of course the dbus-mqtt solution is much more elegant.

1685387347149.png


with the contents
1685387386784.png



1685387455688.png


1685387030678.png (43.4 KiB)
1685387095067.png (130.9 KiB)
1685387347149.png (171.9 KiB)
1685387386784.png (114.1 KiB)
1685387455688.png (95.9 KiB)
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

hominidae avatar image hominidae commented ·

nice. Note, that IMHO with modbus read node, the conversion in the function node could me much more simple, when using the Response Buffer, not the data-bytes.

This is for a Bernecker MPM3PM meter, that I use outside of the victron ecosystem/GX.

1685437706032.png


For a signed 32bit BigEndian Buffer, coming from the modbus-read node, this is what I do:

var W = 0;
W = parseInt(msg.responseBuffer.buffer.readInt32BE() / 100);
msg.payload = W;
return msg;
0 Likes 0 ·
1685437706032.png (30.9 KiB)
markus-001 avatar image
markus-001 answered ·

You can also use the Victron node grid meter the EM24 Ethernet publishes a few basic values in that node which might be just what you need.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

stadlix avatar image
stadlix answered ·

I recently spent a few days trying to understand how to read a 32-bit signed integer (INT32) from a Modbus device using Node-RED, as I had no prior experience with Modbus. I want to share my findings to help others who might encounter a similar situation.

To read a 32-bit signed integer (INT32) from an EM24 using Node-RED, follow these steps:

  1. Create a Modbus Read node in Node-RED that starts reading at address 40 (0x28 in hexadecimal) for a length of two. This means that two consecutive 16-bit registers will be read:
    • Address 40 contains the "Least Significant Word" (LSW).
    • Address 41 contains the "Most Significant Word" (MSW).
  2. Combine the LSW and MSW values into a single 32-bit value.
  3. Convert the combined 32-bit value to decimal using 2's complement notation.

Here's an example of how to process the Modbus data in Node-RED using a function node:

const lsw = msg.payload[0];
const msw = msg.payload[1];

const uint16Array = new Uint16Array([lsw, msw]);
const int32Array = new Int32Array(uint16Array.buffer);

const result = int32Array[0];

msg.payload = {
  Watt: result
}

return msg;


Node-RED:

Note the two registers in the Response node: 192; 0

1711882967034.png

Modbus Read:

1711882850756.png


https://gavazzi.se/app/uploads/2020/11/em24_is_cp.pdf

28h is hex for 40

1711882889748.png




1711882850756.png (21.4 KiB)
1711882889748.png (392.4 KiB)
1711882967034.png (83.9 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.