Tools and technology to build own Internet of Things platform. Exaples uses MQTT broker, Node.js publisher and subscribers, Angular realtime application and Arduino Yun pub/sub example.
8. MQTT
โค MQTT is lightweight, secure, battery friendly and machine-to-
machine (M2M) / โInternet of Thingsโ connectivity protocol
โค Publish-subscribed based
โค Designed for connections with remote locations where โsmall
code footprintโ is required and/or network bandwidth is
limited
โค The publish-subscribe messaging pattern requires a message
broker
โค The broker is responsible for distributing messages to
interested clients based on the topic of a message
17. MOSCA
โค Standalone usage
โค Embeddable in your app
โค Authentication API
โค Supports AMQP, Mongo, Redis, and MQTT as pub/sub
backends
โค Needs a DB as LevelDB, Mongo or Redis
โค Support Websockets
โค Fast, 10k+ messages routed per second
โค Scalable, 10k+ concurrent connections
18. MOSCA, MQTT.JS, BROWSER
โค Works on top of WebSockets
โค Node.js excels that ;)
โค MQTT over Websocket is โstandardโ
โค Uses test broker at test.mosca.io
25. BROWSER PUBLISHER
define([
'angular'
], function (angular) {
'use strict';
angular.module('BenfiIoTApp.Controllers.ColorCtrl', [
'BenfiIoTApp.Services.MQTTService'
])
.controller('ColorCtrl', ControllerFn);
ControllerFn.$inject = ['MQTTService'];
function ControllerFn(MQTTService) {
var vm = this;
vm.selectedColor = '#000000';
vm.send = send;
MQTTService.connect(
'ws://YOUR.BROKER:URL'
);
function send() {
MQTTService.publish('color', vm.selectedColor);
}
}
});
26. DEVICE SOFTWARE
โค On your Arduino Yun install packages:
โค opkg update
โค opkg install mosquitto mosquitto-client libmosquitto
27. DEVICE PUB/SUB
#include <MQTTclient.h>
#define MQTT_HOST โYOUR.BROKER.URLโ
void setup() {
Serial.begin(115200);
// remember the bridge!
Bridge.begin();
// begin the client library (initialize host)
mqtt.begin(MQTT_HOST, 1883);
mqtt.subscribe("color", colorEvent);
}
void loop() {
// check for incoming events
mqtt.monitor();
mqtt.publish("sensors/brightness", brightness);
mqtt.publish("sensors/temperature", temperature);
mqtt.publish("sensors/humidity", humidity);
delay(1000);
}
void colorEvent(const String& topic, const String& subtopic, const String& message) {
// hex to rgb
String hexstring = message;
// Get rid of '#' and convert it to integer
long number = strtol( &hexstring[1], NULL, 16);
// Split them up into r, g, b values
long r = number >> 16;
long g = number >> 8 & 0xFF;
long b = number & 0xFF;
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(r,g,b)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
28. WHY CLOUD? WHY AWS? WHAT MAY BE USEFUL?
โค Load balancers
โค Security groups
โค Autoscaling
โค Elastic Beanstalk
โค EC2
โค S3
โค Elasticsearch Service
โค ElasticCache
โค Lambda
โค Kinesis