Skip to content

mesh protocol

Germán Martín edited this page Jan 5, 2017 · 14 revisions

The protocol used by the mesh is JSON based. Here we describe the role and the JSON schema used for the different messages. The messages send between nodes can be subdivided into control messages and user messages. The control messages are send between nodes to exchange information about routing and sync the time between nodes, while the user messages are generated by the user and will send a JSON object either to a single node or broadcast it over the network.

Addresses

Node address is derived from SOFT_AP mac address, actually last 4 bytes of mac address.

Control packages

Control packages are only exchanged between neighbouring nodes and consist of a number of types.

Time sync

Nodes clocks are synchronized so that all them they share the same clock. So, they can run tasks synchronously.

Time in a node is synchronized with its neighbors. When node time is update all its connections but the just adjusted one is marked to be updated. So, mesh time is kept in sync in a few seconds span with a precision of a few milliseconds.

Time sync is started periodically. A random delay is applied to every iteration to avoid time sync collisions, although if happen they are considered and processed accordingly.

Besides this near periodic synchronization, a time sync is started every time a node connects to an AP.

Before starting a sync request, originating node decides if who (its pair or itself) should adapt its clock. Node with fewer connections and subconnections will adopt a new time to get synchronized. In case of an equal number of connections, the node bahabing as an AP will be the time master.

Routing information

Routing information is shared in form of node synchronization messages. Every node inform its neighbors about all other nodes it is connected directly to and all their respective subconnections. In this way every node has a real time picture of the whole mesh and knows which nodes are connected to the mesh. This information is refreshed every 6 seconds.

User packages

User messages can be sent over the network. Two kind of messages are possible.

Single addressed messages

This messages are tagged with origin node address and destination node address.

Broadcast messages

Broadcast nodes are tagged only with origin node address.