MeshCore routing algorithms
Discover how MeshCore messages automatically find the best route through the mesh network. Technical explanation of flooding, hop limiting and route discovery.
How does a message find its way through the mesh network?
In a mesh network there is no central router that determines which route a message should take. Instead, MeshCore uses intelligent routing algorithms that ensure messages automatically find the most efficient route to their destination.
The MeshCore routing protocol is based on flooding with optimizations. This means messages are broadcast in multiple directions, but with smart mechanisms to prevent network congestion and save battery life.
In this technical guide we explain how the MeshCore routing algorithm works, which optimizations are applied, and how you can configure routing for your specific use case.
Basic routing protocol mechanisms
MeshCore uses four core mechanisms for routing:
Flood routing
Messages are broadcast to all nodes in range. Each node that receives the message forwards it until the maximum hop count is reached.
Duplicate detection
Each message has a unique ID. Nodes remember recently seen messages and ignore duplicates to prevent endless loops.
Hop count limiting
Each message has a hop counter that starts at 0 and increases with each hop. After the maximum number of hops (default 3) the message is no longer forwarded.
Signal strength evaluation
Nodes evaluate the signal strength (RSSI) of incoming messages. Weak signals are forwarded with lower priority to improve network efficiency.
How flooding routing works
The flooding algorithm is the core of MeshCore routing. Here's how it works step by step:
Step 1: Message is sent
Node A sends a message. The message gets a unique ID and the hop counter is set to 0. The message is broadcast to all nodes within radio range.
Step 2: First hop - neighbors receive
Nodes B, C and D receive the message. They check: "Have I seen this message before?" If yes โ ignore. If no โ save in recent messages cache and forward. Hop counter is increased to 1.
Step 3: Second hop - further distribution
Nodes E, F, G receive the message from B, C, D. They perform the same check. Some nodes may receive duplicates from different neighbors - these are ignored. Hop counter becomes 2.
Step 4: Destination reached or max hops
If the target node receives the message, it sends an ACK back (optional). If the hop counter reaches the maximum value (default 3), nodes stop forwarding.
Flooding optimizations
To prevent network overload, MeshCore uses these optimizations:
- โข <strong>Message deduplication:</strong> Messages that have already been seen are not forwarded again, even if they arrive via a different route.
- โข <strong>Implicit ACK:</strong> If a node hears that its neighbor has forwarded the message, it knows the transmission was successful.
- โข <strong>Random delay:</strong> Nodes wait a short, random time before forwarding to prevent collision storms.
- โข <strong>RSSI-based prioritization:</strong> Nodes with stronger signal get priority when forwarding.
Hop limiting mechanism
Default hops
Default maximum hops in MeshCore configuration. Suitable for local networks within 3-5 km range.
Maximum hops
Maximum configurable hops. More hops = greater range but higher latency and more network traffic.
Range per hop
Average range per hop in urban area (1km) times 3 hops = total range approximately 3 km.
How hop counting works
Each packet contains a hop_limit field in the header. Each node that forwards the packet increases the hop counter by 1:
Message sent: hop_count = 0 First relay: hop_count = 1 Second relay: hop_count = 2 Third relay: hop_count = 3 โ Max reached, stop forwarding
This prevents messages from circulating endlessly in the network and saves valuable battery energy and airtime.
Advantages of MeshCore routing
Self-organizing
No configuration needed. Nodes automatically find the best routes without central control.
Energy-efficient
Smart optimizations ensure only necessary nodes forward messages, saving battery.
Robust against failure
If one route fails, messages automatically find an alternative path through the network.
Scalable range
By adding more nodes the range grows exponentially without additional configuration.
Simple protocol
The flooding-based protocol is simple to implement and debug compared to complex routing tables.
No single point of failure
No central router means there is no single point that can crash the entire network.
Routing configuration examples
You can adjust routing behavior via the MeshCore CLI or Python API:
CLI: Set hop limit
Increase hop limit for greater range (note: more battery consumption and latency):
meshcore --set router.hop_limit 5 meshcore --set router.rebroadcast_mode ALL_SKIP_DECODING
Python API: Routing configuration
Configure routing via Python for automated deployments:
import meshcore
interface = meshcore.SerialInterface()
node = interface.getNode("^local")
# Set routing parameters
node.router.hop_limit = 4
node.router.rebroadcast_mode = meshcore.Router.ALL_SKIP_DECODING
node.writeConfig()
Advanced: RSSI threshold
Set a minimum RSSI for rebroadcasting to ignore weak links:
meshcore --set router.rebroadcast_min_rssi -120 # -120 dBm = very weak signal # -100 dBm = average signal (recommended) # -80 dBm = strong signal
Frequently asked questions about routing
Why does MeshCore use flooding and not table-based routing?
Flooding is much simpler and more robust in mobile networks where nodes constantly turn on and off. Table-based routing requires route discovery and maintenance of routing tables, which is complex and energy-intensive for LoRa devices.
What happens if two nodes forward a message simultaneously?
MeshCore uses random backoff delays to minimize collisions. If a collision does occur, other nodes in the network will successfully forward the message thanks to the flooding principle.
Can I set different hop limits per message type?
Yes, in the routing configuration you can set different hop limits for position updates, text messages and telemetry. This optimizes your network traffic per message type.
How does MeshCore prevent route loops?
Through a combination of hop limiting and message deduplication. Each node remembers recent message IDs and does not forward duplicates, even if they arrive via a different route.
What is the latency with 3 hops?
Each hop takes approximately 1-3 seconds depending on spreading factor and message size. With 3 hops, end-to-end delivery takes approximately 3-10 seconds.
Can I disable routing for my node?
Yes, you can disable routing by setting rebroadcast_mode to "NONE". Your node will still receive messages but will not forward them. This is useful for mobile devices to save battery.
Start with MeshCore routing development
The MeshCore routing algorithm provides a robust, energy-efficient way to route messages without central infrastructure. Perfect for emergency communication and off-grid networks.