An IoT-based system uses ESP32, ESP8266, PZEM 004T, and other sensors, software, and smart devices to collect data on energy consumption, production, and distribution in a smart microgrid and process this data to provide a perception of energy use and optimize energy management.