feat: Switching to mqtt
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_WIFI_SSID
|
||||
config DEVICE_WIFI_SSID
|
||||
string "Wi-Fi SSID"
|
||||
default "eth2ap"
|
||||
help
|
||||
Set the SSID of Wi-Fi ap interface.
|
||||
|
||||
config EXAMPLE_WIFI_PASSWORD
|
||||
config DEVICE_WIFI_PASSWORD
|
||||
string "Wi-Fi Password"
|
||||
default "12345678"
|
||||
help
|
||||
Set the password of Wi-Fi ap interface.
|
||||
|
||||
config EXAMPLE_WIFI_CHANNEL
|
||||
config DEVICE_WIFI_CHANNEL
|
||||
int "WiFi channel"
|
||||
range 1 13
|
||||
default 1
|
||||
help
|
||||
Set the channel of Wi-Fi ap.
|
||||
|
||||
config EXAMPLE_MAX_STA_CONN
|
||||
config DEVICE_MAX_STA_CONN
|
||||
int "Maximum STA connections"
|
||||
default 4
|
||||
help
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
ethernet_init:
|
||||
path: ${IDF_PATH}/examples/ethernet/basic/components/ethernet_init
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct {
|
||||
const char *syslogDest = "syslogDst"; // example: "172.16.16.10"
|
||||
const char *mqttBroker = "mqttBroker"; // example: "172.16.16.10"
|
||||
const char *mqttPrefix = "mqttPrefix"; // example: "SomeTag"
|
||||
const char *spitServer = "spitServer"; // example: "172.16.16.10"
|
||||
} ConfigKeys;
|
||||
|
||||
// MQTT Topics
|
||||
struct {
|
||||
// Subscriptions:
|
||||
const char *moveTo = /* <mqttPrefix>/ */ "watch/moveTo";
|
||||
const char *startShuffle = /* <mqttPrefix>/ */ "watch/startShuffle";
|
||||
// Publishes:
|
||||
const char *inPosition = /* <mqttPrefix>/ */ "watch/inPosition";
|
||||
const char *changingPosition = /* <mqttPrefix>/ */ "watch/changingPosition";
|
||||
} MqttTopics;
|
||||
|
||||
struct {
|
||||
const char *expectedServer = "";
|
||||
struct {
|
||||
const char *group = "CatasWatchMovement";
|
||||
const char *startShuffle = "ActionStartShuffle";
|
||||
const char *moveToX[6] = {
|
||||
"ActionMoveTo1",
|
||||
"ActionMoveTo2",
|
||||
"ActionMoveTo3",
|
||||
"ActionMoveTo4",
|
||||
"ActionMoveTo5",
|
||||
"ActionMoveTo6",
|
||||
};
|
||||
} Provided;
|
||||
struct {
|
||||
const char *changingPos = "ChangingPositionScene";
|
||||
const char *inPosX[6] = {
|
||||
"InPosition1Scene",
|
||||
"InPosition2Scene",
|
||||
"InPosition3Scene",
|
||||
"InPosition4Scene",
|
||||
"InPosition5Scene",
|
||||
"InPosition6Scene",
|
||||
};
|
||||
} Expected;
|
||||
} SpitTypes;
|
||||
+38
-103
@@ -2,8 +2,6 @@
|
||||
* @file watchMain.cpp
|
||||
* @author Gustice
|
||||
* @brief ChaosWatch Application
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
|
||||
/* Watchface
|
||||
@@ -13,58 +11,8 @@
|
||||
3
|
||||
*/
|
||||
|
||||
struct {
|
||||
const char *syslogDest = "syslogDst"; // example: "172.16.16.10"
|
||||
const char *mqttBroker = "mqttBroker"; // example: "172.16.16.10"
|
||||
const char *mqttPrefix = "mqttPrefix"; // example: "SomeTag"
|
||||
const char *spitServer = "spitServer"; // example: "172.16.16.10"
|
||||
} ConfigKeys;
|
||||
|
||||
// MQTT Topics
|
||||
struct {
|
||||
// Subscriptions:
|
||||
const char *moveTo = /* <mqttPrefix>/ */ "watch/moveTo";
|
||||
const char *startShuffle = /* <mqttPrefix>/ */ "watch/startShuffle";
|
||||
// Publishes:
|
||||
const char *inPosition = /* <mqttPrefix>/ */ "watch/inPosition";
|
||||
const char *changingPosition = /* <mqttPrefix>/ */ "watch/changingPosition";
|
||||
} MqttTopics;
|
||||
|
||||
struct {
|
||||
const char *expectedServer = "";
|
||||
struct {
|
||||
const char *group = "CatasWatchMovement";
|
||||
const char *startShuffle = "ActionStartShuffle";
|
||||
const char *moveToX[6] = {
|
||||
"ActionMoveTo1",
|
||||
"ActionMoveTo2",
|
||||
"ActionMoveTo3",
|
||||
"ActionMoveTo4",
|
||||
"ActionMoveTo5",
|
||||
"ActionMoveTo6",
|
||||
};
|
||||
} Provided;
|
||||
struct {
|
||||
const char *changingPos = "ChangingPositionScene";
|
||||
const char *inPosX[6] = {
|
||||
"InPosition1Scene",
|
||||
"InPosition2Scene",
|
||||
"InPosition3Scene",
|
||||
"InPosition4Scene",
|
||||
"InPosition5Scene",
|
||||
"InPosition6Scene",
|
||||
};
|
||||
} Expected;
|
||||
} SpitTypes;
|
||||
|
||||
// ToDo:
|
||||
// - MQTT Integration
|
||||
// - OTA
|
||||
// - Syslog heartbeat
|
||||
// - Streamlined DMX
|
||||
// -
|
||||
|
||||
#include "watchMain.hpp"
|
||||
#include "interconConfig.hpp"
|
||||
|
||||
string ClientName = "CatasWatchDev";
|
||||
string ProjectName = "CatastrphicProj";
|
||||
@@ -112,7 +60,7 @@ static fos::Queue<PictoIllumCommand> pictoIllumQue(2);
|
||||
|
||||
DeviceState activeState;
|
||||
static const char *TAG = "Watch";
|
||||
static bool EthernetIsConnected = false;
|
||||
bool EthernetIsConnected = false;
|
||||
|
||||
std::unique_ptr<Cli> pShell;
|
||||
|
||||
@@ -312,8 +260,6 @@ void moveToSubs(std::string data) {
|
||||
int p = std::stoi(data);
|
||||
Syslog::logv(Syslog::Severity::Informational, "got MoveTo-Cmd->%i", p);
|
||||
commandQueue.enqueue(std::make_unique<MoveCommand>(MoveType::StepTo, p));
|
||||
auto &client = MqttClient::getInstance();
|
||||
client.publish(MqttTopics.inPosition, data + "Picto");
|
||||
} catch (const std::exception &e) {
|
||||
ESP_LOGE(TAG, "Error to process data %s, with ex: %s", data.c_str(), e.what());
|
||||
}
|
||||
@@ -321,12 +267,9 @@ void moveToSubs(std::string data) {
|
||||
|
||||
void startShuffle(std::string data) {
|
||||
ESP_LOGI(TAG, "StartShuffle command %s", data.c_str());
|
||||
|
||||
try {
|
||||
Syslog::logv(Syslog::Severity::Informational, "got Shuffle-Command");
|
||||
commandQueue.enqueue(std::make_unique<MoveCommand>(MoveType::Shuffle, 0));
|
||||
auto &client = MqttClient::getInstance();
|
||||
client.publish(MqttTopics.changingPosition, "....");
|
||||
} catch (const std::exception &e) {
|
||||
ESP_LOGE(TAG, "Error to process data %s, with ex: %s", data.c_str(), e.what());
|
||||
}
|
||||
@@ -360,7 +303,6 @@ static void dmxSocketSenderTask(UdpSocket &socket) {
|
||||
* @param args ignored task argument
|
||||
*/
|
||||
static void dmxSocketTask(int addrFamily) {
|
||||
|
||||
ESP_LOGI(TAG, "Starting ArtNet task");
|
||||
constexpr uint16_t ArtNetPort = arx::artnet::DEFAULT_PORT;
|
||||
IpAdr address = addrFamily == AF_INET ? IpAdr(INADDR_ANY, ArtNetPort) : IpAdr(ArtNetPort);
|
||||
@@ -389,7 +331,7 @@ fos::Semaphore etherActive;
|
||||
fos::Semaphore spitProjectFinish;
|
||||
|
||||
/** Event handler for IP_EVENT_ETH_GOT_IP */
|
||||
static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data) {
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
|
||||
const esp_netif_ip_info_t *ip_info = &event->ip_info;
|
||||
@@ -403,37 +345,10 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
etherActive.give();
|
||||
}
|
||||
|
||||
// Event handler for Ethernet
|
||||
static void eth_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data) {
|
||||
uint8_t mac_addr[6] = {0};
|
||||
switch (event_id) {
|
||||
case ETHERNET_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "Ethernet Link Up");
|
||||
EthernetIsConnected = true;
|
||||
ESP_LOGI(TAG, "Ethernet Link Up");
|
||||
ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||
break;
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "Ethernet Link Down");
|
||||
EthernetIsConnected = false;
|
||||
break;
|
||||
case ETHERNET_EVENT_START:
|
||||
ESP_LOGI(TAG, "Ethernet Started");
|
||||
break;
|
||||
case ETHERNET_EVENT_STOP:
|
||||
ESP_LOGI(TAG, "Ethernet Stopped");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void initialize_ethernet(void) {
|
||||
uint8_t eth_port_cnt = 0;
|
||||
esp_eth_handle_t *eth_handles;
|
||||
ESP_ERROR_CHECK(example_eth_init(ð_handles, ð_port_cnt));
|
||||
ESP_ERROR_CHECK(eth_init(ð_handles, ð_port_cnt));
|
||||
if (eth_port_cnt > 1) {
|
||||
ESP_LOGW(TAG, "multiple Ethernet devices detected, the first initialized is to be used!");
|
||||
}
|
||||
@@ -656,6 +571,7 @@ void MovementTask() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LocalSpitObj {
|
||||
string iD;
|
||||
string groupName;
|
||||
@@ -851,7 +767,6 @@ void onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_Pl
|
||||
*/
|
||||
void onPlaySpitType(string p_PlayerID, string spitTypeId, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value) {
|
||||
// double doubleValue = ((double)p_PlayObject.getValue() / 1000000) * ((double)p_PlayObject.getValueFactor() / 1000000);
|
||||
|
||||
ESP_LOGD(TAG, "eventPlayObject Player: %s is running: %d Object Started: %d Stopped: %d", p_PlayerID.data(), p_PlayerIsRunning, p_Started, p_Ended);
|
||||
// ESP_LOGD(TAG, " SPITType: %s SPITObject: %s Position: %lld Value: %f\n", spitTypeId.data(), p_SPITObject.getName().data(), p_PlayObject.getFrameInside(), doubleValue);
|
||||
ESP_LOGD(TAG, " SPITType: %s Value: %f\n", spitTypeId.data(), p_Value);
|
||||
@@ -938,6 +853,32 @@ void SpitClientApp() {
|
||||
}
|
||||
}
|
||||
|
||||
void MqttThread() {
|
||||
ESP_LOGI(TAG, "Starting MQTT task");
|
||||
|
||||
auto &store = NvsApi::getInstance();
|
||||
auto broker = store.getValue(ConfigKeys.mqttBroker);
|
||||
if (broker != "") {
|
||||
ESP_LOGI(TAG, "Initializing MQTT");
|
||||
auto prefix = store.getValue(ConfigKeys.mqttPrefix);
|
||||
auto &client = MqttClient::init(broker, prefix);
|
||||
if (!client.isRunning()) {
|
||||
client.addSubscription(MqttTopics.moveTo, [](std::string d) { moveToSubs(d); });
|
||||
client.addSubscription(MqttTopics.startShuffle, [](std::string d) { startShuffle(d); });
|
||||
client.start();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
auto res = responseQueue.dequeue();
|
||||
if (res->type == ResponseType::StartMoving) {
|
||||
client.publish(MqttTopics.changingPosition, "");
|
||||
} else if (res->type == ResponseType::StepAt) {
|
||||
client.publish(MqttTopics.inPosition, std::to_string(res->pos) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
// esp_err_t ret = nvs_flash_init();
|
||||
// if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
@@ -953,14 +894,14 @@ void app_main(void) {
|
||||
etherActive.take();
|
||||
fos::Task::delayMs(10000);
|
||||
ESP_LOGI(TAG, "Start net services");
|
||||
|
||||
// esp_log_level_set("SPIT", esp_log_level_t::ESP_LOG_DEBUG);
|
||||
|
||||
static int ipVersion = AF_INET;
|
||||
static fos::TaskT<int> telnetSocket(telnetSocketTask, ipVersion, "tcpServer", 4096);
|
||||
static fos::TaskT<int> dmxNode(dmxSocketTask, ipVersion, "dmxNode", 4096);
|
||||
// static fos::Task spit(SpitClientApp, "SpitClient");
|
||||
static fos::Task mqtt(MqttThread, "MqttEndpoint");
|
||||
// static Task otaUpdate(SystemFunctions::OtaTaskEntry, "otaTask", 8192);
|
||||
static fos::Task spit(SpitClientApp, "SpitClient");
|
||||
|
||||
auto &store = NvsApi::getInstance();
|
||||
auto logger = store.getValue(ConfigKeys.syslogDest);
|
||||
@@ -968,17 +909,11 @@ void app_main(void) {
|
||||
Syslog::setupTask(IpAdr{logger, 0});
|
||||
}
|
||||
|
||||
// auto broker = store.getValue(ConfigKeys.mqttBroker);
|
||||
// if (broker != "") {
|
||||
// ESP_LOGI(TAG, "Initializing MQTT");
|
||||
// auto prefix = store.getValue(ConfigKeys.mqttPrefix);
|
||||
// auto &client = MqttClient::init(broker, prefix);
|
||||
// if (!client.isRunning()) {
|
||||
// client.addSubscription(MqttTopics.moveTo, [](std::string d) { moveToSubs(d); });
|
||||
// client.addSubscription(MqttTopics.startShuffle, [](std::string d) { startShuffle(d); });
|
||||
// client.start();
|
||||
// }
|
||||
// }
|
||||
ESP_LOGI(TAG, "Configuration");
|
||||
ESP_LOGI(TAG, "%s: %s", ConfigKeys.syslogDest, store.getValue(ConfigKeys.syslogDest).c_str());
|
||||
ESP_LOGI(TAG, "%s: %s", ConfigKeys.mqttBroker, store.getValue(ConfigKeys.mqttBroker).c_str());
|
||||
ESP_LOGI(TAG, "%s: %s", ConfigKeys.mqttPrefix, store.getValue(ConfigKeys.mqttPrefix).c_str());
|
||||
ESP_LOGI(TAG, "%s: %s", ConfigKeys.spitServer, store.getValue(ConfigKeys.spitServer).c_str());
|
||||
|
||||
while (true) {
|
||||
fos::Task::delayMs(5000);
|
||||
|
||||
Reference in New Issue
Block a user