Architecture
FastBee-Arduino uses a configuration-driven architecture with runtime capability gates. Web/API requests update configuration; core modules coordinate networking, protocols, peripherals and rules; health monitoring degrades optional work when resources are tight.
Module Relationships
Startup Order
- Initialize serial logging, LittleFS and configuration storage.
- Inspect chip, Flash and PSRAM, then run the feature memory budget.
- Load
/config/features.jsonand apply dependencies and user switches. - Start WiFi/AP, optional network adapters and the Web/API routes.
- Start network-dependent MQTT, Modbus and other active features after networking is ready.
- Initialize peripheral drivers, rule scheduling and the main loop.
Network-dependent modules use delayed initialization so their allocation peaks do not collide with WiFi startup, sensor initialization or script-engine startup.
Core Modules
| Module | Responsibility | Main Source |
|---|---|---|
FastBeeFramework | Startup orchestration and service lifecycle | src/core/FastBeeFramework.cpp |
RuntimeFeatureManager | Feature registration, features.json, dependencies and state | src/core/RuntimeFeatureManager.cpp |
FeatureBudget | Reject heavy features when internal DRAM is too low | include/core/FeatureBudget.h |
NetworkManager | WiFi AP/STA, adapter switching, reconnect and AP fallback | src/network/NetworkManager.cpp |
WebConfigManager | Routes, authentication, static assets and request limiting | src/network/WebConfigManager.cpp |
ProtocolManager | MQTT/Modbus lifecycle and data routing | src/protocols/ProtocolManager.cpp |
PeripheralManager | Pin validation, drivers and peripheral read/write | src/core/PeripheralManager.cpp |
PeriphExecManager | Triggers, conditions, actions and execution results | src/core/PeriphExecManager.cpp |
HealthMonitor | Heap, task stack, networking and watchdog monitoring | src/systems/HealthMonitor.cpp |
Configuration Flow
Web form/API
-> validation
RuntimeFeatureManager / ConfigStorage
-> atomic write
LittleFS /config/*.json
-> restart or module reload
Runtime objects and drivers
-> MQTT reports, SSE events and rule conditionsConfiguration writes use temporary files, parse validation and replacement so a failed write leaves the previous file intact. Network, device, protocol, peripheral, rule, feature and authentication settings remain separate for backup and migration.
Feature Gates
Drivers call RuntimeFeatureManager::shouldEnable(key). A feature is usable only when:
compiled AND userEnabled AND budgetPassed AND NOT runtimeDisabledDisabling a parent also disables its dependent features, such as lcd to lcdGb2312 or ruleScript to commandScript. Web menus and API capability responses must use this same registry, not a separate hard-coded matrix.
Network and Protocols
- WiFi is the default adapter. Failed STA connections can fall back to AP, and background probing can restore STA later.
- W5500 and EC801E-CN implement
INetworkAdapterand require compile support plus external hardware. ProtocolManagerowns MQTT publish/subscribe. MQTTS uses the same stack with a runtime feature switch and higher transient DRAM demand.- Modbus RTU currently acts as a master. Poll results enter the peripheral cache for local rules and MQTT reporting.
Web and Security
WebConfigManagerregisters/api/*; handlers live undersrc/network/handlers/.- Except for health and login endpoints, management APIs require an authenticated session.
- Static assets come from LittleFS. Under memory pressure,
WebMemoryGuardcan return503withRetry-Afterfor heavy requests. - SSE
/api/eventspushes sensor, Modbus and MQTT state; clients must reconnect after interruption.
Extension Rules
When adding a feature:
- Define its compile flag and register its runtime key and dependencies.
- Add a resource budget, clear errors and a low-memory degradation path.
- Keep names consistent across Web/API, config transfer and capability responses.
- Update device documentation, build matrix and test matrix.
- Run native, device API and browser smoke tests.
See Project Structure, Build Configuration and API Reference.

