v0.1.0 Start document voor MQTT and installatie instructies door HU IICT.
MQTT has become the standard messaging and data exchange protocol for the Internet of Things (IoT). MQTT solves the folowing problem: A sensor can only seldomly send data, because of power-usage (recharge time). If at the moment of transmission there is no client to listen the information is lost. Furthermore, sending the data to multiple clients would cost more power as well. With MQTT protocol in place the the sensor sends its data to an intermediate server (a so called “broker”). That broker than publishes the data to any subscriber that is interested.
MQTT is a lightweight, publish-subscribe, machine to machine network protocol. The letters MQTT do not stand for anything. It is no longer a traditional ‘message que’. It usually runs over a TCP/IP transport protocol.
Data Agnostic – the broker does not need to understand the semantics of the data that it is caching.
Continuous Session Awareness (optional) - a client could provide the broker with his “last will and testament”. That determines what the broker will do after contact with the client is lost. Example: retry to connect for up to 10 more times over a timespan of one hour.
In contrast to many API services you know the client-server architecture is not a request/response model. It ahers a publish/subscribe model resulting in loose coupeling.
Client A opens a topic at a broker. Other clients can subscribe to that topic (fully asynchronously). A broker must always be online.
Methods that work, regardless of the semantics of the data. These 5 simple, pre-implemented methods are all you need to get your MQTT job done!
1) Connect: Connects with the broker 2) Disconnect: Disconnect with the broker 3) Subscribe: Subscribes the client to (a) topic(s) 4) Unsubscribe: Unsubscribes the client from (a) topic(s) 5) Publish: Publishes a message to a topic
Subscriptions are on topics. Hierarchical, separated by “/” (e.g. kitchen/oven/temperature). Wildcards subscribe to whole hierarchies and are not allowed in publishing “+” matches a single level “#” matches multiple levels (0 or more).
The topic kitchen/+/temperature
The topic kitchen/#
Fire and Forget. The broker sends data to subscribers without verifying whether it is received (like UDP). Messages are delivered at least once (like TCP). Messages are delivered exactly once (more strict than TCP) for non-idempotent operations.
QOS downgrading: Both clients can specify the desired QOS. The lowest of both is used.
Messages can be marked retained. All (re-)connecting subscribers receive last retained message.
To retain all messages of a topic, a persistent session must be setup by the client. Persistent session: subscriber gets session-id. After offline->back online it continues, using that session-id.
The broker will then store:
Subscriber will receive the messages upon reconnection. Very suitable for low-power clients. There is no need to (re-)authenticate using a computationally expensive https connection.
A crash or transmission error can create half-open connections. The unctioning end is not aware and wastes resources. The solution for this are the following:
A publisher can set a Last Will & Testament, a predefined payload, sent on a (detected) disconnect, if:
Example of Last will: “Keep sending the data for half an hour”.