25
Westminster Impact Hub London, UK. 29/5/2015 Hack Risk Allianz Hackathon Getting started with the Internet of Things Tom Collins @snillocmot [email protected]

Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/5/15 #IoT

Embed Size (px)

Citation preview

Page 1: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Westminster Impact HubLondon, UK. 29/5/2015

Hack Risk Allianz Hackathon

Getting started with the Internet of Things

Tom Collins@snillocmot

[email protected]

Page 2: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

What is IoT?

An extension of the traditional web

providing intelligent features

through embedded computing,

which allows dumb objects

to autonomously react, inform and learn

from the context of Humans and Things

Tom Collins@snillocmot

[email protected]

Page 3: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

How is IoT?

The convergence of

cheaper and accessible

cloud, network and processing power,

with smaller and smarter computers

and a variety of hardware I/O sources

Tom Collins@snillocmot

[email protected]

Page 4: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Where is IoT?

Page 5: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Where is IoT?

Page 6: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Where is IoT?

Page 7: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

By 2020...$7.1 trillion market value

50 billion connected devices

30 million every day

1 in 3 ‘knowledge workers’ will be

replaced by a digital workforce and smart machines

Page 8: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Why IoT?

To improve quality of life and drive new business

through connecting physical, cyber and social domains

Page 9: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT
Page 10: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Connected devices

Page 11: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Problems

● Millions of apps● Still stuck in remote control mode● Siloed solutions (An API doesn’t make it IoT)● Big innovation captures the consumers eye,

but not enough immediate ROI for business to adopt

Page 12: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

SmartLivingIoT Starter KitA Computer (Arduino Ethernet, Intel Edison or Raspberry PI) & Grove shield

A bunch of sensors and actuators● Button● Blue LED (5mm)● Rotary Angle Sensor (P)● Light Sensor (P)● Vibration Motor● Temperature Sensor● Infrared receiver● Infrared emitter● LED Bar● PIR Motion sensor

Check out the kits athttp://www.smartliving.io/kits

Page 13: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

ExamplesTCP/IP, MQTT, IPv6, CoAP, REST, XBEE, ZigBee, ZWave, Serial, custom radios, IPoAC, etc

CONNECTIVITY

LandscapeEND POINTS

aka ThingsMIDDLEWARE

routergateways

fog servicescloud bridges

brokers

ExamplesOpenHAB, TheThingSystem, ZIPR, Dowse, Ponte, WebSphere, RabbitMQ, Dweet

IOT SERVICES

SmartLivingIFTTTXively

TempoIQInitialStateWaylay.io

Millions of other single use services...

ExamplesPersistence, (E.g TempoIQ), automation (E.g IFTTT), intelligence, third party integrators (ERP connectors)

APPS

Companion appsWidgiots

FreeboardNode redWyliodrin

ExamplesWidgIoTs, SmartLiving Web & Mobile Apps, FreeboardCustom RF

Page 14: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

END POINTSaka Things

CONNECTIVITY MIDDLEWARE IOT SERVICES APPS

LED

POTArduino DBBroker Manage

WidgetRules

Blinking IoT Led

TrustyEthernet cable

Potentiometer Sensor CodeDevice.Send(String(potRead), pot); //Reads and sends pot

LED Actuator codeif (command == "false") { digitalWrite(led, LOW); //Turns LED off } else if (command == "true") { digitalWrite(led, HIGH); //Turns LED on}

SmartLiving API’shttpServer = "api.smartliving.io"; mqttServer = "broker.smartliving.io";

Automation RuleWhen

Arduino.pot > 500Then

Arduino.led = trueElse

Arduino.led = false

Page 15: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

SmartLiving ToolboxEND POINTS CONNECTIVITY MIDDLEWARE IOT SERVICES APPS

ArduinoRaspberry

Pi

Android Makers

App

Virtual actuator

Virtual sensors

iOS App

Web app WidgetsZWave Devices

Solu

tio

nsD

ev T

oo

ls

C Lib

Android Gateway

Arduino Gateway

PUBSUB Clients

REST Clients

Raspberry Pi Makers Gateway

Management

Telemetry DB

Rule Engine

Automation Scripting

Rule Wizard

SERIALTCP/IP

ZWAVE

XBEE

Python Lib

JS Lib

WidgetLib

Node.js Lib

Go Lib

433 Mhz

IR!!?

Polymer Widgets

Web Services

ZigBee

Custom microcont

rollers

Java Lib

Plenty of existing

resources here

SmartLiving pub:sub Broker

ZWave IPv6

Gateway

Page 16: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Library & API’S

Endpoints (Hardware and libs)

● Arduino/C● Python● Node.js● C#● Javascript (HTML5-browser-as-a-sensor)

Middleware

● Python Gateway● C++ Gateway● XBee Gateway

IOT Services

● REST API - Gateway, Device, Asset, Rules,

Users ● Telemetry API - Sensor data, actuator

commands

● Automation rules, scripting & API

Apps

● Javascript Widgets

Page 17: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Arduino - setupvoid setup(){ pinMode(ledPin, OUTPUT); // initialize the digital pin as an output. Serial.begin(9600); // init serial link for debugging byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0xE1, 0x3E}; // Adapt to your Arduino MAC Address

if (Ethernet.begin(mac) == 0) // Initialize the Ethernet connection: { Serial.println(F("DHCP failed,end")); while(true); //we failed to connect, halt execution here. }

delay(1000); //give the Ethernet shield a second to initialize: if(Device.Connect(&ethClient, httpServer)) //connect the device with the IOT platform. {

Device.AddAsset(knobPin, "Potentiometer", "A rotary sensor pot",false, "int"); //pin, name, desc, assetType, dataPro

Device.AddAsset(ledPin, "LED", "A blinky light emitting diode", true, "bool"); //pin, name, desc, assetType, dataPro

Device.Subscribe(pubSub); } }

