{"id":17880371,"url":"https://github.com/brainstorm/esp-modbus-power-meter","last_synced_at":"2025-03-22T07:31:33.975Z","repository":{"id":61482129,"uuid":"470182924","full_name":"brainstorm/esp-modbus-power-meter","owner":"brainstorm","description":"(unofficial) Modbus Espressif component for power meters","archived":false,"fork":false,"pushed_at":"2023-03-04T14:10:38.000Z","size":17887,"stargazers_count":7,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T09:21:34.030Z","etag":null,"topics":["esp-idf","esp-idf-component","esp32","powermeter","powermeter-reader"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brainstorm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-15T13:55:38.000Z","updated_at":"2024-10-15T16:00:15.000Z","dependencies_parsed_at":"2024-10-28T12:47:15.942Z","dependency_job_id":null,"html_url":"https://github.com/brainstorm/esp-modbus-power-meter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainstorm%2Fesp-modbus-power-meter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainstorm%2Fesp-modbus-power-meter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainstorm%2Fesp-modbus-power-meter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainstorm%2Fesp-modbus-power-meter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainstorm","download_url":"https://codeload.github.com/brainstorm/esp-modbus-power-meter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244925150,"owners_count":20532873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp-idf","esp-idf-component","esp32","powermeter","powermeter-reader"],"created_at":"2024-10-28T12:14:18.738Z","updated_at":"2025-03-22T07:31:28.948Z","avatar_url":"https://github.com/brainstorm.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚡ ModBus (unofficial) Espressif support for power meters\n\nThis repo details how to use a [Saola-1 ESP32S2 board](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/hw-reference/esp32s2/user-guide-saola-1-v1.2.html) coupled with [a RS485 transceiver from\nLinkSprite][linksprite_rs485_shield] and connect it to Espressif's IoT cloud platform: [RainMaker][rainmaker].\n\nAlso, there's support for [PVoutput.org][pvoutput] graphs since my meter\nis coupled to three 500W solar panels (one per phase) equipped with APC\nmicroinverters.\n\n![power_meter_front](./img/yigedianqi_power_meter_front.png)\n![supported_power_meters](./img/menuconfig_power_meters.png)\n\nThere are several branches, all of them with custom setups that work\nwith PlatformIO IDE with varying degrees of success:\n\n## 🎋 Branches\n\n* master: FreeModbus from ESP-IDF framework with PVoutput.org and RainMaker support.\n* emodbus: [eModbus][emodbus] with Arduino, first time I got the Modbus holding registers listed thanks to [this eModbus discussion thread][emodbus_hardware_discussion].\n* arduino-rainmaker: Same as emodbus, but trying to mix in RainMaker,\nultimately switching to ESP-IDF (on `master`) after realising that\n[Arduino support for RainMaker has some rough edges at the time of\nwriting this](https://esp32.com/viewtopic.php?f=41\u0026t=26552).\n\n## 🤖 Hardware setup\n\nThe hardware setup is very similar to [this eModbus hardware example thread][emodbus_hardware_example] with a couple of notable differences:\n\n1) The use of a [ttl level converter][ttl_level_converter] between the\n[`MAX481CSA` RS485 (5V level)][MAX481] transceiver and the Espressif board (which is 3.3V level).\n2) RE/DE circuitry is handled by the LinkSprite shield instead of [via\nsoftware with `REDEPIN`][redepin]. This is because [the shield has a\ntransistor-based automatic switching between transmitting and\nreceiving][auto_rede], see the schematic in\n[docs/linksprite_shield_datasheet.pdf][linksprite_rs485_shield_schematic]\n\nHere's a picture at some of the hardware specs from the power meter:\n\n![power_meter_specs](./img/yigedianqi_power_meter_specs.png)\n\n## 🖥️ Code structure\n\nDon't forget to clone it like this, otherwise the RainMaker submodules\nwill not be pulled and the code will not compile:\n\n```\ngit clone --recursive\nhttps://github.com/brainstorm/esp-modbus-power-meter/\n```\n\n[When and if Espressif merges my RainMaker power metering PR, I'll\nrepoint those submodules away from my\nfork][espressif_rainmaker_powermeter_pr].\n\nThe 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`.\n\n* `app_modbus.c`: ModBus RTU code\n* **`include/cid_tables.h`: Definitions of the Modbus registers for the\nseveral power meters supported**\n* `app_rmaker.c`: RainMaker setup for parameters and updates.\n* `app_time.c`: PVoutput.org time and date formatting for watts submission.\n* `app_rgbled.c`: Nothing to see here, move along XD\n* `platformio.ini`: Embeeded certs for RainMaker and other flashing/building goodies.\n\n## 🏗️ Building and provisioning\n\nAs usual with `esp-idf`, you should consult the official [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html) docs as the following is tailored to my personal dev environment and paths:\n\n```sh\nconda activate esp\n. $HOME/esp/esp-idf/export.sh\nidf.py menuconfig build flash monitor\n```\n\nMake sure that menuconfig has those enabled as sometimes the build system forgets:\n\n1. Custom partition table read from `partitions.csv`\n2. esp-insights enabled.\n\nTo re-provision RainMaker you'd need to kill the device's memory entirely and start over on your phone with:\n\n```sh\nidf.py erase-flash\n```\n\nSo this is just a self-reminder, YMMV wildly ;)\n\n## ✋ How can you contribute?\n\n1. Review your own power meter's manual and find the register(s) listing.\n1. Submit a pullrequest with a CID table for your meter (**see include/cid_tables.h**)\n1. Small and sweet [code reviews and pull requests](https://github.com/brainstorm/esp-modbus-power-meter/pull/2).\n\n## 🌀 Random notes\n\nThere are a few vague, vestigial references online about this power meter:\n\n1. There's a [youtube][youtube_usage] video showing the default setup\npassword and some basic usage/configuration as well as a full [teardown video][yigedianqi_teardown]\n1. A possible company spinoff, [from yiGedianqi to yiHedianqi][possible_company_spinoff]?\n1. Several [Amazon customers rating this meter][amazon_power_meter_ratings] and pointing out that it only comes with a chinese manual (true story).\n1. [A similar project, including Grafana, RPi and other power meters supported.][guillermo_electrico]\n\n\n[youtube_usage]: https://www.youtube.com/watch?v=22_Wp99j8_U\n[possible_company_spinoff]: http://www.yihedianqi.com/\n[amazon_power_meter_ratings]: https://www.amazon.com/3-Phase-Electric-Voltage-Multifunction-Frequency/dp/B078NRNM37\n[emodbus_hardware_discussion]: https://github.com/eModbus/eModbus/discussions/166\n[rainmaker]: https://rainmaker.espressif.com\n[emodbus]: https://emodbus.github.io\n[emodbus_hardware_example]: https://github.com/eModbus/eModbus/discussions/112#discussion-3650333\n[ttl_level_converter]: https://hackaday.com/2016/12/05/taking-it-to-another-level-making-3-3v-and-5v-logic-communicate-with-level-shifters/\n[redepin]: https://github.com/eModbus/eModbus/blob/2c740aa0960328fb0851ab0ff771236b14ed7838/examples/RTU04example/main.cpp#L21\n[auto_rede]: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/uart.html#circuit-c-auto-switching-transmitter-receiver\n[guillermo_electrico]: https://github.com/GuillermoElectrico/energy-meter-logger\n[pvoutput]: https://pvoutput.org/\n[espressif_rainmaker_powermeter_pr]: https://github.com/espressif/esp-rainmaker/pull/121\n[linksprite_rs485_shield]: https://www.electan.com/rs485-shield-amp-4078-en.html\n[MAX481]: https://github.com/brainstorm/yigedianqi-modbus/blob/master/docs/max481csa.pdf\n[linksprite_rs485_shield_schematic]:  https://github.com/brainstorm/yigedianqi-modbus/blob/master/docs/linksprite_shield_datasheet.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainstorm%2Fesp-modbus-power-meter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainstorm%2Fesp-modbus-power-meter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainstorm%2Fesp-modbus-power-meter/lists"}