Groov EPIC Serial communition module use in Node-RED

While there is no groov Manage API access to the 4 port groov EPIC Serial Communication Module (yet - and if you need it, please please let me know!), Node-RED talks to the module just fine. Here is how to get started.

Use groov Manage to set the serial port type. This is important as its the only way (without using a PAC Control strategy) to set the serial port mode and termination if required.

Next, open up the Node-RED editor and head over to the manage palette menu and install the ‘serialport’ node(s).

I tested the receive node with an RS-232 GPS receiver that I happen to have sitting on my desk.

It is as simple as it looks to get started.
Drag the input (receive) node over. Add a new serial port, see this forum post here for more information on their names.
Configure the baud rate, stop bits and parity.

From here you are up and running and can start to see the data you have coming in.

Sending data is much the same.
Drag the serial send node over and inject (for a test) your message.

From here, you have the basics to get started sending and receiving data from the GRV-CSERI-4.

[Note that this is very (very) similar to using the USB to Serial adapter as mentioned in this forum post here].

From here you are kind of only limited by your imagination and Node-RED skills.
For example, you could open a groov EPIC firewall port and listen for http data coming in that you wanted sent to the serial module… sort of like a home spun API if you will.

IMPORTANT EDIT. I have found that if you run Node-RED and PAC Control with serial commands addressing the same serial port, you get undesired results. So in short, pick one method and stick with it.

2 Likes

" IMPORTANT EDIT. I have found that if you run Node-RED and PAC Control with serial commands addressing the same serial port, you get undesired results. So in short, pick one method and stick with it."

Indeed…and there are similar issues with MODBUS rtu/serial nodes…I am working on that problem as I type this…as soon as more than one slave is added, there are problems. Need to confirm if this is an issue in the node itself or a PAC conflict…

If all those Modbus nodes are using the same serial port then that is likely a problem. Node-red will operate asynchronously, so multiple nodes will try to write/read on the serial port at the same time.

You didn’t specify which modbus node red library you are using, but you likely need to change your design to have only a single Modbus Serial In node for each serial port and then use a switch node based on your slave ID and requested register(s) to direct the output to the correct PAC write node.

Edit: I think you may be using node-red-contrib-serial-modbus. I took a look at that module and it probably won’t work for you - it is quite limited. I would suggest using node-red-contrib-modbus and use the “modbus getter” node which is implemented as a function node so you can call separate nodes sequentially. This is a more mature node-red module than the one you are using.

Hi philip,

Thanks for the suggestion. I did implement “getter”/flex getter etc earlier on. I had similar issues with it. They are certainly timing related. So far this has been the most stable topology, but still has it’s problems.

I have ruled out PAC conflicts for this flow, but had them in another flow (controlling a PDU). I was hoping it was the serial port I left open in PAC (com handle), but I do believe it is the limitations of this node.

Extra info about how to use serial communication via Python.

I’ve just done some basic testing of this and wanted to document it in case anyone else wants to use this in their own applications. It will, of course, require a shell license, and uses the pySerial Python package for Python 2.7 or Python 3.4 (I tested with 2.7).
To use it you’ll start by updating your apt-get repository, install Python pip, use pip to install pySerial, then you can use it in your script. Here’s that step-by-step:

sudo apt-get update
sudo apt-get install python-pip
sudo pip install pySerial

Then use import serial at the top of your script. Further documentation of how to connect to a device and send / receive data can be found on the pySerial page: pyserial.readthedocs.io/en/latest/shortintro


Two more things to keep in mind are that first, you must run your script as sudo, since the path to your serial device will be /dev/ttyUSB0 through /dev/ttyUSB3, which is pathed for the dev user, not the shell user. Secondly, you cannot run the script while the serial device is communicating with another service like Node-RED.

Happy coding!

Hello Guys,
I am getting the following errors while connecting temperature sensor to groov epic.

Invalid data on Node Red in case of Temperature Sensor:

Can anyone please help me out ?
Thanks,
Megha

Can you share a little more information?
You have posted in a serial module thread, but that does not seem to be a serial module error.

Take a step back and describe how the temperature sensor is connected, what module and what nodes and your flow outline.

Thanks.

I am using Modbus Read node in both case energy meter and temperature sensor .
In case of temperature sensor, I am getting invalid constant data.

Temperature Sensor Configuration in Node Red


Modscan Simulator Configuration:


In Modscan for energy meter and Temperature Sensor I am getting correct value.

Thanks,
Megha

Energy Meter configuration with node Red including error


