Lite Emulator of Grid Operations
Firmware
The operating code used in the LEGOS platform for programming the building blocks of the Distribution layer and the entities of the Application layer was developed using the official Espressif IoT Development Framework ESP-IDF (version 4.1 release build).
Architecture
flowchart TB
subgraph main[main]
start([Start]) --> init_entity[[Init Entity]]
init_entity --> init_network[[Init Wi-Fi]]
init_network --> init_mqtt[[Init MQTT]]
init_mqtt --> loop((yield))
end
subgraph entity[entity];
init_entity --> init_modules[[Init peripherals]];
init_modules --> init_tasks((Main tasks));
end
subgraph network[wifi]
init_network --> init_sta[[Init mode STA]]
init_sta --> init_server[Start web server]
init_server --> init_netfsm((Event FSM))
end
subgraph mqtt[mqtt]
init_mqtt --> init_client[[Init MQTT client]]
init_client --> sub_topic[Subscribe topics]
sub_topic --> init_mqttfsm((Event FSM))
end
init_mqttfsm o-->|MQTT callbacks| init_tasks
init_netfsm o-->|HTTP callbacks| init_tasks
The firmware architecture can be divided in 3 sub-blocks called in the main in the following order:
-
entity: application specific code
- init entity peripherals
- handle period tasks
- provide mqtt callbacks
- provide http callbacks
-
wifi: application independent code
- init wifi STA mode
- provide network stack
- invoke http callbacks
-
mqtt: application independent code
- init MQTT
- provide protocol stack
- invoke mqtt callbacks
Building
Select the desired compilation target from the LEGOS menu.
cd <project-dir>
idf.py menuconfig
Build and flash the code for the target entity. Replace port with the programmer port (eg. COM3)
idf.py -p <port> -b 921600 build flash
Open the debug terminal if required.
idf.py monitor
Repository structure
All the entities in LEGOS share a common behavior as IoT devices, which is customized for the specific profile using libraries arranged in separate component folders:
-
components
-
common: library for implementing shared entity features
- legos_common: shared settings and functions
- legos_id:
- legos_libs: custom build profile selection
- legos_mqtt: mqtt thread finite state machine
- legos_netw: wifi thread finite state machine
- branch: library for monitoring, controlling and visualizing the branch power flow
- datacenter: library for monitoring the power consumption, switching to ups upon fault and controlling the server activity
- ecstation: library for monitoring the power consumption and emulate electric-car charging profiles based on RFID data stored in the vehicle
- factory: library for monitoring the power consumption and controlling the factory electrical load due to manufacturing activities
- hospital: library for monitoring the power consumption, switching to ups upon fault and controlling the hospital alert status
- house: library for monitoring the power consumption, combining production from PVs and controlling household appliances
- powerplant: library for monitoring the power generation from traditional fossil-fuel
- skyscraper: library for monitoring the power consumption, controlling a HVAC system and implementing a SCADA/Cyber-Security center
- solarfarm: library for monitoring the power generation from renewable energy using solar cells, optimized via 1-axis solar tracker
- stadium: library for monitoring the power consumption due to occasional football matches
- substation: library for low-level automation of an electrical grid, provides bus trip/close operations upon fault
- supermarket: library for monitoring the power consumption, combining electrical and thermal energy generation from gas
- windfarm: library for monitoring the power generation from renewable energy using wind
- ms4: library for interfacing Ambimate Sensor Modules MS4 by TE Connectivity
- owb: library for interfacing devices over 1-Wire technology by Maxim Integrated
- ina233: library for interfacing INA233 power monitors by Texas Instruments
- mfrc522: library for interfacing RFID shields based on MFRC522 by NXP Semiconductors
- pca9536: library for interfacing PCA9536 I/O expanders by Texas Instruments
- tmp100: library for interfacing TMP10x temperature sensors by Texas Instruments
-
common: library for implementing shared entity features
-
main
- main.c: entry point function for code execution
Copyright
2021, Institute for Automation of Complex Power Systems, EONERC
License
This work is licensed under a MIT License.
Funding
This work was supported by FIWARE for Smart Energy Platform (FISMEP), a German project funded by the Federal Ministry for Economic Affairs and Energy (BMWi) and the ERA-Net Smart Energy Systems Programme under Grant 0350018A.
Contact
Institute for Automation of Complex Power Systems (ACS)
E.ON Energy Research Center (EONERC)
RWTH University Aachen, Germany