This repository contains a broker of Message Queuing Telemetry over SSL/TLS made in go
While the MQTT protocol performs very well under networks with limited bandwidth, the support of MQTT under TLS on microcontrollers is very limited. The very popular ESP8266 does not have hardware support for TLS which means that it must be emulated via software. Having then an even simpler subscribe-publish protocol allows to implement telemetry securely on this board. In MqTLS publish packets have payload length from 12 to 208 bytes. This can be shortened even more, but to make implementations as easy as possible the protocolo has some overhead by encoding integers in utf-8.
The protocol is not the same, and is not intended to be compatible. Its nature derives from a combination of both MQTT and the readable nature of HTTP. This means that newer servers and clients will have to be developed.
Some properties:
- All data is encoded using utf-8 (including lengths of fields and the actions)
- Data has a maximum of 99 characters
- Both ip and port are stored in the server for client check (asigned when login)
- All messages are retained
- All messages should end with '\n'
- Instead of subscribe with callbacks, the action is called watch, which any change made to a topic and its slots will send a messge back to all watchers (max. 5 per topic)
- Lengths are defined by the digits, not the bytes
- Because of performance reasons, all communications are QoS 0. Only the connect, retrieve and last-will packets should expect response.
Connect packet: → MQS004user08password15\n ←
MQS → Protocol name0 → Action type, authetificate in this case
04 → length of user field
user → utf-8 encoded string
08 → length of password field
password → utf-8 endoded string
15 → time to keep the connection live in seconds (if not specified default is 10s, maximum is 99s)
Connect packet response: → MQS0\n ←
MQS → Protocol name0 → Action type (expected the same as the sent packet) if equals 9 then then the action failed
Last-will packet: → MQS317/home/temperature303Off\n ←
MQS → Protocol name3 → Action type, last-will in this case
17 → length of topic field
/home/temperature → utf-8 encoded string for topic
3 → utf-8 encoded single digit integer to represent which slot to use in the topic (each topic has 10 slots)
03 → length of data field
Off → utf-8 endoded string for data
Publish packet: → MQS117/home/temperature10416ºC\n ←
MQS → Protocol name1 → Action type, publish in this case
17 → length of topic field
/home/temperature → utf-8 encoded string for topic
1 → utf-8 encoded single digit integer to represent which slot to use in the topic (each topic has 10 slots)
04 → length of data field
16ºC → utf-8 endoded string for data
Retrieve packet: → MQS217/home/temperature2\n ←
MQS → Protocol name2 → Action type, retrieve in this case
17 → length of topic field
/home/temperature → utf-8 encoded string for topic
2 → utf-8 encoded single digit integer to represent which slot to use in the topic (each topic has 10 slots)
Retrieve packet response: → MQS20416ºC\n ←
MQS → Protocol name2 → Action type, retrieve in this case
04 → length of payload field
16ºC → utf-8 encoded string for the payload
Watch packet: → MQS417/home/temperature\n ←
MQS → Protocol name4 → Action type: watch
17 → length of topic field
/home/temperature → utf-8 encoded string for the topic
Watch on update response packet: → MQS517/home/temperature00416ºC\n ←
MQS → Protocol name5 → Action type: watch update
17 → length of topic field
/home/temperature → utf-8 encoded string for the topic
0 → utf-8 encoded single digit integer to represent which slot has been updated
04 → length of payload field
16ºC → utf-8 encoded string for the payload
There are many more things, but as I'm the only currently using it I will leave the README as is.
///// topic = BC:DD:C2:08:8C:BE ///// (only MAC) (status topic)
0 -> PC off
1 -> PC on
2 -> PC suspended
3-6 -> not used
7 -> Board is updating
8 -> Board is in recovery mode
9 -> Board is off
///// topic = BC:DD:C2:08:8C:BE ///// ("" + MAC) (actions topic)
0 -> Simple power button click (to turn off or on)
1 -> Force off (holds button for 5s)
2 -> Reset PC (actions 1 and 0 combined)
3-5 -> not used
4 -> Turning off
5 -> Action failed
6 -> Performed action (default status, waiting for command or cancel action)
7 -> Update
8 -> Enter recovery mode
9 -> Update settings
///// topic = !BC:DD:C2:08:8C:BE ///// ("!" + MAC) (settings topic)
off1640on0915 -> Turn off at 16:40, turn on at 09:15