The SDM230 series is an advanced multifunction single-phase energy monitoring solution with optional outputs such as Pulsed, RS485 RTU Modbus and Mbus. Equipped with configuration and display buttons for ease of navigation through the various parameters and settings. Housed for DIN rail mounting, IP51 protection and direct connection up to 100A. Selectable measurement modes using our free configurations software for kWh display, Total kWh (Import + Export), Import kWh and Net kWh (Export - Import) Certified in the UK according to EU Directive 2014/32/EU. MID Certificate number 0120 / SGS0206.
In this article, we demonstrate how to connect the SDM230M Series to a Modbus master using Modbus RTU. We then show how the Modbus master sends the collected data to Ubidots using HTTP.
Requirements
An active Ubidots account
A Modbus RTU master device with Node-RED.
1. Setup
Connect the SDM230M Series to your power network according to your requirements. Below is a brief connection schematic. For detailed instructions, refer to the datasheet.
Once the power lines are connected, connect the SDM230M Series to the Modbus master via the RS-485 interface.
Modbus connection baud rate
This guide uses a 9600 baud rate. For other baud rate settings, please consult the configuration manual.
2. Modbus master configuration
Make sure that your device's Node-Red installation features the "Modbus Read" node, if not the case, please head to the following link to get information regarding the installation process.
Navigate to the Node-RED interface on your Modbus master device and search for "Modbus" in the node palette.
Add a "Modbus Read" node to your flow. Once placed, double click on it and then click the "Add new modbus-client..." button. This will display the Serial configuration for the modbus master:
Here, configure the Serial parameters according to your setup. In this guide, the following settings were used:
Baud rate: 9600.
Modbus master address: 1.
Configure the other settings as you require.
After saving the previous changes, you'll return to the "Modbus Read" node configuration. This node is set to read the "Line to Neutral Volts" variable. Use the configuration below to obtain this variable's value, or adjust the "Address" as needed for your setup. For information on the variables and their Modbus addresses, refer to the following reference manual.
Optional: retrieve "current" and "total active energy" variables
Add other two "Modbus read" nodes and configure them as shown above, only changing the "Address" to match the following addresses for each variable:
Variable | Modbus address (Hex) | Modbus address (Dec) |
line to neutral volts | 00 | 00 |
current | 06 | 06 |
Total active energy | 56 | 86 |
After that, you'll have 3 "Modbus read" nodes:
Drag and drop 3 "function" modules and connect each to the output of the "Modbus read" nodes as shown below:
Double click on any of the "function" nodes previously placed and paste the following code, you only have to replace the variable name:
// Access the msg.payload which contains the object
const bufferArray = msg.payload.buffer;
// Extract bytes from the buffer array
const highByteFirstRegister = bufferArray[0] & 0xFF;
const lowByteFirstRegister = bufferArray[1] & 0xFF;
const highByteSecondRegister = bufferArray[2] & 0xFF;
const lowByteSecondRegister = bufferArray[3] & 0xFF;
// Combine bytes into a 32-bit integer (big-endian)
const combinedValue = (highByteFirstRegister << 24) |
(lowByteFirstRegister << 16) |
(highByteSecondRegister << 8) |
lowByteSecondRegister;
// Convert to floating-point number using IEEE 754 format
const float32Buffer = new ArrayBuffer(4);
const float32View = new DataView(float32Buffer);
float32View.setUint32(0, combinedValue, false); // false for big-endian
// Replace variable name here instead of "voltage"
const voltage = float32View.getFloat32(0, false); // false for big-endian
// Replace variable name here instead of "voltage" (the key)
return { payload: { voltage: voltage } };
Do the same for the other 2 function nodes, only changing the variables names according to your requirement. Add another "function" node and connect the output of the previous 3 "function" nodes to the input of this one. You should get something as shown below:
Double click on that node and add the following, only replacing <UBIDOTS-TOKEN> by your Ubidots token:
msg.headers = {
'Content-Type' : 'application/json',
'X-Auth-Token' : 'UBIDOTS-TOKEN'
}
return msg;
Note: Newer versions of node-red natively implement a configuration for setting the headers, thus this steps is not required.
3. Send data to Ubidots
Drag and drop a "http request" node and a "debug" node and connec them together to the previous nodes as shown below:
Double click on the "http request" node and fill the field as:
Method: This is the method of the HTTP request. POST is required to send data.
URL: https://industrial.api.ubidots.com/api/v1.6/devices/<your-device-label>. This is the endpoint used to send data to Ubidots. Here you'll have to replace your device label.
Click the "Done" button to save the changes and then click the "Deploy" button to deploy the changes to the device. After doing so, you'll be able to see a new device on Ubidots featuring the variables mentioned above: