From 096f5606b60c7efeb96d838f8a599c56523e8b1d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 22 Jun 2021 14:12:05 +0200 Subject: [PATCH] Add ESP-NOW hooks --- tasmota/xdrv_02_9_mqtt.ino | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tasmota/xdrv_02_9_mqtt.ino b/tasmota/xdrv_02_9_mqtt.ino index 30789fa2f..35bcc03f6 100644 --- a/tasmota/xdrv_02_9_mqtt.ino +++ b/tasmota/xdrv_02_9_mqtt.ino @@ -476,6 +476,13 @@ bool MqttPublishLib(const char* topic, const uint8_t* payload, unsigned int plen } } +#ifdef USE_TASMESH + if (MESHrouteMQTTtoMESH(topic, (char*)payload, retained)) { // If we are a node, send this via ESP-Now + yield(); + return true; + } +#endif // USE_TASMESH + #ifdef USE_MQTT_AZURE_IOT String sourceTopicString = urlEncodeBase64(String(topic)); String topicString = "devices/" + String(SettingsText(SET_MQTT_CLIENT)); @@ -555,6 +562,14 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len TasmotaGlobal.masterlog_level = LOG_LEVEL_DEBUG_MORE; // Hide logging } +#ifdef USE_TASMESH +#ifdef ESP32 + if (MESHinterceptMQTTonBroker(topic, (uint8_t*)mqtt_data, data_len +1)) { + return; // Check if this is a message for a node + } +#endif // ESP32 +#endif // USE_TASMESH + // MQTT pre-processing XdrvMailbox.index = strlen(topic); XdrvMailbox.data_len = data_len; @@ -621,7 +636,11 @@ void MqttPublishPayload(const char* topic, const char* payload, uint32_t binary_ // To lower heap usage the payload is not copied to the heap but used directly String log_data_topic; // 20210420 Moved to heap to solve tight stack resulting in exception 2 if (Settings->flag.mqtt_enabled && MqttPublishLib(topic, (const uint8_t*)payload, binary_length, retained)) { // SetOption3 - Enable MQTT +#ifdef USE_TASMESH + log_data_topic = (MESHroleNode()) ? F("MSH: ") : F(D_LOG_MQTT); // MSH: or MQT: +#else log_data_topic = F(D_LOG_MQTT); // MQT: +#endif log_data_topic += topic; // stat/tasmota/STATUS2 } else { log_data_topic = F(D_LOG_RESULT); // RSL: