Three Realtime IoT Protocols (HTTP, MQTT, WebSockets)

@ChrisMatthieu
3 min readJan 1, 2014

SKYNET.im is a realtime IoT network and API making it easy to connect devices to the Internet of Things and facilitating machine-to-machine instant messaging. From day 1, SkyNet supported an HTTP REST API and a realtime WebSocket API complimented by a Node.JS NPM module appropriately named SkyNet too. A couple of weeks ago, we released a client-side HTML/JavaScript library called skynet.js making it easy for all clients and applications to communicate with hardware seemlessly.

We are proud to announce that we have added MQTT support to the SkyNet platform! Not only did we just “add” MQTT support but we fully integrated it into our REST API, WebSocket API, Node.JS NPM module, and SkyNet.JS client-side library!

MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.

MQTT defines three levels of Quality of Service (QoS). The QoS defines how hard the broker/client will try to ensure that a message is received. Messages may be sent at any QoS level, and clients may attempt to subscribe to topics at any QoS level. This means that the client chooses the maximum QoS it will receive. For example, if a message is published at QoS 2 and a client is subscribed with QoS 0, the message will be delivered to that client with QoS 0. If a second client is also subscribed to the same topic, but with QoS 2, then it will receive the same message but with QoS 2. For a second example, if a client is subscribed with QoS 2 and a message is published on QoS 0, the client will receive it on QoS 0.

Higher levels of QoS are more reliable, but involve higher latency and have higher bandwidth requirements.

0: The broker/client will deliver the message once, with no confirmation.

1: The broker/client will deliver the message at least once, with confirmation required.

2: The broker/client will deliver the message exactly once by using a four step handshake.

SkyNet’s MQTT support is provided by Matteo Collina’s opensource Node.JS-powered Mosca MQTT Broker. Mosca currently only supports QoS levels 0 & 1 but level 2 is on the roadmap!

Adding MQTT support to your existing SkyNet-powered IoT app/device is as simple as adding QoS to your NPM configuration. Here’s a quick Node.JS code example:

var skynet = require(‘skynet’);
var conn = skynet.createConnection({ “uuid”: “1234567890", “token”: “1234567890", “qos”: 0
});

conn.on(‘notReady’, function(data){ console.log(‘UUID FAILED AUTHENTICATION!’);
});

conn.on(‘ready’, function(data){ console.log(‘UUID AUTHENTICATED!’); conn.message({ “devices”: “*”, “message”: { “hello”:”world” }, “qos”: 0 });

conn.on(‘message’, function(channel, message){ console.log(‘message received’, channel, message); });

});

Our goal is to make your next Internet of Things development and deployment effort super simple and super scalable. Let us know how we can help you connect the dots and hack the planet!

--

--

@ChrisMatthieu

Builder of companies, robots, supercomputers, & motorcycles. @xrpanet & @twelephone CEO. Formerly @magicleap @computesio @citrix @octoblu @nodester @teleku