esp-mesh-lite icon indicating copy to clipboard operation
esp-mesh-lite copied to clipboard

Issue with MESH Lite Communication After Merging with MQTT — Data Not Exchanging Between Master & Slave (AEGHB-1086)

Open gajananmaske1234 opened this issue 7 months ago • 6 comments

Checklist

  • [x] Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • [x] Provided a clear description of your suggestion.
  • [x] Included any relevant context or examples.

Issue or Suggestion Description

Hi all,

I'm working on a project where: Master device connects to a Wi-Fi router and publishes data using MQTT (this part is working fine ✅). Slave device is connected to the master via ESP-MESH Lite (using the no_router example as the reference).

Working : MQTT connection and data publish/subscribe from master to cloud.

MESH network formation: Logs from slave show parent MAC as the master. Logs from master show child MAC as the slave.

Devices are connected in the MESH network (confirmed via logs). Both MQTT and mesh components initialize without error.

Not Working: After merging the no_router (MESH Lite) example with my MQTT code, the master and slave are no longer able to exchange data over MESH. I’ve confirmed:

What I Expect

  1. Master should send/receive data from slave over MESH Lite (no internet/router needed for MESH path).
  2. At the same time, Master should continue its MQTT communication with the cloud over Wi-Fi.

What I'm Looking For Any working example that combines MESH Lite and MQTT? Any suggestions on how to debug mesh data transfer specifically? Best practices to combine Wi-Fi STA (for MQTT) and MESH (for slave comm) cleanly?

gajananmaske1234 avatar May 16 '25 04:05 gajananmaske1234

Slave device is connected to the master via ESP-MESH Lite (using the no_router example as the reference).

Both Root/Leaf/Intermediate Parent nodes can communicate directly with the MQTT broker. Messages from Leaf/Intermediate Parent nodes are forwarded through the root node.

+-----------+                      +----------+
|           |<---(mqtt request)----|   root   |
|           |                      |          |
|mqtt broker|                      |          |
|           |                      |          |                      +----------+
|           |<---(mqtt request)----|          |<---(mqtt request)----|   leaf   |
+-----------+                      +----------+                      +----------+

Is this not good enough?

PS)MESH-LITE does not use Master/Slave. https://github.com/espressif/esp-mesh-lite/blob/master/components/mesh_lite/User_Guide.md

ESP-MESH-LITE Node Type
Root Node: Nodes at the top of the network, which serve as the only interface between the ESP-MESH-LITE network and the external IP network. The Root Node connects directly to the traditional Wi-Fi router and acts as a bridge between the nodes of the ESP-MESH-LITE network and the external IP network. Normally, there can only be one root node in an ESP-MESH-LITE network, and the root node's upstream connection can only be to a router. As shown in the figure above, Node A is the root node of this ESP-MESH-LITE network.

Leaf Node: Nodes that are not allowed to have any child nodes (i.e., no downstream connections). If a node is on the maximum allowed layer of the ESP-MESH-LITE network, the node will become a leaf node. Leaf nodes do not generate further downstream connections, ensuring that the network layers will not exceed the limit. Since the SoftAP interface is required to establish downstream connections, some nodes with station interface only will also be assigned as leaf nodes. As shown in the figure above, the L/M/N nodes on the outermost layer of the network are the leaf nodes.

Intermediate Parent Node: A node that is neither a root nor a leaf node is an intermediate parent node. An intermediate parent node must have one and only one upstream connection (i.e., one parent node), yet can have zero or more downstream connections (i.e., zero or more child nodes). Therefore, an intermediate parent node can send and receive its own packets, as well as forward packets from its upstream and downstream connections. As shown in the figure above, nodes B to J are intermediate parent nodes. Note that intermediate parent nodes such as E/F/G/I/J without downstream connections are not equivalent to leaf nodes, as these nodes are still allowed to establish downstream connections.

Idle Node: A node that has not yet joined the network is considered an idle node. An idle node will attempt to establish an upstream connection with an intermediate parent node, or become a root node if available (see [Automatic Root Node Selection](https://github.com/espressif/esp-mesh-lite/blob/master/components/mesh_lite/User_Guide.md#automatic-root-node-selection)). As shown in the figure above, K and O are idle nodes.

nopnop2002 avatar May 16 '25 08:05 nopnop2002

I would suggest using the mesh Lite example of "local control" as you are using a router (Access Point) and you have a master connected to said router and in some way or another controlling it.

the no route configuration is best used when the mesh is self contained

Edit: you can directly port the MQTT/TCP example into the local control example and call "mqtt_app_start()" on IP event of "IP_EVENT_STA_GOT_IP"

BR-Coding-cmd avatar May 16 '25 08:05 BR-Coding-cmd

you can directly port the MQTT/TCP example into the local control example and call mqtt start on IP event of "IP_EVENT_STA_GOT_IP"

Here is example. https://github.com/nopnop2002/esp-mesh-lite-examples/tree/main/mesh_mqtt_client

nopnop2002 avatar May 16 '25 08:05 nopnop2002

I am using already developed code for MQTT with provising using scanner. Mesh lite example : https://github.com/nopnop2002/esp-mesh-lite-examples/tree/main/router_less_message_exchange

Router <- Parent Node <-> child node MQTT MESH LITE

I want to connect root device only to router rest of the communication should be on elite mesh with no router example.

gajananmaske1234 avatar May 16 '25 10:05 gajananmaske1234

After merging the no_router (MESH Lite) example with my MQTT code, the master and slave are no longer able to exchange data over MESH.

I have confirmed that only the root node direct connects to Host, and that the root and leaf nodes can communicate internally.

I think there is something wrong with your code.

I want to connect root device only to router rest of the communication should be on elite mesh with no router example.

Is there any special reason why only the root node directly connect to the MQTT brokerr and the leaf node does not directly connect to the MQTT broker?

I am using already developed code for MQTT with provising using scanner.

If your project meets the MESH-LITE specifications, you can build MESH network by simply flashing the same project to multiple ESP32s.

nopnop2002 avatar May 16 '25 11:05 nopnop2002

https://github.com/espressif/esp-mesh-lite/edit/master/examples/mesh_local_control/sdkconfig.defaults#L21-L24

Some necessary configuration items also need to be checked for correct settings.

tswen avatar May 19 '25 02:05 tswen