industrial automation, communication and data management · prototyping simulation prototype...

Post on 31-Jul-2020

6 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Politecnico di MilanoAdvanced Network Technologies Laboratory

Industrial automation, communication and data management

Hands on activities

□ Edoardo Longo□ DEIB Building 20 - Ground Floor – ANTLab□ IG: @antlabpolimi

□ Email: edoardo.longo@polimi.it□ Phone: 02 2399 9614

□ Giving you an overview on the software used in the IoT community

□ Stimulating your curiosity□ Providing you with basic tools to develop simple

IoT applications□ Classes time is limited -> Play with these tools

on your own!!

Classes Objectives

Politecnico di MilanoAdvanced Network Technologies Laboratory

Internet of ThingsHardware and Sensors

4

’’take all the things in the world and connect them to the internet’’

Things

Hardware

MKR-1000Flash Memory: 256KB

SRAM: 32KBClock Speed: 48MHz

Wi-Fi

RASPBERRY PIFlash Memory: microSD

RAM: 1GBClock Speed: 1.2GHz

(Wi-Fi / Bluetooth) / Eth

MICAZFlash Memory: 128KB

SRAM: 4KBClock Speed: 7 MHz

ZigBee

ARDUINO UNOFlash memory: 32KB

SRAM: 2KBClock Speed: 16MHz

Ethernet

Sensors

□ Temperature□ Proximity□ Gas□ InfraRed□ Chemical□ Smoke□ Motion detector□ Air quality□ …

Communication pattern

Politecnico di MilanoAdvanced Network Technologies Laboratory

IoT Software Platforms…in the cloud

9

□ IoT is about DATA sensed and transmitted from OBJECTS□ How much data?

■ IPV6 covers every atom on 100+ earths■ Recent estimates: 4.4 zettabytes (10^21B) of IoT data

produced by 2020■ That’s 1 stack of 128 GB Ipad Air reaching the moon!

□ How to manage it? Go to the cloud with an IoT platform!

Why the cloud?

□ The term “platform” can refer to:■ Hardware architectures (ARM, Arduino, etc…)■ Software frameworks to program smart things ■ Cloud-based middleware platforms to manage IoT data and

devices

IoT platforms

11

□ IoT platforms world is growing fast■ 100+ platforms available online

□ They are getting more and more mature and stable■ Not only startups, also big players (Microsoft, IBM, AWS)

□ Key value proposition ■ reduce costs and time-to-market for IoT solution, reduce

management complexity□ But: a lot of confusion for users!

IoT platforms

12

IoT platforms

13

□ Old Giants■ IBM: Bluemix IoT Cloud, Node-RED■ Microsoft: Azure IoT Suite + Windows 10 IotCo■ Amazon: AWS IoT■ Google: Cloud IoT + Android Things■ Intel: IoT platform

□ Startups■ Thingspeak, FreeBoard, ThingWorx, Dweet.io….

Solutions

□ Device management ■ Connect devices to the cloud, configure devices, update

firmware, monitor devices…□ Data management

■ Store and retrieve data, manage events, visualize and share data

□ Data analysis / automation■ Statistical analysis, data mining, machine learning, etc…

□ Security

Desired features

Data Analytics &

BI

Device management

Security

Data management

Automation

Specialized platforms:only one feature is

implemented

AutomationDevice

management

Datamanagement

Data Analytics

& BI

Security

Generalized platforms: many features are

implemented

Two types of platforms

How to choose?

□ Specialized■ Connectivity

management■ Device configuration■ OtA firmware update

□ Generalized■ Data mining & machine

learning■ Data fusion■ Event processing■ Rules engine

19

□ It depends on the particular IoT application!

Distinctive Features

20

□ Device SDK:■ Firmware programming, API documentation

□ Cloud SDK:■ API■ Graphic programming tools ■ Built-in functional blocks

□ General features■ Language agnosticity (C, Java, Python)■ Communities (Arduino, mbed, launchpad)

Easy development

21

Easy development

22

□ Built-in and custom functionsReactive Blocks

Node-Red

Communities

23

□ Speed-up learning processes

Dashboard DIY24

DGLux CumulocityAzure BI

freeboard

□ Many IoT platforms available□ Both startups and big IT players□ Different solutions / services for different

users□ In general, it’s quite a complex scenario

Summary

25

Politecnico di MilanoAdvanced Network Technologies Laboratory

Developing IoT applications

26

MBED OS simulator

Development Pipeline

□ Application design□ Prototyping

■ Simulation■ Prototype implementation

□ Production□ Release□ Application maintenance/updates

Development boards

□ IoT devices are mostly microcontrollers (MCU)□ MCU = compact integrated circuit on a single board

■ Processor■ Memory■ Input/output peripherals■ (Serial ports)■ (ADC/DAC)

Simulation

□ Complex and inefficient deploying applications on real HW■ Risk-free environment■ Debugging■ Save money and time■ Visualization■ Handle uncertainty■ Visualization

MBED OS simulator

□ Operating system for ARM microcontrollers□ Simulate 200+ of embedded boards□ Add plenty of sensors to the boards□ C/C++ software platform and tool for creating

microcontroller firmware that runs on IoT devices

MBED OS simulator

Available at:□ Under polimi-protected/eduroam network:

https://tinyurl.com/simulatorpoli

□ Under any other network:https://tinyurl.com/simulatormbed

MBED OS simulator

Code area

Demo list

Debug area

Board & sensors area

MBED Simulator Examples

□ Blink (turn on/off a LED)□ Temperature – Humidity sensors

Send data somewhere

