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:
@@ -9,6 +9,8 @@
|
||||
#include "dt1.hpp"
|
||||
#include "dt8.hpp"
|
||||
#include "addr.hpp"
|
||||
#include "gateway_cloud.hpp"
|
||||
#include "gateway_provisioning.hpp"
|
||||
#include "color.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "gateway_cloud.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
extern "C" {
|
||||
#include "esp_err.h"
|
||||
}
|
||||
#else
|
||||
using esp_err_t = int;
|
||||
#endif
|
||||
|
||||
// Stores/loads gateway cloud configuration using ESP-IDF NVS.
|
||||
class GatewayProvisioningStore {
|
||||
public:
|
||||
explicit GatewayProvisioningStore(std::string nvsNamespace = "dali_cloud")
|
||||
: nvsNamespace_(std::move(nvsNamespace)) {}
|
||||
|
||||
esp_err_t save(const GatewayCloudConfig& config) const;
|
||||
esp_err_t load(GatewayCloudConfig* config) const;
|
||||
esp_err_t clear() const;
|
||||
|
||||
private:
|
||||
std::string nvsNamespace_;
|
||||
};
|
||||
Reference in New Issue
Block a user