Have you ever wondered how to interconnect your apps with physical things? Have you ever felt that the request/response pattern of HTTP is not enough? What about a binary protocol? In this talk you will discover the internal of the open source QEST broker, a Node.js-based broker for the Internet of Things that implements a classic publish/subscribe pattern, while making it accessible from HTTP and MQTT, an ultra-fast binary protocol.
15. We can supercharge our house with hubot
How
module.exports = (robot) ->
robot.respond /what’s the temperature?/i, (msg) ->
msg.http("http://mchouse.it/temperature")
.header("Accept", "application/json")
.get() (err, res, body) ->
msg.send JSON.parse(body)
16. In order to ask our temp
to hubot, we need to:
1. sense the temp
2. get the temp on the web
3. build a web API
17. We are building an API
In Italy,
“API” means
“bees”
http://www.flickr.com/photos/theseanster93/4056815767
22. HTTP is slow and safe
http://www.flickr.com/photos/clearlyambiguous/48185613/
23. We need a
fast, binary
protocol
http://www.flickr.com/photos/grrphoto/305649629
24. M2M protocols are “Things” should interact
mostly ad-hoc, and with our lives, and all the
researchers and technology should be
businesses focus on low built to make them easy
level problems. to use.
25. • “things” exposed • “things” exposed
with binary protocol to the web
• publish/subscribe • request/response
• topics as the naming • URIs as the
system naming system
27. HTTP Clients MQTT Clients
QEST
REST Server MQTT Server
• MQTT broker
QEST
• REST interface
• HTTP semantics Data Layer
• no QoS
• built on node.js
and redis Redis
28. state-of-art
state-of-art QEST-based QEST-based
approach to IoT apps IoT apps
approach to solution to IoT apps
solution to IoT apps
Web App Web App
Web App
Bridge
Web App
QEST
Bridge
QEST
IoT
Broker Device
IoT
Device
3 2 1 0 9 8 7 6 5 4 3 2 1 0
GND
SCL
AREF
SDA
1 1 1 1 DIGITAL
RX
TX
PWM
PWM
PWM
PWM
PWM
PWM
L
TX
Arduino UNO ON
Broker
RX
1
ICSP
www.arduino.cc
RESET
IOREF
POWER ANALOG IN
3V3
5V Gnd Vin 0 1 2 3 4 5
Device
3 2 1 0 9 8 7 6 5 4 3 2 1 0
GND
SCL
AREF
SDA
1 1 1 1 DIGITAL
RX
TX
PWM
PWM
PWM
PWM
PWM
PWM
L
TX
RX
Arduino UNO ON
1
ICSP
www.arduino.cc
RESET
IOREF
POWER ANALOG IN
3V3
5V Gnd Vin 0 1 2 3 4 5
Device
29. QEST : MQTT to REST
• retains every message received
client = PubSubClient(server, 1883, callback);
client.publish("temp", "30");
• every topic has its own URI: /topics/<NAME>
curl -H "Accept: txt" http://qest.me/topics/temp
30. QEST : REST to MQTT
• transform every HTTP PUT received to a MQTT message
curl -X PUT -d '{ "payload": 42 }'
-H "Content-Type: application/json"
http://qest.me/topics/temp
• devices can listen directly to MQTT topics
void callback(char* topic, byte*
payload, int length) {
...
}
PubSubClient(server, 1883, callback);
client.subscribe("temp");
31. HTTP/MQTT Clients
How to Load Balancer
scale
REST Server MQTT Server REST Server MQTT Server
QEST
Data Layer
... QEST
Data Layer
Redis
47. ActiveRecord
1. Best pattern for storing data
2. Its main responsibilities are
CRUD operations
3. I used that pattern to build a
cross-process pub/sub
system
51. ir
to
lta • Redis
co
is a multi- • ZeroMQ
process pub/sub
As
library backed by
• RabbitMQ
• MQTT
(Mosquitto)
• Memory
(EventEmitter)
52. r i
to
lta
co
var
ascoltatori
=
require('ascoltatori');
//
you
can
use
RedisAscoltatore,
ZeromqAscoltatore,
As
//
RabbitAscoltatore,
MQTTAscoltatore
var
ascoltatore
=
new
ascoltatori.MemoryAscoltatore();
ascoltatore.subscribe("hello/*",
function()
{
//
this
will
print
{
'0':
"hello/42",
'1':
"a
message"
}
console.log(arguments);
process.exit(0);
});
ascoltatore.publish("hello/42",
"a
message",
function()
{
console.log("message
published");
});
53. Memory Redis ZeroMQ RabbitMQ Mosquitto
r i
to
lta
100.000 us
co
10.000 us
As
1.000 us
100 us
10 us
1 us
1 10 100 1000
Listeners
54. i r
to
lta
co
allowed me to
As
refactor QEST as
just an MQTT
wrapper!
55. ut ing
s
rib ek
or
nt se
co m
Ia
github.com/mcollina/qest
github.com/mcollina/ascoltatori