Modscan Simulator for energy meter

Please do not post the same question in different threads. The one thread will be read by everyone. I have deleted your other duplicate posts from the other thread as they will not also get a reply.
Also, keep in mind we all live in different time zones.

I see some confusion between screenshots and not enough information for us to really say for sure what the issue is.
First up. One Node-RED screenshot shows a baud rate of 19200, the other shows a baud of 9600 and you do not show what modscan64 is configured as, so we are unable to help at the most basic level of what baud rate the energy meter is expecting.

EDIT:
Secondly, you are testing two different registers in Modscan64. I suggest that you just focus on one value in Modscan and the same register in Node-RED. Get that one value reading correctly before adding a second.

Modscan addresses (really registers) start at 1, the node-red-contrib-modbus addresses start at 0. So you need to subtract 1 from the address in Node-Red.

The resulting two registers returned will need converted to a floating point in your node-red flow. There are many ways to do that, here is one, assuming big endian:

let a = msg.payload;
let a1 = (a[0] >> 8) & 255;
let a2 = a[0] & 255;
let a3 = (a[1] >> 8) & 255;
let a4 = a[1] & 255;
const buf = Buffer.from([a1,a2,a3,a4]);
let floatVal = buf.readFloatBE(0);
2 Likes

Thanks for response and Actually I am using two serial device to communicate with groov epic .

  1. Energy Meter EM6400NG
  2. Temperature Sensor TW2LPXA

With Energy Meter I am trying to read the frequency which is at 3110 register (which is Read holding register) address along with energy meter default settings like baud rate - 9600 , parity- even , stop bit- 1 and device Id -1 .

In node red debug window , getting the following error-

" Error: Modbus exception 3: Illegal data value (value cannot be written to this register)".

And with Temperature sensor, I am reading temperature which is at register address 1 and 2 both (which is Read Input Register) along with sensor settings like baud rate-19200 , parity - None , stop bit -1 , device Id - 5 . In node red I am getting some constant value which is 256 that I am not sure whether it’s valid or not.

Please let me know if you required more info.

Thanks,
Megha

Hello @philip / @Beno , Regarding energy meter I have got the correct frequency value in node red in integer format which is 16967 . In order to the conversion I am using below code-

msg.payload = (msg.payload / 99999 * (65 - 45) + 45).toFixed(1);
return msg;

Above code is throwing error like “Nan” in node red debug window.

Here frequency range - (minimum -42) and (maximum - 70) for energy meter EM6400NG.

I need to convert the integer value into float .

Can you please help me out?

16967 is not the right result.

Have you tried reading the data one address lower in Node-Red? 3109 for the frequency and 0 for the temperature?

The result should be two registers, so you should have two values for each. What is in the payload array after changing to the correct address (register - 1) and reading 2 registers? There is no use in trying to convert data that is from the wrong registers.

One more thing @philip I don’t have knowledge of java script properly , so please correct if I will be worng.
Actually I have reduced the register address -1 means actually it was 3110 , 3110-1=3109 I have got the register value 16967 and after conversion with below code.

var rawData = new ArrayBuffer(4);

var fltView = new Float32Array(rawData);

var intView = new Uint16Array(rawData);

intView[0]= msg.payload[1];

intView[1]= msg.payload[0];

msg.payload = parseFloat(fltView[0].toFixed(2));

msg.topic = “Frequency”;

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

return msg;

I have got the exact frequency in node red.
Please confirm whether above code is any integer value into float .

For temperature reading on 0th address I am getting some values like in node red by following the data sheet of temperature sensor.

Indeed it requires conversion but I am not sure which code I should follow because if I will follow the conversion code which I have shared with you so I am not getting the correct value for temperature .

Please do the needful for the same.
Thanks

The temperature values is stored with the least significant 16 bits first. (modbus little endian).

Again, there are many ways to convert this to a float, here is one that is using the ArrayBuffer that you are using for the frequency. The first line of your debug output [45491, 16853] converts to 22.212.

// Create a buffer
const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);
//Assign 16 bit swapped values (modbus little endian)
view.setUint16(0, msg.payload[1]);
view.setUint16(1, msg.payload[0]);
//Get the float value
let floatVal = view.getFloat32(0);
msg.payload = floatVal;
1 Like

@philip ,with the above code I am unable to get the proper output regarding temperature value which is collected by the temperature sensor.


Can you please help me out ?
Thanks,

How?

Please show us the payload output from the modbus node and show us your function logic.

I am using the above code for conversion of integer into float .