IoT Physical Servers, Cloud Offerings and IoT Case …...Contents •Communication API •Web...
Transcript of IoT Physical Servers, Cloud Offerings and IoT Case …...Contents •Communication API •Web...
IoT Physical Servers, Cloud Offerings and IoT Case Studies
Mrs. K.M. Sanghavi
Contents
• Communication API • Web Application Messaging Protocol (WAMP) :
Autobahn for IoT • Xively Cloud for IoT • Python Web Application Framework: Djanjo • Amazon Web Services for IoT • SkyNet IoT Messaging Platform • Case Studies
– Home Intrusion Detection – Weather Monitoring System – Air Pollution Monitoring – Smart Irrigation
Communication API
• Facilitate
– Data Transfer
– Information Transfer
– Service Transfer
• Support
– Publish Subscribe models
• Use
– Remote Procedure Call
• WebSocket is a network communication protocol, which is required for many advanced features.
• Why do we need WebSocket?
• The answer is that because the HTTP protocol has a flaw: communication only can be initiated by the client.
WebSocket
• For example, let's say we want to know the weather today: the server will return the results of the query only if the client makes a request to the server.
• The HTTP protocol doesn't allow the server to push information to the client actively.
WebSocket
• Unidirectional
• Half duplex
• Stateless
• For each request, TCP connection has to be established first.
• Therefore, in order to find a better way, engineers invented WebSocket.
Problems with HTTP
• The biggest feature of the protocol is that the server can push information to the client actively, and the client can also send information to the server actively.
• It is a true two-way equal communication and is one of the server push technologies.
• It's based on the TCP protocol, and the implementation on the server side is relatively easy.
• It uses Publish – Subscribe communication model
WebSocket
• The data format is relatively light, and the performance overhead is small, but the communication is efficient
• Uses port number 443 and also 80
• Client can communicate with any server.
• The protocol identifier is ws (wss if encrypted) , and the URL is exactly the server's URL.
• ws://example.com:80/some/path
WebSocket
WebSocket
WebSocket
Is Great for Apps like :
Chat Trading
Multiplayer games Real – time charts
WAMP
Problem #1
• Its now no longer a time now to be static
• All the web applications need dynamism
• The web applications now should automatically get updated
• To solve this we use WAMP.
WAMP
• It is a subprotocol of WebSocket
• It is a routed protocol that means it requires a central router server to work.
• Enables different technologies,processes and machines to communicate with each other at real time.
• It offers two tools : Remote Procedure Call(RPC) and Pub / Sub
• Messages on WAMP are based on JSON format.
WAMP
WAMP
WAMP
WAMP
• Transport: Transport is a channel that connects two peers.
• Session: Session is a conversation between two peers that runs over a transport.
• Client: Clients are peers that can have one or more roles.
• In the publish–subscribe model, the Client can have the following roles:
–Publisher: Publisher publishes events (including payload) to the topic
maintained by the Broker.
–Subscriber: Subscriber subscribes to the topics and receives the events
including the payload.
•In the RPC model, the Client can have the following roles:
–Caller: Caller issues calls to the remote procedures along with call arguments.
–Callee: Callee executes the procedures to which the calls are issued by the
Caller and returns the results to the Caller.
WAMP
• Router: Routers are peers that perform generic call and event routing.
• In the publish–subscribe model, the Router has the role of a Broker.
–Broker: Broker acts as a Router and routes messages published to a topic to all
the subscribers subscribed to the topic.
• In the RPC model, the Router has the role of a Dealer.
–Dealer: Dealer acts a router and routes RPC calls from the Caller to the
Callee and routes results from the Calleeto the Caller.
• Application code: Application code runs on the Clients (Publisher, Subscriber, Callee or
Caller).
AUTOBAHN for IoT
Open source(MIT) real-time framework
Framework for WAMP and WebSocket i.e Web, Mobile and IoT
Compatible with Python 2.7
Supports TLS(Transport Layer Security) (secured WebSocket)
AUTOBAHN for IoT
Client
Roles for Pub/Sub
Roles for RPC
Subscriber
Publisher
Callee
Caller
Router
Roles for Pub/Sub
Roles for RPC
Broker
Dealer
Transport
Session
Communication channel
Autobahn framework working
WAMP Application deploy on
client
Client publishes the
event
Client messages to the router
Router runs on server and
sends the events to the Subscriber /
Callee
Autobahn Installation for WAMP
Installation
• $ sudo apt-get install python-twisted python-dev
• $ sudo apt-get install python-pip
• $ sudo pip install-upgrade twisted
• $ sudo pip install-upgrade autobahn
Implementation
• $ git clone https://github.com/tavendo/AutobahnPython.git
Xively Cloud
It is an IoT Cloud Platform
Builds , manages and derive business value from connected products
Provides cloud base API
It is a PAAS via RESTful API
Supports messaging service based on MQTT
Xively Concepts
Xively device: It is your “device” or the IoT project you are building. Consider it as an envelope containing the data.
Channels: It is the streaming coming from your sensors. Usually, the channel number is equal to the sensor number (as long as you want to monitor them all).
Sending data to Xively and monitoring
Adding the “device” to our account
Define the channels
Use the Xively library for your device
Send data to Cloud
Run the Code
Create a dashboard using the data stored in Xively.
Adding the “device” to our account
Define the channels
Add Xively library to the device
#include <b64.h> #include <HttpClient.h> #include <SPI.h> #include <Ethernet.h> #include <HttpClient.h> #include <Xively.h> #include "DHT.h“ #define DHTPIN 2 #define DHTTYPE DHT11 byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; EthernetClient client;
Add Xively library to the device
IPAddress ip(192, 168, 1, 40); // Arduino IP Add IPAddress myDns(8,8,8,8); IPAddress myGateway(192,168,1,1); int moisturePin = 0; int lightPin = 3; DHT dht(DHTPIN, DHTTYPE); // Xively setup char xivelyKey[] = "your_Xively_key_here"; char lightId[] = "Light"; char tempId[] = "Temperature"; char pressId[] = "Humidity"; char moistId[] = "Moisture";
Add Xively library to the device
XivelyDatastream datastreams[] = {
XivelyDatastream(lightId, strlen(lightId), DATASTREAM_FLOAT),
XivelyDatastream(tempId, strlen(tempId),DATASTREAM_FLOAT),
XivelyDatastream(pressId, strlen(pressId),DATASTREAM_FLOAT),
XivelyDatastream(moistId, strlen(moistId),DATASTREAM_FLOAT)
};
XivelyFeed feed(739668463, datastreams, 4);
XivelyClient xivelyclient(client);
Add Xively library to the device
void setup() { Serial.begin(9600); Serial.print("Starting..."); setupNet(); dht.begin(); } void loop() { float soilHum = analogRead(moisturePin); soilHum = (1023 - soilHum) * 100 /1023; Serial.println("Soil Humidty: " + String(soilHum)); // Read light float volts = analogRead(lightPin) * 5.0 / 1024.0; float amps = volts /10000.0;
Add Xively library to the device
float microamps = amps * 1000000; float lux = microamps * 2.0; Serial.println("Lux: " + String(lux)); float h = dht.readHumidity(); float temp = dht.readTemperature(); Serial.println("Temp: " + String(temp,2)); Serial.println("Hum: " + String(h,2)); // Prepare to send data datastreams[0].setFloat(lux); datastreams[1].setFloat(temp); datastreams[2].setFloat(h); datastreams[3].setFloat(soilHum); int ret = xivelyclient.put(feed, xivelyKey); Serial.println("Client returns ["+String(ret)+"]"); delay(5000); }
Add Xively library to the device
void setupNet() {
Serial.println("Set up network access.....");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac,ip,myDns,myGateway);
}
}
Add Xively library to the device
• XivelyDatastream that holds the four stream we send to Xively platform.
• Each channel defined previously using Xively interface corresponds to a XivelyDatastream.
• Remember to use in the data stream the same name used in the Xively interface.
Xively data
Creating dashboard
• Use Freeboard.io. This is a free IoT dashboard tool that can be integrated with Xively easily.
• It helps us to represent the information stored in Xively using charts.
Creating dashboard..connect freeboard.io
• Connecting Freeboard.io to Xively.
• This can be done easily using API Key.
Creating dashboard..create chart
• Create charts connecting them to the Xively channels covered before.
Creating dashboard..create your dashboard
• Create dashboard
Django
K M Sanghavi
Why Django framework and what is it
MVC-MVT Architecture
HandOn Django
Building Blocks of Django
Django Project Web Application
Agenda
Why Django framework
Django is a python framework which a code library that provide tools
and libraries to simplify common web development operations.
A framework provides a structure and common methods to make a
life of a web app developer much easier for flexible , scalable and
maintainable web applications
What is Django framework
It is a high level and has MVC-MVT style based architecture
It is written in powerful python
language
Features of Django
Django MVC-MVT Architecture
It is slightly different from MVC, as here Django takes part of Controller itself .
The template is either HTML or forms mixed with Django Template
Language(DTL)
Django MVT
The developer provides the model, the view and template then just maps
it to the URL and Django provides service to the user.
Hands On
Let’s create a Web App Using Django…on Linux
• Update the System
$ sudo apt-get update
• Install Django
$ sudo apt-get install python-django
• Check if Django is Installed
$ django-admin --version
Django Installation
• Open the terminal and create a directory
$ mkdir ks1
• Change the directory to the newly formed directory
$ cd ks1
• Create the Django Project
ks1 $ django-admin startproject Kfirst
This will create Kfirst folder with following structure
Django Web App..Create Project
Kfirst/ manage.py Kfirst/ _init_.py settings.py urls.py wsgi.py
Django Project Structure
Kfirst/
manage.py
KFirst/ _init_.py settings.py urls.py wsgi.py
Kfirst folder is just the project container / directory. We can rename it to anything we like
This Kfirst folder is actual python package of your project wchich contains some default files
• Change the directory to the Kfirst
$ cd Kfirst
• Run the Server
ks1/Kfirst/ $ python manage.py runserver
• Go to the browser and type
localhost:8000
The following o/p is shown on browser window
Django Web App…RunServer
• Create the App
ks1/Kfirst $ python manage.py startapp Kfirstapp
This adds certain files into Kfirstapp folder
• Register the Kfirstapp it with our Django project “Kfirst".
– To do so, update INSTALLED_APPS tuple in the settings.py file of your project Kfirst\Kfirst (add your app name)
Django Web App…Create App
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ‘Kfirstapp', )
• Initiate the database, to have access to admin interface
ks1/Kfirst $ python manage.py syncdb
• Open the Kfirst/urls.py and you should have something like −
Django Web App…Admin Interface
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns(‘ ‘, url(r'^admin/', include(admin.site.urls)), )
Django Web App…Admin Interface
• Run the Server #ignore if server is already running ks1/Kfirst/ $ python manage.py runserver
• Go to the browser and type localhost:8000/admin/
The following o/p is shown on browser window
• Open the Kfirstapp/views.py and add as per following −
Django Web App…Create View
from django.http import HttpResponse def hello(request): text = """<h1>welcome to my app !</h1>""" return HttpResponse(text)
• Open the myproject/urls.py and add as per following −
Django Web App…URL Mapping
from django.conf.urls import patterns, include, url from django.contrib import admin from Kfirstapp import views admin.autodiscover() urlpatterns = patterns(‘ ‘, url(r'^admin/', include(admin.site.urls)), url(r'^hello/$', views.hello, name=‘hello')
)
Django Web App…Access Web App
• Run the Server #ignore if server is already running ks1/Kfirst/ $ python manage.py runserver
• Go to the browser and type localhost:8000/hello
Hands On
Let’s create a Web App Using Django…on Windows
• Install Python – https://python.org/downloads/
• Check if Python is Installed $ python –version
• If O/P is Python 3.x.x …python has been installed
• Install Django $ pip install django
• verify your Django installation by executing $ django-admin --version
$ If O/P is 2.1.7…Django has been installed
For Django Installation..On Windows
• Open the command prompt and create a directory
$ mkdir ks1
• Change the directory to the newly formed directory
$ cd ks1
• Create the Django Project
ks1 $ django-admin startproject Kfirst
This will create Kfirst folder with following structure
Django Web App..Create Project ..On Windows
Kfirst/ manage.py Kfirst/ _init_.py settings.py urls.py wsgi.py
• Change the directory to the Kfirst
$ cd Kfirst
• Run the Server
ks1/Kfirst/ $ python manage.py runserver
• Go to the browser and type
localhost:8000
The following o/p is shown on browser window
Django Web App…RunServer..On Windows
• Create the App in another command-prompt in Kfirst folder ks1/Kfirst $ python manage.py startapp Kfirstapp
This adds certain files into Kfirstapp folder
• Register the Kfirstapp it with our Django project “Kfirst". – To do so, update INSTALLED_APPS tuple in the settings.py file
(in Kfirst\Kfirst folder)
(add your app name)
Django Web App…Create App…On Windows
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ‘Kfirstapp', )
• Initiate the database, to have access to admin interface …(Run this command in the project folder)
ks1/Kfirst $ python manage.py migrate
• Open the Kfirst/Kfirst/urls.py and you should have something like −
Django Web App…Admin Interface..on Windows
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = [ path(‘admin/', admin.site.urls), ]
Django Web App…Admin Interface.. On Windows
• Run the Server #ignore if server is already running ks1/Kfirst/ $ python manage.py runserver
• Go to the browser and type localhost:8000/admin/
The following o/p is shown on browser window
• Open the Kfirstapp/views.py and add as per following −
Django Web App…Create View…On windows
from django.http import HttpResponse def hello(request): text = """<h1>welcome to my app !</h1>""" return HttpResponse(text)
• To call the view, we need to map it to a URL - and for this we need a URLconf.
• To create a URLconf in the Kfirstapp directory, create a file called urls.py. Your app directory should now look like:
URL Mapping…On windows
from django.urls import path from .import views urlpatterns= [ path(‘ ‘, views.hello, name=‘hello’), )
• Change the urls.py in Kfirst\Kfirst folder.
from django.urls import include, path from django.contrib import admin urlpatterns = [ path('admin/', admin.site.urls), path('Kfirstapp/', include(‘Kfirstapp.urls’)),
)
URL Mapping…On windows
Django Web App…Access Web App
• Run the Server #ignore if server is already running ks1/Kfirst/ $ python manage.py runserver
• Go to the browser and type localhost:8000/Kfirstapp
• This is the final output.
Amazon Web Services
• What is AWS • Why to Use AWS • AWS Service Overview • Cost of AWS • Future of AWS
Amazon Web Services
Global Cloud Platform
Used by 80% of fortune 500 Companies
Infrastructure as a service
Platform as a service
Software as a service
Cloud Storage PLatform
Why to Use AWS
Per Hour Billing Easy Sign Up
Simple Billing Stable
Trusted Vendor
AWS Service Overview
Elastic Cloud Compute (EC2)
• Gives PAAS Service as per requirements
Virtual Private Cloud(VPC)
• Allows to create networks and allows servers to be in those networks
Simple Storage Service(S3)
• Gives Opportunity to Upload and Store filesi.e File Storage and Sharng service
Relational Database Service(RDS)
• Allows to Run and manage database on cloud
AutoScaling
• Adds Capacity on a fly to the ELB , so as to let the application never down due to load
Route 53
• It has DNS Routing Service
Elastic Load Balanacer(ELB)
• Gives Opportunity to Load Balance in the coming traffic to multiple machines; so that web app can scale up to any number of users
AWS Service Overview
Elastic Cloud Compute (EC2)
• Gives PAAS Service as per requirements
Virtual Private Cloud(VPC)
• Allows to create networks and allows servers to be in those networks
Simple Storage Service(S3)
• Gives Opportunity to Upload and Store filesi.e File Storage and Sharng service
Relational Database Service(RDS)
• Allows to Run and manage database on cloud
AutoScaling
Route 53
• It has DNS Routing Service
Elastic Load Balanacer(ELB)
• Gives Oppurtunity to Load Balance in the coming traffic to multiple machines; so that web app can scale up to any number of users
Cost of AWS
• Per Hour Billing • Region Wise Billing • Term specific billing • Spot Resources…Bidding
Future of AWS
• 64 Services there in total • Focus on Machine Learning • Focus on SAAS products • Reduction in Costs
SKYNET ..IOT MESSAGING PLATFORM
K M Sanghavi
Skynet
■ Open source
■ Instant Messaging (IM) service for connected devices and services
■ Launched recently.
■ Cloud-based MQTT-powered network
■ Scales to meet any needs whether the nodes are smart home devices, sensors, cloud resources, drones, Arduinos, Raspberry Pis, among others.
■ Powered by Node.JS,
■ Combines IoT with Artificial Intelligence
■ Supports Pub/SUb
■ When nodes and devices register with Skynet, they are assigned a unique id known as a UUID along with a security token
■ Upon connecting your node or device to Skynet, you can query and update devices on the network and send machine-to-machine (M2M) messages in an RPC-style fashion.
■ Real time M2M communication is what Skynet aims for.
■ SkyNet runs as an IoT platform-as-a-service (PaaS) as well as a private cloud through Docker
Skynet
■ With SkyNet platform, we are able to save a ton of work by not having to develop our own communication tools, authentication scheme, or backend service to handle the streams of data
■ Instead, our devices simply turn on, authenticate and connect with SkyNet automatically, and we are able to start passing data securely
Skynet
■ Details can be found on : https://www.youtube.com/watch?v=iCLe1XScr2M
■ Skynet.im
Skynet