MQTT Slides 140524043859 Phpapp01
MQTT Slides 140524043859 Phpapp01
An introduction
Alexandre Moreno
MQ Telemetry Transport
MQTT is a machine-to-machine (M2M)/Internet of
Things connectivity protocol. It was designed as an
extremely lightweight publish/subscribe messaging
transport. It is useful for connections with remote
locations where a small code footprint is required
and/or network bandwidth is at a premium.
http://mqtt.org
buzzwords
Internet of Things
Machine to Machine
Smart Grid
Purpose of MQTT?
Fill the gap between the numerous devices and applications that can
produce data and the wider world of data consumers
Good fit for simple push messaging scenarios
At a glance...
Application-layer protocol
Runs atop TCP
Binary wire-protocol
No message queue albeit the name
Publish/subscribe pattern
Designed for resource-constrained devices
UTF-8 encoded strings (since V3.1)
Payload-agnostic
Keep-Alive timer
QoS
Scalability
“a single 1u-form-factor appliance can handle up to 1
million sensors and 13 million concurrent messages”
link to article
Interoperability
MQTT Interop Testing Day
The goal is to have as many different MQTT client and
server implementations participate in interoperability
testing to validate the implementation of the
upcoming OASIS MQTT standard.
https://wiki.eclipse.org/Paho/MQTT_Interop_Testing_Day
Background
Publish/Subscribe pattern
Publish/Subscribe Messaging
Model
Clients subscribe to topics (SUBSCRIBE)
Messages are published to a specific topic name (PUBLISH)
A broker server handles the routing of messages
Publish/Subscribe Messaging
Model
Pros
Greater network scalability and a more dynamic network topology
Decoupling of applications
Cons
Same security vulnerabilities as Client/Server model
Message broker
Authenticates clients
mosquitto.org
Examples
Mosquitto
C client
#include <stdio.h>
#include <err.h>
#include <mosquitto.h>
void on_message(struct mosquitto *m, void *user_data, const struct mosquitto_message *msg)
{
fprintf(stderr, "lights at %s are %s\n", msg->topic, (char*)msg->payload);
}
mosquitto_lib_init();
#!/usr/bin/env python
import mosquitto
client = mosquitto.Mosquitto()
client.connect("localhost")
client.subscribe("switches/+/status")
client.on_message = on_message
A simple example showing how to subscribe to a topic and define a function to receive the messages.
Eclipse Paho
Project providing open source implementations of C, C++, Java,
JavaScript, Lua and Python client libraries, plus a client view plugin for
Eclipse IDE.
http://www.eclipse.org/paho
Eclipse Paho
JavaScript MQTT client
client = new Messaging.Client( "127.0.0.1", 80, 'clientId' );
};
client.connect({
onSuccess:function() {
client.subscribe( "switches/+/status" );
}
});