□ Communication protocols■ NFC■ ZigBee■ Bluetooth■ WiFi■ Cellular■ LoRaWan■ NB-IoT■ …

Send data somewhere

□ Application layers protocols■ MQTT■ HTTP RESTful API■ CoAP■ AMQP■ DDS■ XMPP■ …

RESTful API

□ Request –> response fashion□ Based on client-server architecture□ One-to-one communication□ The client requests resources to an online server

■ GET, PUT, POST, DELETE

Query string

Examples:https://api.nasa.gov/planetary/apod?api_key=DEMO_KEYhttps://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=1000&api_key=DEMO_KEY

ThingSpeak

38

ThingSpeak

39

□ An IoT cloud platform for:■ Real-time data collection and storage■ Data analytics and visualization (integrated with MATLAB)■ Alerts and Scheduling■ Device Communication, Open API

ThingSpeak

40

□ Weather Station: https://thingspeak.com/channels/536159■ Arduino-based to collect, store and analyze weather data

□ Tide Level Alerts https://thingspeak.com/channels/50289■ Real-time tide predictions and water levels monitoring

■ My channel: https://bit.ly/2xQdEwx

ThingSpeak features projects

□ ThingSpeak uses channels to store data sent from devices or apps

□ Data stored in channels:■ Create / view / update / delete / import / export

□ Channel settings■ ID, name, description■ Up to 8 fields (datastreams)■ Public / private■ Location, Metadata, etc…

ThingSpeak channels

42

Operating on a channel

43

□ Operations can be done from the web interface or through the REST API

□ Create a channel:■ Send an HTTP POST to:

https://api.thingspeak.com/channels■ With parameters

□ api_key=XXXXXXXXXXXXXXX□ name=My New Channel

API Key

44

□ When performing an operation, your API key is required□ Keys can be regenerated

if the user feels that theyare compromised

Channel fields

45

□ Each channel supports up to 8 fields□ Each field represents an individual sensor stream and is

associated to a chart■ e.g., temperature, humidity, number of parked cars, etc…

□ Field/Chart parameters:■ Title, x axis, y axis, appearance, etc…

Channel field update

46

□ Like channels, fields can be updated via HTTP requests:

https://api.thingspeak.com/update?api_key=XXXXXXXXXX&field1=YY

https://api.thingspeak.com/update?api_key=XXXXXX&field1=YY&field2=ZZ

□ Try it from yourself, copy the GET API request in your browser address bar

From the board to the cloud

□ Let’s insert HTTP requests into our simulated board□ Create a new channel with 2 fields:

■ Temperature■ Humidity

□ Send the data to ThingSpeak every time the temperature or the humidity change

□ CURL: CLI tool for transferring data using HTTP (and many others protocols)

□ Escape “special” characters□ curl

https://api.thingspeak.com/update\?api_key\=YOUR_API_KEY\&field1\=XXXX

Update a channel via Terminal

□ Use python3!

Update a channel (python3)

Node-RED

51

□ Visual tool for wiring the Internet of Things□ Can be run on a variety of platforms:

■ Edge devices: Raspberry PI, BeagleBone black■ Cloud: IBM Bluemix, Amazon AWS, Azure

□ The user creates flows by wiring together different nodes:■ I/O (serial port, tcp sockets, http, mqtt, files)■ Functions (built in or custom JS functions)■ Advanced (execute programs, post a tweet)

Node-RED

52

□ Open a terminal and type node-red□ Open the browser and go to localhost:1880□ The node-red console appears

Node-RED flow

53

Node-RED flow

Nodes

Flow Tabs

Flow Area

Deploy button

□ Insert an inject node and a debug node. Wire them together.

□ Modify the inject block as it followsPayload -> "Hello World!"

□ Click on Deploy and then on the inject button

The “Hello World” flow

55

A working example

56

□ Let’s create a flow in Node-RED that:■ Generates random data periodically■ Create a chart and a gauge with such numbers

□ We need:■ Inject node■ Random node -> to install■ Dashboard nodes -> to install■ Debug node

MQTT

□ Protocol optimized for unreliable, low-bandwidth, high-latency network

□ Smallest possible packet size is 2 bytes□ Few methods: publish/subscribe/unsubscribe□ Based on topics

□ Publish/Subscribe paradigm■ Clients don’t know each other■ One-to-Many paradigm■ Every client publishes & subscribes

MQTT

MQTT

Topics

□ Topics are arbitrary strings used to identify a resource

□ Add the MQTT publisher node and the inject

□ Server: ws://mqtt.thingspeak.com:80/mqtt□ Topic: channels/<channelID>/publish/<apikey>□ Payload: field1=XX&field2=YY&status=MQTTPUBLISH□ Username: anyone□ Password: MQTT API key (Account -> My Profile)

Send data from Node-RED to ThingSpeak

□ Add the MQTT subscriber node and the debug

□ Server: ws://mqtt.thingspeak.com:80/mqtt□ Topic: channels/<channelID>/subscribe/fields/+/<apikey>

□ <apikey> is not required if the channel is public□ Username: anyone□ Password: MQTT API key (Account -> My Profile)

Read data from Node-RED to ThingSpeak

Last exercise

□ Send data from the MBED simulated temperature-humidity sensor to ThingSpeak via HTTP requests

□ Read the data on Node-RED■ Using MQTT, Subscribe to the channel from Node-RED

□ Visualize the data on the Node-RED dashboard■ A chart for historical temperature values■ A chart for historical humidity values■ A gauge for instantaneous temperature value■ A gauge for instantaneous humidity value

top related