Skip to content

brainstorm/esp-modbus-power-meter

Repository files navigation

⚡ 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.

power_meter_front supported_power_meters

There are several branches, all of them with custom setups that work with PlatformIO IDE with varying degrees of success:

🎋 Branches

🤖 Hardware setup

The hardware setup is very similar to this eModbus hardware example thread with a couple of notable differences:

  1. The use of a ttl level converter between the MAX481CSA RS485 (5V level) transceiver and the Espressif board (which is 3.3V level).
  2. RE/DE circuitry is handled by the LinkSprite shield instead of via software with REDEPIN. 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:

power_meter_specs

🖥️ 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/

When and if Espressif merges my RainMaker power metering PR, I'll repoint those submodules away from my fork.

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 code
  • include/cid_tables.h: Definitions of the Modbus registers for the several power meters supported
  • app_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 XD
  • platformio.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 monitor

Make sure that menuconfig has those enabled as sometimes the build system forgets:

  1. Custom partition table read from partitions.csv
  2. 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-flash

So this is just a self-reminder, YMMV wildly ;)

✋ How can you contribute?

  1. Review your own power meter's manual and find the register(s) listing.
  2. Submit a pullrequest with a CID table for your meter (see include/cid_tables.h)
  3. Small and sweet code reviews and pull requests.

🌀 Random notes

There are a few vague, vestigial references online about this power meter:

  1. There's a youtube video showing the default setup password and some basic usage/configuration as well as a full [teardown video][yigedianqi_teardown]
  2. A possible company spinoff, from yiGedianqi to yiHedianqi?
  3. Several Amazon customers rating this meter and pointing out that it only comes with a chinese manual (true story).
  4. A similar project, including Grafana, RPi and other power meters supported.