diff --git a/info/xdrv_57_tasmesh.md b/info/xdrv_57_tasmesh.md index b3a6018c5..2da2fac19 100644 --- a/info/xdrv_57_tasmesh.md +++ b/info/xdrv_57_tasmesh.md @@ -22,7 +22,7 @@ Add ``#define USE_TASMESH`` to your file ``user_config_override.h`` before compi ## Commands -**WARNING: The MAC address used for ESP-NOW is the *Soft AP MAC*, not the WiFi MAC.** +**WARNING: The MAC address used for ESP-NOW on the broker is the *Soft AP MAC*, not the WiFi MAC.** *NOTE: The colons in the mac addresses of the commands are optional.* diff --git a/tasmota/xdrv_57_1_tasmesh_support.ino b/tasmota/xdrv_57_1_tasmesh_support.ino index 81949af0f..5c3718adc 100644 --- a/tasmota/xdrv_57_1_tasmesh_support.ino +++ b/tasmota/xdrv_57_1_tasmesh_support.ino @@ -41,10 +41,13 @@ #define MESH_MAX_PACKETS 3 // (3) Max number of packets #define MESH_REFRESH 50 // Number of ms +// The format of the vendor-specific action frame is as follows: // ------------------------------------------------------------------------------------------------------------ // | MAC Header | Category Code | Organization Identifier | Random Values | Vendor Specific Content | FCS | // ------------------------------------------------------------------------------------------------------------ // 24 bytes 1 byte 3 bytes 4 bytes 7~255 bytes 4 bytes +// +// The Vendor Specific Content contains vendor-specific fields as follows: // ------------------------------------------------------------------------------- // | Element ID | Length | Organization Identifier | Type | Version | Body | // ------------------------------------------------------------------------------- diff --git a/tasmota/xdrv_57_9_tasmesh.ino b/tasmota/xdrv_57_9_tasmesh.ino index 223abe266..d309b4d59 100644 --- a/tasmota/xdrv_57_9_tasmesh.ino +++ b/tasmota/xdrv_57_9_tasmesh.ino @@ -288,7 +288,7 @@ bool MESHroleNode(void) { } /** - * @brief Redirects the mqtt message on the node just before it would have been sended to + * @brief Redirects the outgoing mqtt message on the node just before it would have been sent to * the broker via ESP-NOW * * @param _topic @@ -385,8 +385,9 @@ void MESHstartNode(int32_t _channel, uint8_t _role){ //we need a running broker wifi_promiscuous_enable(0); WiFi.disconnect(); MESHsetWifi(0); - esp_err_t init_result = esp_now_init(); - if (esp_err_t() != ESP_OK) { + esp_now_deinit(); // in case it was already initialized but disconnected + int init_result = esp_now_init(); + if (init_result != 0) { AddLog(LOG_LEVEL_INFO, PSTR("MSH: Node init failed with error: %d"), init_result); // try to re-launch wifi MESH.role = ROLE_NONE; @@ -422,9 +423,10 @@ void MESHstartBroker(void) { // Must be called after WiFi is initialized!! WiFi.softAPmacAddress(MESH.broker); //set MESH.broker to the needed MAC uint32_t _channel = WiFi.channel(); + esp_now_deinit(); // in case it was already initialized by disconnected esp_err_t init_result = esp_now_init(); if (esp_err_t() != ESP_OK) { - AddLog(LOG_LEVEL_INFO, PSTR("MSH: Broker init failed with error: %d"), init_result); + AddLog(LOG_LEVEL_INFO, PSTR("MSH: Broker init failed with error: %s"), init_result); return; } @@ -648,6 +650,7 @@ void MESHEverySecond(void) { if (millis() - MESH.lastMessageFromBroker > 70000) { AddLog(LOG_LEVEL_DEBUG, PSTR("MSH: Broker not seen for 70 secs, try to re-launch wifi")); MESH.role = ROLE_NONE; + MESHdeInit(); // if we don't deinit after losing connection, we will get an error trying to reinit later MESHsetWifi(1); WifiBegin(3, MESH.channel); } @@ -735,12 +738,15 @@ void (* const MeshCommand[])(void) PROGMEM = { &CmndMeshBroker, &CmndMeshNode, &CmndMeshPeer, &CmndMeshChannel, &CmndMeshInterval }; void CmndMeshBroker(void) { +#ifdef ESP32 // only ESP32 currently supported as broker MESH.channel = WiFi.channel(); // The Broker gets the channel from the router, no need to declare it with MESHCHANNEL (will be mandatory set it when ETH will be implemented) MESHstartBroker(); ResponseCmndNumber(MESH.channel); +#endif // ESP32 } void CmndMeshNode(void) { +#ifndef ESP32 // only ESP8266 current supported as node if (XdrvMailbox.data_len > 0) { MESHHexStringToBytes(XdrvMailbox.data, MESH.broker); if (XdrvMailbox.index != 0) { XdrvMailbox.index = 1; } // Everything not 0 is a full node @@ -766,6 +772,7 @@ void CmndMeshNode(void) { AddLog(LOG_LEVEL_INFO, PSTR("MSH: No Mesh Broker found using MAC %s"), XdrvMailbox.data); } } +#endif // ESP32 } void CmndMeshPeer(void) {