Addressing, discovery, routing, multi-hop forwarding
The network layer provides:
- node addressing (
NET_ID + NODE_ID) - join/assign/leave discovery
- multi-hop packet forwarding
- two routing modes: distance-vector and gradient
NET_ID (8-bit) identifies the mesh network.
NODE_ID (8-bit) identifies a node inside the network.
Reserved node IDs:
0x00broadcast0x01coordinator0xFEunassigned
UMESH_ROLE_COORDINATORUMESH_ROLE_ROUTERUMESH_ROLE_END_NODEUMESH_ROLE_AUTO(auto election)
UMESH_ROUTING_DISTANCE_VECTOR (default):
- route table per destination
- good for smaller networks and bidirectional traffic
- practical range: up to ~10 nodes
UMESH_ROUTING_GRADIENT:
- each node tracks only one value: hop distance to coordinator
- packets to coordinator move uphill through neighbors with lower distance
- good for many-to-one sensor collection
- practical range: 10-100+ nodes
- Coordinator sends
UMESH_CMD_GRADIENT_BEACONwith payload{distance=0}. - Node receiving beacon with distance
Dcomputes candidateD+1. - If candidate improves local distance, node stores it and rebroadcasts with random jitter
50-200 ms. - If candidate is equal/worse, node updates neighbor info but does not rebroadcast.
- Propagation depth is capped by
UMESH_MAX_HOP_COUNT.
When routing mode is gradient and destination is coordinator:
- choose neighbor with
neighbor_distance < my_distance - prefer lowest neighbor distance
- if tie, prefer better RSSI
- if none exists, return
UMESH_ERR_NOT_ROUTABLE
UMESH_CMD_JOIN(0x50)UMESH_CMD_ASSIGN(0x51)UMESH_CMD_LEAVE(0x52)UMESH_CMD_DISCOVER(0x53)UMESH_CMD_ROUTE_UPDATE(0x54)UMESH_CMD_NODE_JOINED(0x55)UMESH_CMD_NODE_LEFT(0x56)UMESH_CMD_ELECTION(0x57)UMESH_CMD_ELECTION_RESULT(0x58)UMESH_CMD_GRADIENT_BEACON(0x59)UMESH_CMD_GRADIENT_UPDATE(0x5A)UMESH_CMD_POWER_BEACON(0x5B)
UMESH_ROUTE_UPDATE_MS = 30000UMESH_NODE_TIMEOUT_MS = 90000UMESH_DISCOVER_TIMEOUT_MS = 2000UMESH_ELECTION_TIMEOUT_MS = 1000UMESH_GRADIENT_BEACON_MS = 30000UMESH_NEIGHBOR_TIMEOUT_MS = 30000