Skip to content

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 ​

  1. Initialize serial logging, LittleFS and configuration storage.
  2. Inspect chip, Flash and PSRAM, then run the feature memory budget.
  3. Load /config/features.json and apply dependencies and user switches.
  4. Start WiFi/AP, optional network adapters and the Web/API routes.
  5. Start network-dependent MQTT, Modbus and other active features after networking is ready.
  6. 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 ​

ModuleResponsibilityMain Source
FastBeeFrameworkStartup orchestration and service lifecyclesrc/core/FastBeeFramework.cpp
RuntimeFeatureManagerFeature registration, features.json, dependencies and statesrc/core/RuntimeFeatureManager.cpp
FeatureBudgetReject heavy features when internal DRAM is too lowinclude/core/FeatureBudget.h
NetworkManagerWiFi AP/STA, adapter switching, reconnect and AP fallbacksrc/network/NetworkManager.cpp
WebConfigManagerRoutes, authentication, static assets and request limitingsrc/network/WebConfigManager.cpp
ProtocolManagerMQTT/Modbus lifecycle and data routingsrc/protocols/ProtocolManager.cpp
PeripheralManagerPin validation, drivers and peripheral read/writesrc/core/PeripheralManager.cpp
PeriphExecManagerTriggers, conditions, actions and execution resultssrc/core/PeriphExecManager.cpp
HealthMonitorHeap, task stack, networking and watchdog monitoringsrc/systems/HealthMonitor.cpp

Configuration Flow ​

text
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 conditions

Configuration 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:

text
compiled AND userEnabled AND budgetPassed AND NOT runtimeDisabled

Disabling 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 INetworkAdapter and require compile support plus external hardware.
  • ProtocolManager owns 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 ​

  • WebConfigManager registers /api/*; handlers live under src/network/handlers/.
  • Except for health and login endpoints, management APIs require an authenticated session.
  • Static assets come from LittleFS. Under memory pressure, WebMemoryGuard can return 503 with Retry-After for heavy requests.
  • SSE /api/events pushes sensor, Modbus and MQTT state; clients must reconnect after interruption.

Extension Rules ​

When adding a feature:

  1. Define its compile flag and register its runtime key and dependencies.
  2. Add a resource budget, clear errors and a low-memory degradation path.
  3. Keep names consistent across Web/API, config transfer and capability responses.
  4. Update device documentation, build matrix and test matrix.
  5. Run native, device API and browser smoke tests.

See Project Structure, Build Configuration and API Reference.

FastBee | fastbee.cn