Abstract
This article introduces a cost-effective, IoT-enabled flexible energy management system (EMS) for residential photovoltaic (PV) microgrids with battery storage, implemented on an ESP32 microcontroller. The proposed system achieves indirect control over commercial household inverters by altering wattmeter readings and utilizing Modbus communication, thereby avoiding expensive hardware modifications. A significant contribution of this work is enabling the injection of energy from the Battery Energy Storage System (BESS) into the grid, a capability often restricted by commercial inverters. Real-world experimentation validated robust performance of the proposed system, demonstrating its ability to dynamically manage energy flows, achieve minimal tracking errors, and optimize energy usage in response to both flexibility market signals and electricity prices. This approach provides a practical and accessible solution for prosumers to actively participate in energy trading and flexibility markets using widely available technology.