Skip to content

Instantly share code, notes, and snippets.

@recrof
Created September 12, 2025 17:42
Show Gist options
  • Select an option

  • Save recrof/504dca2a96950b0870230c6cc4cfc437 to your computer and use it in GitHub Desktop.

Select an option

Save recrof/504dca2a96950b0870230c6cc4cfc437 to your computer and use it in GitHub Desktop.

MeshCore routing for dummies

Imagine you're in a large, crowded room, and you want to get a message to your friend, Zoe, who is on the other side. You don't know the best way to get the message to her. This mesh network system uses two main strategies to solve this problem.

1. Discovering a Path: "Shouting into the Crowd" (Flood Routing)

This is how a device finds a path to another device for the first time.

  • The Initial Shout: Your device (let's call it Node A) wants to find Node Z. It sends out a special "discovery" message. Think of this as shouting, "Message for Zoe! If you hear this, sign your name and pass it on!" This is called a Flood packet.

  • Passing it On: Every device nearby hears this message. Let's say Node B hears it. Node B does two things:

    1. It "signs" the message by adding its own unique ID to a list on the message. The list now says "from A, via B".
    2. It then shouts out the newly signed message.
  • Spreading the Message: Node C and Node D hear the message from Node B. They each add their own ID to the list ("from A, via B, via C") and shout it out again. This process repeats, with the message spreading through the network like a ripple in a pond.

  • Avoiding Loops: To prevent the message from echoing forever, if a device hears a message that it has already signed and passed on, it simply ignores it.

  • Zoe Hears the Message: Eventually, Node Z (Zoe) will hear the message. It might even hear it multiple times from different directions! The first one it receives will have a complete list of all the nodes the message passed through to get there. For example, the list might be: [B, F, K]. This is a working path from A to Z!

This "flooding" method is great for discovery, but it's noisy and inefficient for regular conversation. It's like everyone in the room shouting at once. Once a path is found, the system switches to a much quieter method.

2. Using a Path: "Passing a Note" (Direct Routing)

Now that Node Z knows a path back to Node A, it can send messages much more efficiently.

  • The Reply Note: Node Z creates a reply message for Node A. It attaches the path it discovered [B, F, K], but in reverse order: [K, F, B]. This is now a Direct packet.

  • The First Hop: Node Z sends the message. Because of how radio works, only its immediate neighbors can hear it. Out of all the neighbors, only Node K sees its ID at the front of the path list. Node K knows the message is for it to handle.

  • Passing it Along: Node K takes the "note," crosses its own ID off the list, and sends the message again. The path list now just says [F, B].

  • The Next Hop: The process repeats. Node F hears the message, sees its ID at the front, crosses it off, and forwards it. The list is now just [B].

  • Final Delivery: Finally, Node B receives the message, sees its name, crosses it off, and forwards it one last time. Now Node A receives the message with an empty path list, and the delivery is complete.

This "direct routing" method is like quietly passing a note from person to person. It's fast, efficient, and doesn't disturb anyone who isn't part of the path.

In Summary

Method Analogy When is it Used? How it Works
Flood Routing Shouting into a crowd To discover a path to a new device. The message is broadcast by everyone. Each device adds its ID to the message's path list before re-broadcasting.
Direct Routing Passing a note To communicate efficiently once a path is known. The message contains an ordered list of "hops." Each device on the list forwards the message to the next one on the list.

This two-step process allows the mesh network to be both robust (it can automatically discover routes) and efficient (it uses quiet, point-to-point messages for most communication). The logic for this is primarily handled in the Mesh.cpp file you provided, which decides whether to treat a packet as a "shout" or a "note."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment