How tdenkov123/bolt works
Purpose and entry points
BOLT is an IEC 61499-inspired Python runtime: applications compose Function Blocks (FBs), connect event/data ports, and execute event chains. The host example starts at main.py; runtime primitives live under core/. An ESP32 MicroPython peer receives engine commands and publishes acknowledgements via MQTT from BOLT_mp/BOLT_mp/main.py.
Host runtime model
core/BaseDevice.py represents a device-level container for resources. core/BaseResource.py owns FB instances and their execution context; core/BaseFunctionBlock.py defines FB lifecycle, interfaces, state, and event handling. core/FunctionBlockLoader.py resolves/load built-in FB implementations, allowing the application to construct a resource graph from FB types.
Event and data graph execution
FB interfaces and execution states are modeled in core/FBInterface.py and core/FBStates.py. Connections are explicit graph edges: core/connections/EventConnection.py propagates control/events, while core/connections/DataConnection.py transfers values between FB variables. Event propagation is the main control flow; the README notes one thread is used per event chain on CPython.
Function-block library
Built-in blocks in core/FBs/ implement application behavior. core/FBs/START.py initiates a graph at resource startup, core/FBs/E_CYCLE.py generates periodic events, and core/FBs/MQTT_PUBLISH.py / core/FBs/MQTT_SUBSCRIBE.py bridge the graph to MQTT. The example’s cyclic path publishes ENGINE_DEGREES every 500 ms and receives ENGINE_STATUS acknowledgements.
Data typing boundary
IEC-style values and casting are centralized in core/datatypes/, including core/datatypes/IEC_INT.py, core/datatypes/IEC_STRING.py, and core/datatypes/Cast.py. This separates typed FB input/output data semantics from Python transport and scheduling concerns.
MQTT and infrastructure boundary
The host MQTT adapter is core/MQTTClient.py; host broker endpoint settings are in config.py. MQTT is the process/network boundary between the Python FB engine and embedded devices. Local infrastructure is Docker Compose-backed Mosquitto via docker-compose.yml and docker/mosquitto.conf; optional Avahi service files under docker/ advertise broker discovery as mqtt.local.
ESP32 MicroPython peer
ESP firmware bootstraps networking in BOLT_mp/BOLT_mp/boot.py, then runs its MQTT command/acknowledgement loop in BOLT_mp/BOLT_mp/main.py using BOLT_mp/BOLT_mp/mqtt_client.py. BOLT_mp/BOLT_mp/bolt_net.py initializes Wi-Fi and resolves the broker. BOLT_mp/BOLT_mp/mdns_discovery.py provides a fast configured-IP probe plus optional mDNS lookup/fallback, controlled by BOLT_mp/BOLT_mp/config.py.
Main entry points: MQTT_PUBLISH.py MQTT publish / subscribe · BaseResource.py Resource executor · BaseFunctionBlock.py Function block base · EventConnection.py Event connections
Components 18
Host runtime
Python IEC 61499-style execution engine.
- Host example
main.py - Device container
core/BaseDevice.py - Resource executor · Owns FB instances and event-chain execution.
core/BaseResource.py - Function block base · Defines lifecycle, interfaces, state, and event handling.
core/BaseFunctionBlock.py - FB loader
core/FunctionBlockLoader.py - Interfaces and states
core/FBInterface.py - Event connections · Propagates events through FB chains.
core/connections/EventConnection.py - Data connections · Transfers values between FB variables.
core/connections/DataConnection.py - IEC data types · Centralizes IEC values and casting.
core/datatypes/Cast.py - Host MQTT adapter
core/MQTTClient.py
Function-block library
- START · Initiates the graph at resource startup.
core/FBs/START.py - E_CYCLE · Generates periodic events.
core/FBs/E_CYCLE.py - MQTT publish / subscribe · Bridges FB events and data to MQTT topics.
core/FBs/MQTT_PUBLISH.py
MQTT infrastructure
- Mosquitto broker · Process and network boundary for engine and device.
docker-compose.yml
ESP32 peer
MicroPython command and acknowledgement runtime.
- ESP boot · Starts networking before the command loop.
BOLT_mp/BOLT_mp/boot.py - ESP command loop · Receives engine commands and publishes acknowledgements.
BOLT_mp/BOLT_mp/main.py - ESP MQTT client
BOLT_mp/BOLT_mp/mqtt_client.py - Wi-Fi and broker discovery · Initializes Wi-Fi and resolves configured or mDNS broker.
BOLT_mp/BOLT_mp/bolt_net.py
Connections 18
- Host example → Device container: builds
- Device container → Resource executor: contains
- Resource executor → FB loader: loads FB types
- FB loader → Function block base: instantiates
- Function block base → Interfaces and states: uses
- Function block base → IEC data types: typed I/O
- Resource executor → Event connections: executes
- Event connections → Data connections: drives data flow
- START → E_CYCLE: startup event
- E_CYCLE → MQTT publish / subscribe: periodic event · Publishes ENGINE_DEGREES every 500 ms in the example.
- MQTT publish / subscribe → Host MQTT adapter: uses
- Host MQTT adapter → Mosquitto broker: publish / subscribe
- ESP boot → Wi-Fi and broker discovery: initializes
- Wi-Fi and broker discovery → ESP command loop: broker ready
- ESP command loop → ESP MQTT client: uses
- ESP MQTT client → Mosquitto broker: commands / acknowledgements · Receives ENGINE_DEGREES commands and publishes ENGINE_STATUS.
- MQTT publish / subscribe → Event connections: FB event endpoints
- MQTT publish / subscribe → Data connections: FB data endpoints