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:
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "dali_comm.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_event_base.h"
|
||||
#include "mqtt_client.h"
|
||||
#endif
|
||||
|
||||
struct GatewayCloudConfig {
|
||||
std::string brokerURI;
|
||||
std::string deviceID;
|
||||
std::string username = "device";
|
||||
std::string password;
|
||||
std::string topicPrefix = "devices";
|
||||
int qos = 1;
|
||||
};
|
||||
|
||||
// DaliCloudBridge bridges MQTT cloud topics and local DALI frames.
|
||||
class DaliCloudBridge {
|
||||
public:
|
||||
explicit DaliCloudBridge(DaliComm& comm);
|
||||
|
||||
bool start(const GatewayCloudConfig& config);
|
||||
void stop();
|
||||
bool isConnected() const;
|
||||
|
||||
bool publishStatus(const std::string& status);
|
||||
bool publishRegister(const std::string& payloadJson);
|
||||
|
||||
private:
|
||||
#ifdef ESP_PLATFORM
|
||||
static void mqttEventHandler(void* handler_args,
|
||||
esp_event_base_t base,
|
||||
int32_t event_id,
|
||||
void* event_data);
|
||||
void onMqttEvent(esp_mqtt_event_handle_t event);
|
||||
#endif
|
||||
|
||||
bool handleDownlink(const std::string& payload);
|
||||
bool publishJSON(const std::string& topic, const std::string& payloadJson);
|
||||
|
||||
std::string topicDown() const;
|
||||
std::string topicUp() const;
|
||||
std::string topicStatus() const;
|
||||
std::string topicRegister() const;
|
||||
|
||||
DaliComm& comm_;
|
||||
GatewayCloudConfig config_;
|
||||
std::atomic<bool> connected_{false};
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_mqtt_client_handle_t client_ = nullptr;
|
||||
#endif
|
||||
};
|
||||
Reference in New Issue
Block a user