MQTT over RS485

From Heatweb Wiki
Jump to: navigation, search

Requirements

  • Make use of standard MQTT topic, value, and QoS structure
  • Miltidrop serial over RS485
  • No master required


Message structure

MQTT

topic = network1/node2/device3/catagory4/key5
value = value
QoS = 0, 1 or 2

MQTT Serial Structure

&network1/node2/device3/catagory4/key6=value (+newline \n)


Mixed:

&network1/node2/device3/catagory4/key6=value1&/key7=value2&catagory5/key8=value3\n


With Timestamp:

&u=52357533&network1/node2/device3/catagory4/key6=value\n
&u=52357533&network1/node2/device3/catagory4/key6=value&u=52357544&key6=value2\n

With Checksum:

&network1/node2/device3/catagory4/key6=value&c=235\n

Subscribe request, single reading:

&s=network1/node2/device3/catagory4/key6\n

Subscribe request, updates when reading varies by more than 0.5 since last post, at least every hour:

&s=network1/node2/device3/catagory4/key6&v=0.5&t=3600\n

Subscribe request, with alias:

&s=network1/node2/device3/catagory4/key6&v=0.5&t=3600&a=device3/key6\n

With wildcards (from every device).

&s=+/+/+/+/key6&v=0.5&t=3600\n
&s=+/+/device3/#&v=0.5&t=3600\n


Message Queueing

Communication is at Node level.

Each node stores list of other nodes.

Queue order is last message age descending, based on an integer ticket derived from unix timestamp.

Each node stores message tickets going back 1000 max typically, as well as its own previous tickets.

A post contains the next ticket on the list, been the oldest on its list. The owner of that ticket then follows.

New Ticket, [Post], Next Ticket

Once post is made a node defers to the next oldest node on the list. This way each node is given equal share, and there is no need to delay between messages, with a clear order to follow in a loop. If a system is missed on one list it will turn on another, so registering a new device on a single existing device will pull newcomer into message loop.

No system sends until it is called to. The act of subscribing adds new entries to the lists, and places them at the oldest (first in queue) system.

If a system does not respond for more than 3 seconds then next on list is called for by the previous poster. Before long the problem unit will drop off all lists.

While a master is not required, initiation of communications loop is required, as well as registering new nodes.

If a node is called a second time within 1 seconds it will pause.

Every minute, a node will post a delay post, and delay 1s to allow broadcast from new nodes. A random delay on new node response reduces collisions.