$ show softwarecrash/Solar2MQTT-ESP8266
This repository provides embedded firmware for the ESP8266 that bridges Chinese solar inverters (Voltronic/Axpert, PIP, EASUN, Deye, Anenji, Must PV/PH18) to MQTT and a local web interface. It communicates with inverters via RS232 serial (using proprietary ASCII protocols like PI30, PI18) or RS485 Modbus RTU, parses real-time status (grid, battery, PV, loads, faults), and publishes structured JSON to configurable MQTT topics including Home Assistant auto-discovery. The firmware also hosts a full web-based configuration portal with captive portal for WiFi setup, OTA updates, a live JSON endpoint, and LED status indication. Architecturally, it is a monolithic embedded application written in C++ for the PlatformIO build system. Key entry points are `src/main.cpp` (setup/loop), the web server endpoints, MQTT callbacks, and the serial/Modbus polling loop. The code is organized into a serial protocol handler (`PI_Serial`), an abstract Modbus device layer (`modbus_device`) with concrete implementations, a settings manager using EEPROM with versioning and fallback, and a chunked HTML serving mechanism to avoid heap fragmentation on memory-constrained ESP8266 devices. Notable strengths include the modular Modbus device interface that allows adding new inverter models by subclassing and providing register tables, and the auto-detection logic that probes protocols in sequence. The web UI is built with Bootstrap and jQuery loaded from CDN, and the project actively supports Home Assistant integration and multiple hardware configurations (Wemos D1 Mini, ESP-01, WiFi dongle). While the code is well-structured for an embedded project, it relies on dynamic `String` objects and large JSON documents on a limited memory platform, which could cause heap fragmentation over long periods. The license (CC BY-NC-ND 4.0) restricts commercial use and derivative works, limiting community contributions.
The LLM identified 3 files worth highlighting for reuse:
Defines the `ModbusDevice` abstract base class for Modbus RTU inverter communication. It provides a clean interface (`init()`, `update()`, `getValue()`, `getRegisterTable()`) that allows new inverter models (Deye, Anenji, Must PV/PH18) to be added by subclassing and overriding a register map. This pattern is reusable for any Modbus device driver project where different devices share the same transport but have distinct register layouts.
Implements EEPROM-based persistent settings with magic byte and version checks for corruption detection, bounds clamping for all numeric fields, and automatic fallback to a legacy JSON-encoded format. This pattern is directly reusable in any ESP8266/ESP32 project that needs robust, upgradeable configuration storage without an external library.
A Python script invoked during the PlatformIO build process that minifies HTML files and generates C++ header arrays stored in PROGMEM. This enables serving full web pages from flash memory without consuming RAM, critical on devices with as little as 80 KB available. The approach can be adapted for any embedded firmware that ships a web UI.