diff --git a/core b/core index 02db420..8af1c2f 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 02db420163fd6bc8e7eec5b6fff957b01b0db476 +Subproject commit 8af1c2f5554b1f3bc16143fb52d51b5c3883653e diff --git a/dependencies.lock b/dependencies.lock index 9fb4267..e9e979e 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -1,17 +1,10 @@ dependencies: - ethernet_init: - dependencies: [] - source: - path: /home/gustice/esp/v5.4.1/esp-idf/examples/ethernet/basic/components/ethernet_init - type: local - version: '*' idf: source: type: idf version: 5.4.1 direct_dependencies: -- ethernet_init - idf -manifest_hash: dfcb516d4bd1043fe7dbc63ade7e95173fcf2993c59d7108e7b96cb5af8f7ebd +manifest_hash: 00d8efc8e59d9f2cc6a576ada310175e19e6f7506dd0b59211849f065dadccae target: esp32c6 version: 2.0.0 diff --git a/doc/LiveShowProject/CatasWatchProject.lsb b/doc/LiveShowProject/CatasWatchProject.lsb index cd59ea5..09d8e59 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsb and b/doc/LiveShowProject/CatasWatchProject.lsb differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsc b/doc/LiveShowProject/CatasWatchProject.lsc index 0d2c322..06f4529 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsc and b/doc/LiveShowProject/CatasWatchProject.lsc differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsh b/doc/LiveShowProject/CatasWatchProject.lsh index 7e89b9f..5ec3783 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsh and b/doc/LiveShowProject/CatasWatchProject.lsh differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsp b/doc/LiveShowProject/CatasWatchProject.lsp index c43e4d5..3be1e38 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsp and b/doc/LiveShowProject/CatasWatchProject.lsp differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsu b/doc/LiveShowProject/CatasWatchProject.lsu index 076cef2..57e5512 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsu and b/doc/LiveShowProject/CatasWatchProject.lsu differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsx b/doc/LiveShowProject/CatasWatchProject.lsx index 3f0917e..ad58ca2 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsx and b/doc/LiveShowProject/CatasWatchProject.lsx differ diff --git a/doc/LiveShowProject/CatasWatchProject.spi b/doc/LiveShowProject/CatasWatchProject.spi index 2c08aca..7a51c8e 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.spi and b/doc/LiveShowProject/CatasWatchProject.spi differ diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 885ccf6..0be2ccc 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -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 diff --git a/main/idf_component.yml b/main/idf_component.yml deleted file mode 100644 index 8453ecc..0000000 --- a/main/idf_component.yml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - ethernet_init: - path: ${IDF_PATH}/examples/ethernet/basic/components/ethernet_init diff --git a/main/interconConfig.hpp b/main/interconConfig.hpp new file mode 100644 index 0000000..02aab38 --- /dev/null +++ b/main/interconConfig.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include + +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 = /* / */ "watch/moveTo"; + const char *startShuffle = /* / */ "watch/startShuffle"; + // Publishes: + const char *inPosition = /* / */ "watch/inPosition"; + const char *changingPosition = /* / */ "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; \ No newline at end of file diff --git a/main/watchMain.cpp b/main/watchMain.cpp index 815e588..38efde6 100644 --- a/main/watchMain.cpp +++ b/main/watchMain.cpp @@ -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 = /* / */ "watch/moveTo"; - const char *startShuffle = /* / */ "watch/startShuffle"; - // Publishes: - const char *inPosition = /* / */ "watch/inPosition"; - const char *changingPosition = /* / */ "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 pictoIllumQue(2); DeviceState activeState; static const char *TAG = "Watch"; -static bool EthernetIsConnected = false; +bool EthernetIsConnected = false; std::unique_ptr 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(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(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 telnetSocket(telnetSocketTask, ipVersion, "tcpServer", 4096); static fos::TaskT 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); diff --git a/sdkconfig b/sdkconfig index 3fb6282..be2a953 100644 --- a/sdkconfig +++ b/sdkconfig @@ -582,10 +582,10 @@ CONFIG_PARTITION_TABLE_MD5=y # # Example Configuration # -CONFIG_EXAMPLE_WIFI_SSID="eth2ap" -CONFIG_EXAMPLE_WIFI_PASSWORD="12345678" -CONFIG_EXAMPLE_WIFI_CHANNEL=1 -CONFIG_EXAMPLE_MAX_STA_CONN=4 +CONFIG_DEVICE_WIFI_SSID="eth2ap" +CONFIG_DEVICE_WIFI_PASSWORD="12345678" +CONFIG_DEVICE_WIFI_CHANNEL=1 +CONFIG_DEVICE_MAX_STA_CONN=4 # end of Example Configuration # @@ -595,27 +595,21 @@ CONFIG_ENV_GPIO_RANGE_MIN=0 CONFIG_ENV_GPIO_RANGE_MAX=30 CONFIG_ENV_GPIO_IN_RANGE_MAX=30 CONFIG_ENV_GPIO_OUT_RANGE_MAX=30 -# CONFIG_USE_SPI_ETHERNET is not set -# end of Example Ethernet Configuration - -# -# Example Ethernet Configuration -# -CONFIG_EXAMPLE_USE_SPI_ETHERNET=y -CONFIG_EXAMPLE_SPI_ETHERNETS_NUM=1 -# CONFIG_EXAMPLE_USE_DM9051 is not set -# CONFIG_EXAMPLE_USE_KSZ8851SNL is not set -CONFIG_EXAMPLE_USE_W5500=y -CONFIG_EXAMPLE_ETH_SPI_HOST=1 -CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO=6 -CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO=7 -CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO=2 -CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ=16 -CONFIG_EXAMPLE_ETH_SPI_CS0_GPIO=3 -CONFIG_EXAMPLE_ETH_SPI_INT0_GPIO=4 -CONFIG_EXAMPLE_ETH_SPI_POLLING0_MS=0 -CONFIG_EXAMPLE_ETH_SPI_PHY_RST0_GPIO=-1 -CONFIG_EXAMPLE_ETH_SPI_PHY_ADDR0=1 +CONFIG_USE_SPI_ETHERNET=y +CONFIG_SPI_ETHERNETS_NUM=1 +# CONFIG_USE_DM9051 is not set +# CONFIG_USE_KSZ8851SNL is not set +CONFIG_USE_W5500=y +CONFIG_ETH_SPI_HOST=1 +CONFIG_ETH_SPI_SCLK_GPIO=6 +CONFIG_ETH_SPI_MOSI_GPIO=7 +CONFIG_ETH_SPI_MISO_GPIO=2 +CONFIG_ETH_SPI_CLOCK_MHZ=16 +CONFIG_ETH_SPI_CS0_GPIO=3 +CONFIG_ETH_SPI_INT0_GPIO=4 +CONFIG_ETH_SPI_POLLING0_MS=0 +CONFIG_ETH_SPI_PHY_RST0_GPIO=-1 +CONFIG_ETH_SPI_PHY_ADDR0=1 # end of Example Ethernet Configuration # diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 2d141da..861053f 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -5,24 +5,24 @@ CONFIG_COMPILER_CXX_EXCEPTIONS=y CONFIG_LWIP_LOCAL_HOSTNAME="ChaosWatch" # -# Example Ethernet Configuration +# Ethernet Configuration # -CONFIG_EXAMPLE_USE_SPI_ETHERNET=y -CONFIG_EXAMPLE_SPI_ETHERNETS_NUM=1 -# CONFIG_EXAMPLE_USE_DM9051 is not set -# CONFIG_EXAMPLE_USE_KSZ8851SNL is not set -CONFIG_EXAMPLE_USE_W5500=y -CONFIG_EXAMPLE_ETH_SPI_HOST=1 -CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO=6 -CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO=7 -CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO=2 -CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ=16 -CONFIG_EXAMPLE_ETH_SPI_CS0_GPIO=3 -CONFIG_EXAMPLE_ETH_SPI_INT0_GPIO=4 -CONFIG_EXAMPLE_ETH_SPI_POLLING0_MS=0 -CONFIG_EXAMPLE_ETH_SPI_PHY_RST0_GPIO=-1 -CONFIG_EXAMPLE_ETH_SPI_PHY_ADDR0=1 -# end of Example Ethernet Configuration +CONFIG_USE_SPI_ETHERNET=y +CONFIG_SPI_ETHERNETS_NUM=1 +# CONFIG_USE_DM9051 is not set +# CONFIG_USE_KSZ8851SNL is not set +CONFIG_USE_W5500=y +CONFIG_ETH_SPI_HOST=1 +CONFIG_ETH_SPI_SCLK_GPIO=6 +CONFIG_ETH_SPI_MOSI_GPIO=7 +CONFIG_ETH_SPI_MISO_GPIO=2 +CONFIG_ETH_SPI_CLOCK_MHZ=16 +CONFIG_ETH_SPI_CS0_GPIO=3 +CONFIG_ETH_SPI_INT0_GPIO=4 +CONFIG_ETH_SPI_POLLING0_MS=0 +CONFIG_ETH_SPI_PHY_RST0_GPIO=-1 +CONFIG_ETH_SPI_PHY_ADDR0=1 +# end of Ethernet Configuration # # Ethernet