Project Background
I decided to expand the energy monitoring network in my house and started looking for an inexpensive solution to measure electricity consumption in both my workshop and office. The requirements were straightforward: Wi-Fi connectivity, a simple web-based configuration interface, and seamless integration with Home Assistant. Since MQTT is the standard communication method for Home Assistant and many other automation platforms, it was the obvious choice for data transmission.
After evaluating different options, I selected DDS5188 energy meters. These meters provide a pulse output with a resolution of 0.5 Wh per pulse. Since I wanted to monitor three separate circuits, three meters were required.
To collect and process the pulse data, I chose the ESP32-C3. It is compact, inexpensive, and provides all the necessary features, including Wi-Fi connectivity, sufficient processing power, and low power consumption. As the device needed to be powered directly from the mains supply without an external power adapter, I selected the HLK-PM01 AC-DC converter. Its small size allowed the entire system to fit neatly inside a DIN rail enclosure while providing a stable 5 V supply.
Hardware Design
The hardware design is intentionally simple. All three energy meters share a common ground, and their pulse outputs are connected directly to ESP32 GPIO inputs with 10 kΩ pull-up resistors to 3.3 V.
Four status LEDs provide visual feedback for system operation, indicating pulse activity and Wi-Fi connection status. Each LED is connected to an ESP32 output through a 1 kΩ current-limiting resistor.
The HLK-PM01 power supply module is connected directly to the ESP32’s 5 V input. The module provides adequate voltage regulation and filtering for reliable operation without additional power conditioning circuitry. For safety, the mains input is protected by a fuse located on the AC side of the circuit.
Firmware Architecture
The firmware is organized into independent modules responsible for configuration storage, network management, pulse acquisition, MQTT communication, web-based configuration, and remote firmware updates. This modular architecture simplifies maintenance, testing, and future feature expansion.
I decided to expand the energy meter network at my house. I did search for cheap solution to measure consumption in my workshop and office. I wanted to have WiFi connectivity to network and some sort of configuration page. The values should be easily accessible to homeAssistant, so mqtt was obvious choice
I found some DDS5188 to use. The modules have pulse output for 0.5Wh per pulse. To measure three peaces of the meters are needed. To achieve the functionality I decided to use ESP32-C3 as it’s cheap and small and has all needed capabilities. The unit needs to be connected to mains without external transformer. The voltage converter HLK-PM01 with 5V output was small enough to do the job and fit to tje DIN rail box.
The hardware is simple, The meters are sharing the same ground and the pulse outputs are connected to ESP32 with 10K 3V3 pull-up resistors. To see that the pulses are coming and WiFi is connected four led’s are used, connected to ESP32 outputs with 1K resistor. The HLK module is directly connected to ESP32 5V input, the module has sufficient regulation and smoothing to be used directly. In the mains side there is fuse to protect the circuit.
The firmware is organized into independent modules responsible for configuration storage, network management, pulse acquisition, MQTT communication, web-based configuration, and remote firmware updates. This modular architecture simplifies maintenance, testing, and future feature expansion.
Short explanation of functions.
main loop
setup()
System initialization sequence
Performs device startup, loads stored configuration, initializes pulse monitoring, establishes network connectivity, starts the web server, and activates MQTT and OTA services when operating in connected mode.
loop()
Main application runtime loop
Continuously executes background services including network maintenance, DNS handling, pulse processing, MQTT communication, web server tasks, and OTA update monitoring.
storage.h
Persistent configuration storage
Manages saving and loading device settings from ESP32 NVS memory, including Wi-Fi, MQTT, meter configuration, and hostname settings.
network.h
Wi-Fi connection management
Handles network discovery, connection establishment, and fallback to Access Point (AP) provisioning mode when no valid Wi-Fi configuration is available.
webserver.h
Web-based configuration interface
Provides a browser-based management portal for device setup, monitoring, and configuration without requiring additional software.
pulses.h
Pulse acquisition and energy calculation
Monitors incoming meter pulses, maintains pulse counters, and converts pulse data into energy consumption values using the configured Wh-per-pulse factor.
mqtt.h
MQTT communication service
Publishes meter readings and device status information to an MQTT broker for integration with platforms such as Home Assistant, Node-RED, and SCADA systems.
ota.h
Over-The-Air firmware updates
Enables remote firmware upgrades over the network, eliminating the need for physical USB access after deployment.