In this opportunity we will integrate our active power meter or electric consumption,Pzem-004 – Peacefair with the IoT Node-RED integration platform used in previous tutorials, we will use an ESP8266 module configured as Modbus TCP / IP slave, later we will visualize the measurements in Node- RED Dashboard to visualize the 4 available variables such as active power, accumulated electrical consumption, voltage and current.
Previous Tutorials Recommended
Installation Platform Node-Red
In the following tutorial we will indicate how to install Node-RED for linux and in case of other OS we recommend Virtualbox.
Updating ESP8266 Industrial Modbus TCP IP V2.0
A long time ago I made some tests of ESP8266 as a Modbus TCP/IP slave, the following tutorial can be taken as background information of the current tests.
Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano
If you want to know more about Pzem-004 Peacefair , I recommend the following tutorial:
Features, Arduino connections and ESP8266.
Meter PZEM-004T with Arduino ESP32 ESP8266 Python & Raspberry Pi
Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano
Measurement Electrical consumption with Ubidots Industrial & ESP32 + PZEM-004T
Tests Performed
We will measure the electrical consumption of a resistance to heat water, consume approximately 920 Watts and we will visualize the measurements in a dashboard created in Node-RED Dashboard and the communication implemented Modbus TCP / IP.
Materials and where to buy them very cheap !!
- Meter PZEM 004 with display
- Meter PZEM 004T & Three phase meters
- Immersion heater / Resistance Water heater
- ESP8266 NodeMCU
Other Recommended Equipment
- Transformer core splitter
- Monophasic Electric Consumption Meters – Per Pulse
- Voltage transformers for insulation
- MPPT Controller Regulator for solar panel
- Solar Panels 10W 18v
- Matrix Led x4 Max7219
- Arduino Nano Clone
Simple Test Meter PZEM-004 & ESP8266 Platform IoT Node-RED Dashboard Modbus TCP/IP
Connections
Note: The PZEM-004 meter requires an adaptation to 3.3v communication, more information references below.
Arduino IDE Code
The routine created in Arduino IDE, ESP8266 performs the reading of the meter PZEM-004 through the serial port, from previous tests with Modbus TCP / IP a routine was created cut for sending and receiving of Holding Registers.
4 variables have been defined in 4 Holding Registers:
- empty = Holding Register[0].
- Instantaneous voltage = Holding Register[1].
- Instant current = Holding Register[2].
- Instant power = Holding Register[3].
- Accumulated power = Holding Register[4].
Quick solution to shipment of Float in Int
The values of the meter are floating type, the Holding Registers are 16-bit Integers, in this case by practicality simply multiplying by 10 we perform the sending of the value, in next tests we will carry out the shipment in 2 integers of 16 bits.
Note: Download and / or github links below.
Node-RED
The nodes used in this test have been downloaded and installed, simply search the Node-RED “Manage palette”.
- Modbus TCP/IP, Node-RED nodes will be Modbus TCP/IP master
- Node-RED Dashboard, visualization package.
In this case, an Array of 5 positions [0,1,2,3,4] is received, the first position in 0 and the rest contains the values of voltage, Current, Power, Accumulated Consumption.
Using some Script nodes the values are separated and is done doing the inverse of Arduino IDE is divided in 10 the values received to convert them from Int to Float in the required cases, technically all this is done for the correct visualization.
Note: Download and / or github links below.
Node-RED Dashboard
Real-time viewing package.
- View from PC
- View from Android
The resistance consumes approximately 922 Watts.
Conclusions & Considerations
Well in this opportunity I tried an alternative to the well-known MQTT protocol, this Modbus TCP / IP version worked very well, clearly keep in mind that this application only works at our local network level.
These are still initial tests, since I have not connected multiple slaves, I suppose it will work well since Node-RED is the master, it would depend more on the machine on which Node-RED runs, be it a PC or another platform like Raspberry Pi or Beaglebone Black etc.
In this implementation, the Serial Port of the ESP8266 should not be used since it is used to communicate with the PZEM-004 Electric Consumption Meter.
In pending pending improvements:
- Updating ESP8266 OTA
- WifiManager
- Web server
Github/Downloads
- Library Communication PZEM004T
- Library SoftwareSerial for ESP8266
- Example Importation Node-RED
- Arduino IDE Code Example PZEM-ESP8266-ModbusTCP_B
References
- Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano
- Installation Node-RED Platform
- Update ESP8266 Industrial Modbus TCP IP V2.0
- Modbus TCP/IP, Node-RED nodes will be Modbus TCP/IP master
- Node-RED Dashboard, visualization package.