Add cloud bridge and provisioning support for ESP32 gateway

- Introduced DaliCloudBridge for MQTT communication with backend.
- Added GatewayProvisioningStore for persisting cloud connection settings using NVS.
- Updated CMakeLists.txt to include new source files.
- Enhanced README.md with usage examples and configuration details.
This commit is contained in:
Tony
2026-03-31 08:44:30 +08:00
parent 7e8ac7f566
commit a8a82f9627
8 changed files with 531 additions and 0 deletions
+71
View File
@@ -47,3 +47,74 @@ std::vector<int> rgb = dali.dt8.getColourRGB(5);
- Optional query support: provide a `transact` callback that returns the gateway reply; otherwise, query methods return `std::nullopt`.
- `Dali` facade in `include/dali.hpp` mirrors `lib/dali/dali.dart` and wires `base`, `decode`, `dt1`, `dt8`, and `addr` together.
- The `t`, `d`, and `g` parameters in Dart are not required here; timing/gateway selection is driven by your callbacks.
## Cloud Bridge (ESP32 Gateway)
The component now includes `DaliCloudBridge` in `include/gateway_cloud.hpp` to connect ESP32 gateways to the backend MQTT broker.
### Topics
- Downlink: `devices/<deviceID>/down`
- Uplink: `devices/<deviceID>/up`
- Status: `devices/<deviceID>/status`
- Register: `devices/<deviceID>/register`
### Downlink JSON Envelope
```json
{
"type": "dali_cmd",
"seq": "123",
"op": "send|send_ext|query",
"addr": 5,
"cmd": 160
}
```
### Uplink JSON Envelope
```json
{
"type": "dali_resp",
"seq": "123",
"op": "query",
"ok": true,
"data": 255
}
```
### Usage
```cpp
GatewayCloudConfig cfg;
cfg.brokerURI = "mqtt://192.168.1.100:1883";
cfg.deviceID = "A1B2C3D4E5F6";
cfg.username = "device";
cfg.password = "A1B2C3D4E5F6";
DaliCloudBridge bridge(comm);
if (bridge.start(cfg)) {
bridge.publishStatus("online");
}
```
### Provisioning via NVS
Use `GatewayProvisioningStore` to persist cloud connection settings:
```cpp
GatewayProvisioningStore store;
GatewayCloudConfig cfg;
cfg.brokerURI = "mqtt://192.168.1.100:1883";
cfg.deviceID = "A1B2C3D4E5F6";
cfg.username = "device";
cfg.password = "A1B2C3D4E5F6";
store.save(cfg);
GatewayCloudConfig loaded;
if (store.load(&loaded) == ESP_OK) {
DaliCloudBridge bridge(comm);
bridge.start(loaded);
}
```