From d49f580ab60931ed824f1cbd9678b08af770a7d9 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 28 Jul 2026 03:57:10 +0800 Subject: [PATCH] Enhance DaliCloudBridge: add gateway settings handler and support for gateway configuration messages Signed-off-by: Tony --- include/gateway_cloud.hpp | 6 ++++++ src/gateway_cloud.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/gateway_cloud.hpp b/include/gateway_cloud.hpp index fada120..e3a96e1 100644 --- a/include/gateway_cloud.hpp +++ b/include/gateway_cloud.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #ifdef ESP_PLATFORM @@ -36,6 +37,9 @@ struct GatewayCloudConfig { class DaliCloudBridge { public: using CemiDownlinkHandler = std::function; + /// Handles gateway-level configuration messages received on the normal MQTT + /// downlink topic and returns the JSON acknowledgement for the up topic. + using GatewaySettingsHandler = std::function; explicit DaliCloudBridge(DaliComm& comm); @@ -46,6 +50,7 @@ class DaliCloudBridge { DaliBridgeEngine& bridge() { return bridge_; } const DaliBridgeEngine& bridge() const { return bridge_; } void setCemiDownlinkHandler(CemiDownlinkHandler handler); + void setGatewaySettingsHandler(GatewaySettingsHandler handler); bool publishStatus(const std::string& status); bool publishRegister(const std::string& payloadJson); @@ -81,6 +86,7 @@ class DaliCloudBridge { DaliBridgeEngine bridge_; GatewayCloudConfig config_; CemiDownlinkHandler cemi_downlink_handler_; + GatewaySettingsHandler gateway_settings_handler_; std::atomic connected_{false}; std::atomic lte_uart_started_{false}; std::atomic lte_uart_stop_requested_{false}; diff --git a/src/gateway_cloud.cpp b/src/gateway_cloud.cpp index 0fd2ac6..19cea25 100644 --- a/src/gateway_cloud.cpp +++ b/src/gateway_cloud.cpp @@ -339,6 +339,10 @@ void DaliCloudBridge::setCemiDownlinkHandler(CemiDownlinkHandler handler) { cemi_downlink_handler_ = std::move(handler); } +void DaliCloudBridge::setGatewaySettingsHandler(GatewaySettingsHandler handler) { + gateway_settings_handler_ = std::move(handler); +} + bool DaliCloudBridge::publishStatus(const std::string& status) { std::string payload = "{\"type\":\"status\",\"status\":\"" + status + "\"}"; return publishJSON(topicStatus(), payload); @@ -571,6 +575,16 @@ bool DaliCloudBridge::handleDownlink(const std::string& payload) { return false; } + const std::string type = toString(cJSON_GetObjectItemCaseSensitive(root, "type")); + if (type == "gatewaySettingsGet" || type == "gatewaySettingsSet") { + const std::string response = gateway_settings_handler_ + ? gateway_settings_handler_(payload) + : "{\"type\":\"gatewaySettings\",\"status\":\"error\"," + "\"error\":\"gateway settings are unavailable\"}"; + cJSON_Delete(root); + return !response.empty() && publishJSON(topicUp(), response); + } + DaliBridgeRequest request; const cJSON* seqItem = cJSON_GetObjectItemCaseSensitive(root, "seq"); if (seqItem == nullptr) seqItem = cJSON_GetObjectItemCaseSensitive(root, "sequence");