Page 18: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Arduino - sensor read loopvoid loop(){ unsigned long curTime = millis(); if (curTime > (time + 1000)) // publish light reading every 5 seconds to sensor 1 { unsigned int lightRead = analogRead(knobPin); // read from light sensor (photocell) if(prevVal != lightRead){

Device.Send(String(lightRead), knobPin); prevVal = lightRead;

} time = curTime; } Device.Process(); }

Page 19: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Arduino - actuator callbackvoid callback(char* topic, byte* payload, unsigned int length) { String msgString; {

char message_buff[length + 1];strncpy(message_buff, (char*)payload, length);message_buff[length] = '\0';

msgString = String(message_buff); } int* idOut = NULL; { int pinNr = Device.GetPinNr(topic, strlen(topic)); //Find what topic hooks to the pin

if (pinNr == ledPin) { if (msgString == "false") { digitalWrite(ledPin, LOW); //led off idOut = &ledPin; } else if (msgString == "true") { digitalWrite(ledPin, HIGH); //led on idOut = &ledPin; } } } Device.Send(msgString, *idOut); //Acknowledges the LED was activated and confirm in the user interface}

Page 20: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Python Pi - Summary

IOT.connect()IOT.addAsset(knobPin, sensorName, "Push button", False, "int")IOT.addAsset(ledPin, actuatorName, "Light Emitting Diode", True, "bool")IOT.subscribe()

while True: try: if grovepi.digitalRead(sensorPin) == 1: if sensorPrev == False: IOT.send("true", sensorPin) sensorPrev = True elif sensorPrev == True: IOT.send("false", sensorPin) sensorPrev = False sleep(.3)

Page 21: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Node.js - Summaryvar a0 = new mraa.Aio(0); //setup access analog input Analog pin #0 (A0)var d8 = new mraa.Gpio(8); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)d8.dir(mraa.DIR_OUT); //set the gpio direction to output

smartliving.addAsset("2", "Missile launcher", "Fires 10xD missiles at incoming spacecraft, and also a neat LED for some visual feedback...", true, "bool", confirmEnroll());smartliving.addAsset("3", "Thermoreactor turbine temperature ", "Monitors the temperature of main alpha turbine", false, "int", confirmEnroll());

smartliving.subscribe(smartliving.baseMQTTUrl, 1883);

vloop();

function vloop(){ var analogValue = a0.read(); //read the value of the analog pin

smartliving.send(analogValue, "3") setTimeout(vloop,1000);}

smartliving.registerActuatorCallback("2", function() { d8.write(ledState?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low) ledState = !ledState; //invert the ledState});

Page 22: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Rules

FYI● Rule wizard doesn’t support complex operators like &&, ||● Create a script and run it in the cloud if you need crazy logic

Page 23: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Hackathon Ethos

Fake it, until you make it (literally)

● Hackathons always have network issues

● Hardware is normally limited or even shared

● Mock data is easy● Things always go wrong● Fancy UI elements always look

good

KISS, Hardware is Hard, Retrofit

● Nest is just a potentiometer, temp, PIR sensor

● GNL is just a LED & Push Button● Hue is just a RGB● Wemo is just a Relay

MVP Mentality

● Build small think big (What’s the story behind your use case)

● High impact features first

Page 24: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

Brainstorming IoT

The problem - Short sharp sentence describing the story of your problem and how the solution solves it

Topology diagram - Visualise what you’re going to build, show the inputs and outputs and use it to explain your idea

THINGS - What are the dumb objects?

END POINTS - What computers and sensors are need to make things smarter?

DATA MODEL - What type of data will the Things produce? What are the inputs/outputs?

MIDDLEWARE - How will devices communicate? one-one, one-many?

AUTOMATION - When this event happens then do this event?

UI - Mockups and wireframes

HUMANS - Who are the most important people using the solution?

Page 25: Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/5/15 #IoT

ResourcesGet your SmartLiving IoT Starter Kit

www.smartliving.io/kits

The platform

beta.smartliving.io

Documentation

http://docs.smartliving.io/Get_Started

GitHub

https://github.com/allthingstalk

API Reference

http://allthingstalk.github.io/api-docs