MQTT

Message Queue for telemetry transport

Created by Disk_91 / @disk_91

You know Facebook Messenger ?

 

Do you know what is hapening when you click on send ?

What are mobile and IoT challenges ?

  • small bandwith networks (3G,Edge,GPRS)
  • not reliable network (tunnel, building)
  • filtering equipements (Nat, firewalls)
  • push notification (incoming messages, config)
  • small and portable (arm, x86, java, C, C#, js)

Why Mqtt is a solution ?


  • Network efficient - 10KB / hour
  • Reliable - Manage QoS
  • Build over TCP
  • Manage publish & subscribe
  • Implemented on every platform and languages

MQTT architecture

One on many Architecture
  • Broker is the central communication point
    • OpenSource server : Mosquitto
    • SaaS server : CloudMqtt.com based on mosquitto
    • Appliances : Datapower message sight to process 13M message / sec
  • Run the server !
    • # ./mosquitto

Client side

  • Client is maintaining open communication with broker
  • Client is publishing messages over topics
  • Client is subscribing to topics
  • Client implementations :
    • Eclipse Paho
      • Java, C, Javascript
    • dotNET, Objective-C, C++
    • Ruby, tcl, perl, rexx, pyhton, php, lua, dart, actionscript
    • Platform - Arduino, mbed, android, raspberry ...

Communication mode


  • One to One
  • One to Many
  • Many to One
  • Many to Many

Client sample code

				
void on_message(struct mosquitto *m, void *user_data, const struct mosquitto_message *msg) {
    fprintf(stderr, "Message from %s is %s\n", msg->topic, (char*)msg->payload);
}

int main(int argc, char **argv) {
    struct mosquitto *client;  int ret;
    mosquitto_lib_init();
    client = mosquitto_new("client-id", true, NULL);
    ret = mosquitto_connect(client, "127.0.0.1", 1883, 60);
    ret = mosquitto_subscribe(client, NULL, "my/topic/to/subscribe", 0);
    mosquitto_message_callback_set(client, on_message);
    while (MOSQ_ERR_SUCCESS == mosquitto_loop(client, -1, 1));
}
				

Let's talk a little bit more about MQTT

 
  • Mqtt has been developped by IBM and Arcom/Eurotech in the late 90's
  • Since 2011 adopted by Eclipse Fundation as part of M2M strategy.
  • Mqtt is now becoming an OASIS standard.

Now take a look to some details

  • Message format
  • Topics
  • QoS
  • Security

Message format

  • Messages are plain text... use what you want!
				
#!/usr/bin/python
import mosquitto
client = mosquitto.Mosquitto("test-client")
client.connect("127.0.0.1")
client.publish("my/topic", "{\"type\":\"integer\",\"value\":\"5\"}", 1)
client.publish("my/topic", "Hello world", 1)
						
  • Maximum message size is 256MB
  • Topics

    • Basically a topic is a queue
    • Tree organization of group of sensors
    • Like house / floor / room / sensor
    • Allows to design filter easily with Wildcard "+" and "#"
    • Anyone can publish in one topic or more
    • Anyone can subscribe to a topic or more

    QoS

    • QoS0 - At most one delivery, message can be lost
    • QoS1 - At least one delivery
    • QoS2 - Exactly one delivery
    • Means MQTT stack manages resubmission regarding QoS

    Security

    • Security is made at topic level - rights & Authentification
    • Level 0 - no security
    • Level 1 - Simple user / password security
    • Level 2 - SLL communication / authentication

    Demo time

    Why choosing MQTT

    Questions

    Made with Slides.com