Giter Site home page Giter Site logo

gobroker's Introduction

gobroker

This repository contains a broker of Message Queuing Telemetry over SSL/TLS made in go

MqTLS

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.

Is it the same as MQTT?

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:

  1. All data is encoded using utf-8 (including lengths of fields and the actions)
  2. Data has a maximum of 99 characters
  3. Both ip and port are stored in the server for client check (asigned when login)
  4. All messages are retained
  5. All messages should end with '\n'
  6. 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)
  7. Lengths are defined by the digits, not the bytes
  8. Because of performance reasons, all communications are QoS 0. Only the connect, retrieve and last-will packets should expect response.

The structure

Connect packet: → MQS004user08password15\n ←

MQS → Protocol name
0 → 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 name
0 → 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 name
3 → 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 name
1 → 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 name
2 → 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 name
2 → 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 name
4 → 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 name
5 → 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.

Use cases for development of lemonSW:

///// 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

gobroker's People

Contributors

efrenbg1 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.