brainstorm/esp-modbus-power-meter
(unofficial) Modbus Espressif component for power meters
โก ModBus (unofficial) Espressif support for power meters
This repo details how to use a Saola-1 ESP32S2 board coupled with a RS485 transceiver from
LinkSprite and connect it to Espressif's IoT cloud platform: RainMaker.
Also, there's support for PVoutput.org graphs since my meter
is coupled to three 500W solar panels (one per phase) equipped with APC
microinverters.
There are several branches, all of them with custom setups that work
with PlatformIO IDE with varying degrees of success:
๐ Branches
- master: FreeModbus from ESP-IDF framework with PVoutput.org and RainMaker support.
- emodbus: eModbus with Arduino, first time I got the Modbus holding registers listed thanks to this eModbus discussion thread.
- arduino-rainmaker: Same as emodbus, but trying to mix in RainMaker,
ultimately switching to ESP-IDF (onmaster) after realising that
Arduino support for RainMaker has some rough edges at the time of
writing this.
๐ค Hardware setup
The hardware setup is very similar to this eModbus hardware example thread with a couple of notable differences:
- The use of a ttl level converter between the
MAX481CSARS485 (5V level) transceiver and the Espressif board (which is 3.3V level). - RE/DE circuitry is handled by the LinkSprite shield instead of via
software withREDEPIN. This is because the shield has a
transistor-based automatic switching between transmitting and
receiving, see the schematic in
docs/linksprite_shield_datasheet.pdf
Here's a picture at some of the hardware specs from the power meter:
๐ฅ๏ธ Code structure
Don't forget to clone it like this, otherwise the RainMaker submodules
will not be pulled and the code will not compile:
git clone --recursive
https://github.com/brainstorm/esp-modbus-power-meter/
The protocol used on top of RS485 is Modbus-RTU with 8N1 parity and with this code is acting as a master and the power meter as master.
app_modbus.c: ModBus RTU codeinclude/cid_tables.h: Definitions of the Modbus registers for the
several power meters supportedapp_rmaker.c: RainMaker setup for parameters and updates.app_time.c: PVoutput.org time and date formatting for watts submission.app_rgbled.c: Nothing to see here, move along XDplatformio.ini: Embeeded certs for RainMaker and other flashing/building goodies.
๐๏ธ Building and provisioning
As usual with esp-idf, you should consult the official ESP-IDF docs as the following is tailored to my personal dev environment and paths:
conda activate esp
. $HOME/esp/esp-idf/export.sh
idf.py menuconfig build flash monitorMake sure that menuconfig has those enabled as sometimes the build system forgets:
- Custom partition table read from
partitions.csv - esp-insights enabled.
To re-provision RainMaker you'd need to kill the device's memory entirely and start over on your phone with:
idf.py erase-flashSo this is just a self-reminder, YMMV wildly ;)
โ How can you contribute?
- Review your own power meter's manual and find the register(s) listing.
- Submit a pullrequest with a CID table for your meter (see include/cid_tables.h)
- Small and sweet code reviews and pull requests.
๐ Random notes
There are a few vague, vestigial references online about this power meter:
- There's a youtube video showing the default setup
password and some basic usage/configuration as well as a full [teardown video][yigedianqi_teardown] - A possible company spinoff, from yiGedianqi to yiHedianqi?
- Several Amazon customers rating this meter and pointing out that it only comes with a chinese manual (true story).
- A similar project, including Grafana, RPi and other power meters supported.


