Industrial automation, communication and data management · Prototyping Simulation Prototype...

60
Politecnico di Milano Advanced Network Technologies Laboratory Industrial automation, communication and data management Hands on activities

Transcript of Industrial automation, communication and data management · Prototyping Simulation Prototype...

Page 1: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Politecnico di MilanoAdvanced Network Technologies Laboratory

Industrial automation, communication and data management

Hands on activities

Page 2: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

□ Email: [email protected]□ Phone: 02 2399 9614

Page 3: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 4: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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’’

Page 5: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Things

Page 6: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 7: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Sensors

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

Page 8: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Communication pattern

Page 9: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Politecnico di MilanoAdvanced Network Technologies Laboratory

IoT Software Platforms…in the cloud

9

Page 10: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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?

Page 11: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 12: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 13: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

IoT platforms

13

Page 14: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 15: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 16: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 17: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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!

Page 18: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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)

Page 19: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Easy development

21

Page 20: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Easy development

22

□ Built-in and custom functionsReactive Blocks

Node-Red

Page 21: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Communities

23

□ Speed-up learning processes

Page 22: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Dashboard DIY24

DGLux CumulocityAzure BI

freeboard

Page 23: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 24: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Politecnico di MilanoAdvanced Network Technologies Laboratory

Developing IoT applications

26

MBED OS simulator

Page 25: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Development Pipeline

□ Application design□ Prototyping

■ Simulation■ Prototype implementation

□ Production□ Release□ Application maintenance/updates

Page 26: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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)

Page 27: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Simulation

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

Page 28: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 29: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

MBED OS simulator

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

https://tinyurl.com/simulatorpoli

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

Page 30: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

MBED OS simulator

Code area

Demo list

Debug area

Board & sensors area

Page 31: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

MBED Simulator Examples

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

Page 32: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Send data somewhere

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

Page 33: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Send data somewhere

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

Page 34: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 35: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 36: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

ThingSpeak

38

Page 37: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

ThingSpeak

39

Page 38: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 39: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 40: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 41: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 42: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

API Key

44

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

if the user feels that theyare compromised

Page 43: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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…

Page 44: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 45: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 46: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 47: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ Use python3!

Update a channel (python3)

Page 48: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Node-RED

51

Page 49: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 50: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Node-RED flow

53

Page 51: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Node-RED flow

Nodes

Flow Tabs

Flow Area

Deploy button

Page 52: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 53: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 54: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

Page 55: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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

MQTT

Page 56: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

MQTT

Page 57: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

Topics

□ Topics are arbitrary strings used to identify a resource

Page 58: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 59: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

□ 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

Page 60: Industrial automation, communication and data management · Prototyping Simulation Prototype implementation Production Release ... IBM Bluemix, Amazon AWS, Azure The user creates

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