Politecnico di Milano Advanced Network Technologies Laboratory IoT Software Platforms in the cloud 1
Why the cloud? o IoT is about DATA sensed and transmitted from OBJECTS o How much data? n IPV6 covers every atom on 100+ earths n Recent estimates: 4.4 zettabytes (10^21B) of IoT data produced by 2020 n That s 1 stack of 128 GB Ipad Air reaching the moon! o How to manage it? Go to the cloud with an IoT platform!
IoT platforms o The term platform can refer to: n Hardware architectures (ARM, Arduino,etc ) n Software frameworks to program smart things n Cloud-based middleware platforms to manage IoT data and devices o We will focus on the last point 3
IoT platforms o IoT platforms world is growing fast n 70+ platforms available online (+40% w.r.t 2014) o They are getting more and more mature and stable n Not only startups, also big players (Microsoft, IBM) o Key value proposition n reduce costs and time-to-market for IoT solution, reduce management complexity o But: a lot of confusion for users! 4
Solutions o Old Giants n IBM: Bluemix IoT Cloud, Node-RED n Microsoft: Azure IoT Suite n Amazon: AWS IoT n Google: Cloud IoT + Brillo n Intel: IoT platform o Startups n Xively, Thingspeak, FreeBoard, ThingWorx.
Desired features o Device management n Connect devices to the cloud, configure devices, update firmware, monitor devices o Data management n Store and retrieve data, manage events, visualize and share data o Data analysis / automation n Statistical analysis, data mining, machine learning, etc o Security
Two types of platforms Specialized platforms: only one feature is implemented Generalized platforms: many features are implemented Security Data Analytics & BI Automation Security Data management Data Analytics & BI Data management Device management Automation Device management
Specialized platforms o May be difficult to link to a particular feature n E.g. Device Management can be very specific (depending on the device) o Security (device&data) is growing importance 8
Generalized platforms o Two main approaches n Native IoT platforms: former specialized platforms that evolved with the addition of new features (e.g., data management) n Cloud-based IoT platforms: traditional cloudbased solutions that evolved with specialized features (e.g., device management) for the IoT o Strengths: n Excellent data management and interface with corporate IT solutions 9
How to choose? o Specialized n Connectivity management n Device configuration n OtA firmware update o Generalized n Data mining & machine learning n Data fusion n Event processing n Rules engine o It depends on the particular IoT application! 10
Distinctive Features o Device SDK: n Firmware programming, API documentation o Cloud SDK: n API n Graphic programming tools (Node-RED) n Built-in functional blocks o General features n Language agnosticity (C, Java, Python) n Communities (Arduino, mbed, launchpad) 11
Easy development 12
Easy development o Built-in and custom functions eactive Blocks Node-Red 13
Communities o Speed-up learning processes 14
Dashboard DIY freeboard DGLux Azure BI Cumulocity 15
Summary o Many IoT platforms available o Both startups and big IT players o Different solutions / services for different users o In general, quite a complex scenario 16
Practical examples: ThingSpeak and Node-RED 17
ThingSpeak 18
ThingSpeak o An IoT cloud platform for: n Real-time data collection and storage n Data analytics and visualization (integrated with MATLAB) n Alerts and Scheduling n Device Communication, Open API 19
ThingSpeak features projects o Car Counter n Keeping track of cars in a busy highway to analyze traffic patterns o Weather Station n Arduino-based to collect, store and analyze weather data o Tide Level Alerts n Real-time tide predictions and water levels monitoring
ThingSpeak channels o ThingSpeak uses channels to store data sent from devices or apps o Basic operation n Create / list / view / update / delete o Channel settings n ID, name, description n Up to 8 fields (datastreams) n Public / private n Location, Metadata, etc 21
Operating on a channel o Operations can be done from the web interface or through the REST API: n Send an HTTP POST to: https://api.thingspeak.com/channels n With parameters o api_key=xxxxxxxxxxxxxxx o name=my New Channel 22
API Key o When performing an operation, your API key is required o Keys can be regenerated if the user feels that they are compromised 23
Channel fields o Each channel supports up to 8 fields o Each field represents an individual sensor stream and is associated to a chart n e.g., temperature, humidity, number of parked cars, etc o Field/Chart parameters: n Title, xaxis, yaxis, appearance, etc 24
Channel field update o Like channels, fields can be updated via HTTP requests: n POST version o POST https://api.thingspeak.com/update.json api_key=xxxxxxxxxxx field1=73 n GET version o GET https://api.thingspeak.com/update? api_key=api_key&field1=73 25
Practical exercise o Starts the IOT Virtual Machine (pwd: user) o Create an account on ThingSpeak o Create a channel called Test with only one field called Random value (we ll use it later) 26
Node-RED 27
Node-RED o Visual tool for wiring the Internet of Things o Can be run on a variety of platforms: n Edge devices: Raspberry PI, BeagleBone black n Cloud: IBM Bluemix, Amazon AWS, Azure o The user creates flows by wiring together different nodes: n I/O (serial port, tcp sockets, http, mqtt, files) n Functions (built in or custom JS functions) n Advanced (execute programs, post a tweet) 28
The Hello World flow o Open a terminal and type node-red o Open the browser and go to localhost:1880 o The node-red console appears 29
The Hello World flow o Insert an inject node, a function node and a debug node. Wire them together. o Modify the function block as it follows msg.payload = "Hello World!"; return msg; o Click on Deploy and then on the inject button 30
A working example o Let s create a flow in Node-RED that: n Generates random data periodically n Upload the random data on the ThingSpeak channel created before o We need: n Inject node n Function node n HTTP request function node n Debug node 31
Random data generation o Modify the function block as it follows var API_KEY = YOUR_API_KEY ; var data = Math.random()*10; msg.url = "https://api.thingspeak.com/update?api_key=" + API_KEY + "&field1=" + data; return msg; o Modify the inject block to run periodically every 10 seconds o What happens on your ThingSpeak page? 32
Processing Data o Create another flow in Node-Red o Import the node-red-alert_template flow o Modify the CreateHttpRequest block to read the last 10 values from your ThingSpeak feed! o Modify the ComputeAverage block to compute the average of the 10 samples. Send an alert email if the average is greater than a fixed threshold. 33