0% found this document useful (0 votes)
5 views

Module 5

The document outlines the fundamentals of Python programming, focusing on data types, control flow, functions, and modules, while also introducing IoT concepts and applications using Raspberry Pi. It highlights Python's characteristics such as being a multi-paradigm, interpreted, and interactive language, along with its broad library support. Additionally, it discusses the structure of IoT devices and their functionalities, emphasizing the role of Raspberry Pi in IoT projects.

Uploaded by

geethumol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Module 5

The document outlines the fundamentals of Python programming, focusing on data types, control flow, functions, and modules, while also introducing IoT concepts and applications using Raspberry Pi. It highlights Python's characteristics such as being a multi-paradigm, interpreted, and interactive language, along with its broad library support. Additionally, it discusses the structure of IoT devices and their functionalities, emphasizing the role of Raspberry Pi in IoT projects.

Uploaded by

geethumol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 111

 Module- 5

 IoT Logical Design using Python, IoT Physical Devices


and Endpoints - Raspberry Pi interfaces, Programming
Raspberry Pi using Python, Other IoT devices, IoT
Physical devices and Cloud offerings, Cloud Storage
Models, WAMP - Autobahn for IoT, Django, Designing
RESTful Web API, Cloud Web Services for IoT.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Python data types and data structures
 Control flow
 Functions
 Modules
 Packages
 File input/output
 Date/Time operations
 Classes

Dr. Uma Narayanan, CSE, RSET


 Python is a general-purpose high-level programming language suitable for
providing a solid foundation to the reader in the area of cloud computing.
 The main characteristics of Python are:
 Multi-paradigm programming language
 Python supports more than one programming paradigm, including object-
oriented programming and structured programming
 Interpreted language
 Python is an interpreted language and does not require an explicit compilation
step. The Python interpreter executes the program source code directly,
statement by statement, as a processor or scripting engine does.
 Interactive language
 Python provides an interactive mode in which the user can submit commands at
the Python prompt and interact with the interpreter directly.
Dr. Uma Narayanan, CSE, RSET
 Easy-to-learn, read and maintain
 Python is a minimalistic language with relatively few keywords, uses English
keywords and has fewer syntactical constructions as compared to other languages.
Reading Python programs feels like reading English with pseudocode-like
constructs. Python is easy to learn yet an extremely powerful language for a wide
range of applications.
 Object and procedure oriented
 Python supports both procedure-oriented programming and object-oriented
programming. Procedure-oriented paradigm allows programs to be written around
procedures or functions that allow reuse of code. Object-oriented paradigm allows
programs to be written around objects that include both data and functionality.
 Extendable
 Python is an extendable language and allows integration of low-level modules
written in languages such as C/C++. This is useful when you want to speed up a
critical portion of a program.
Dr. Uma Narayanan, CSE, RSET
 Scalable
 Due to the minimalistic nature of Python, it provides a manageable structure for large
programs.
 Portable
 Since Python is an interpreted language, programmers do not have to worry about
compilation, linking and loading of programs. Python programs can be directly
executed from the source.
 Broad library support
 Python has broad library support and works on various platforms such as Windows,
Linux, Mac, etc.

Dr. Uma Narayanan, CSE, RSET


 Windows
 Python binaries for Windows can be downloaded from http://www.python.org/getit .
 For the examples and exercise in this book, you would require Python 2.7 which can be
directly downloaded from: http://www.python.org/ftp/python/2.7.5/python-2.7.5.msi
 Once the python binary is installed you can run the python shell at the command prompt
using > python
 Linux

Dr. Uma Narayanan, CSE, RSET


 The number data type is used to store numeric values. Numbers are immutable data
types, therefore changing the value of a number data type results in a newly allocated
object

Dr. Uma Narayanan, CSE, RSET


 A string is simply a list of characters in order. There are no limits to the number of
characters you can have in a string.

Dr. Uma Narayanan, CSE, RSET


A list is a compound data type used to group together other values.
List items need not all be of the same type.
A list contains items separated by commas and enclosed within square brackets.

 #Lists can be nested


 #Mixed data types in a list
 >>>nested=[fruits,vegetables]
 >>>mixed=[’data’,5,100.1, L]
 >>>nested[[’apple’, ’mango’, ’orange’,
 >>>type(mixed) ’banana’, ’pear’], [’potato’, ’carrot’,
 <type ’list’> ’onion’, ’beans’, ’radish’]]
 >>>type(mixed[0])  #Create List
 <type ’str’>  >>>fruits=[’apple’,’orange’,’banana’,’m
ango’]
 >>>type(mixed[1])
 >>>type(fruits)
 <type ’int’>
 <type ’list’>
 #Get Length of List
 >>>len(fruits)
Dr. Uma Narayanan, CSE, RSET  4
 #Access List Elements  #Inserting an item to a list
 >>>fruits[1]’orange’  >>>fruits.insert(1,’mango’)
 >>>fruits[1:3]  [’apple’, ’mango’, ’orange’, ’banana’,
’pear’]
 [’orange’, ’banana’]
 #Combining lists
 >>>fruits[1:]
 >>>vegetables=[’potato’,’carrot’,’onion
 [’orange’, ’banana’, ’mango’] ’,’beans’,’radish’]
 #Removing an item from a list  >>>vegetables[’potato’, ’carrot’,
 >>>fruits.remove(’mango’) ’onion’, ’beans’, ’radish’]
 >>>fruits  >>>eatables=fruits+vegetables
 [’apple’, ’orange’, ’banana’, ’pear’]  >>>eatables
 [’apple’, ’mango’, ’orange’, ’banana’,
’pear’, ’potato’, ’carrot’, ’onion’, ’beans’,
’radish’]
Dr. Uma Narayanan, CSE, RSET
 A tuple is a sequence data type that is similar to the list.
 A tuple consists of a number of values separated by commas and enclosed within
parentheses.
 Unlike lists, the elements of tuples cannot be changed, so tuples can be thought of
as read-only lists.

Dr. Uma Narayanan, CSE, RSET


 Dictionary is a mapping data type or a kind of hash table that maps keys to values.
 Keys in a dictionary can be of any data type, though numbers and strings are
commonly used.
 The values in a dictionary can be any data type or object.
 #Create a dictionary >>>student={’name’:’Mary’,’id’:’8776’,’major’:’CS’}
 >>>student{’major’: ’CS’, ’name’: ’Mary’, ’id’: ’8776’}
 >>>type(student)<type ’dict’>
 #Get length of a dictionary
 >>>len(student)3
 #Get the value of a key in dictionary
 >>>student[’name’]’Mary’
 #Get all items in a dictionary
 >>>student.items()
 [(’gender’, ’female’), (’major’, ’CS’), (’name’, ’Mary’), (’id’, ’8776’)]

Dr. Uma Narayanan, CSE, RSET


 #Get all keys in a dictionary
 >>>student.keys()
 [’gender’, ’major’, ’name’, ’id’]
 #Get all values in a dictionary
 >>>student.values()[’female’, ’CS’, ’Mary’, ’8776’]
 #Add new key-value pair
 >>>student[’gender’]=’female’
 >>>student{’gender’: ’female’, ’major’: ’CS’, ’name’: ’Mary’, ’id’: ’8776’}
 #A value in a dictionary can be another dictionary
>>>student1={’name’:’David’,’id’:’9876’,’major’:’ECE’}
 >>>students={’1’: student,’2’:student1}>>>students{’1’: {’gender’: ’female’, ’major’:
’CS’, ’name’: ’Mary’, ’id’: ’8776’}, ’2’: {’major’: ’ECE’, ’name’: ’David’, ’id’: ’9876’}}
 #Check if dictionary has a key
>>>student.has_key(’name’)True>>>student.has_key(’grade’)False
Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
 The if statement in Python is similar to the if statement in other
languages.

Dr. Uma Narayanan, CSE, RSET


 The for statement in Python iterates over items of any sequence (list,
string, etc.) in the order in which they appear in the sequence.
 This behavior is different from the for statement in other languages
such as C, in which initialization, incrementing and stopping criteria
are provided.

Dr. Uma Narayanan, CSE, RSET


 The while statement in Python executes the statements within the
while loop as long as the condition is true.

Dr. Uma Narayanan, CSE, RSET


 The range statement in Python generates a list of numbers in arithmetic
progression.

Dr. Uma Narayanan, CSE, RSET


 The break and continue statements in Python are similar to the statements
in C
 The break statement breaks out of the for/while

 The continue statement continues with the next iteration.

Dr. Uma Narayanan, CSE, RSET


 The pass statement in Python is a null operation.
 The pass statement is used when a statement is required syntactically but you do
not want any command or code to execute.
 >>>fruits=[’apple’,’orange’,’banana’,’mango’]
 >>>for item in fruits:
if item == "banana":
pass
else:
print item
apple
orange
mango
Dr. Uma Narayanan, CSE, RSET
 A function is a block of code that takes in
information (in the form of parameters), does
some computation and returns a new piece of
information based on the parameter information.
 A function in Python is a block of code that begins
with the keyword def followed by the function
name and parentheses. The function parameters
are enclosed within the parenthesis.
 The code block within a function begins after a
colon that comes after the parenthesis enclosing
the parameters.
 The first statement of the function body can
optionally be a documentation string or docstring

Dr. Uma Narayanan, CSE, RSET


 Functions can have default values
for the parameters.
 If a function with default values is
called with fewer parameters or
without any parameter, the
default values for the parameters
are used.

Dr. Uma Narayanan, CSE, RSET


 All parameters in Python functions
are passed by reference.
 If a parameter is changed within a
function, the change is also reflected
in the calling function

Dr. Uma Narayanan, CSE, RSET


 Functions can also be called using keyword arguments that identify
the arguments by the parameter name when the function is called.

Dr. Uma Narayanan, CSE, RSET


 Python functions can have variable length arguments.
 The variable length arguments are passed as a tuple to the function
with the argument prefixed with an asterix (*)

Dr. Uma Narayanan, CSE, RSET


 Python allows organization of
the program code into
different modules, which
improves code readability and
management.
 A module is a Python file that
defines some functionality in
the form of functions or
classes.
 Modules can be imported
using the import keyword.
 Modules to be imported must
be present in the search path.
Dr. Uma Narayanan, CSE, RSET
 A Python package is a hierarchical file
structure that consists of modules and
subpackages.
 Packages allow better organization of
modules related to a single application
environment.

Dr. Uma Narayanan, CSE, RSET


 Python allows reading and writing
to files using the file object.
 The open(filename, mode) function
is used to obtain a file object.
 The mode can be read (r), write
(w), append (a), read and write (r+
or w+), read-binary (rb), write-
binary (wb), etc.
 After the file contents have been
read, the close function is called
which closes the file object.
Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
 Python provides several functions for date and time access and
conversions.
 The datetime module allows manipulation of date and time in several
ways.
 The time module in Python provides various time-related functions.

Dr. Uma Narayanan, CSE, RSET


 Python is an Object-Oriented Programming (OOP) language.
 Python provides all the standard features of OOP such as classes, class variables, class
methods, inheritance, function overloading and operator overloading.
 Class
 A class is simply a representation of a type of object and a user-defined prototype for an object
that is composed of three things: a name, attributes and operations/methods.
 Instance/Object
 An object is an instance of the data structure defined by a class.

 Inheritance
 Inheritance is the process of forming a new class from an existing class or base class.

 Function overloading
 Function overloading is a form of polymorphism that allows a function to have different
meanings, depending on its context.
 Operator overloading
 Operator overloading is a form of polymorphism that allows assignment of more than one
function to a particular operator.
 Function overriding
 Function overriding allows a child class to provide a specific implementation of a function that
is already provided by the base class. Child class implementation of the overridden function
has the same name, parameters and return type as the function in the base class.
Dr. Uma Narayanan, CSE, RSET
 The variable studentCount is a class
variable that is shared by all instances
of the class Student and is accessed by
Student.studentCount.
 The variables name, id and grades are
instance variables which are specific
to each instance of the class.
 There is a special method by the name
__init__() which is the class
constructor.
 The class constructor initializes a new
instance when it is created. The
function __del__() is the class
destructor.
Dr. Uma Narayanan, CSE, RSET
 In this example, Shape is the base class and Circle is the derived class.
 The class Circle inherits the attributes of the Shape class.
 The child class Circle overrides the methods and attributes of the base
class (e.g., the draw() function defined in the base class Shape is
overridden in child class Circle).

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 A "Thing" in Internet of Things (IoT) can be any object that has a
unique identifier and which can send/receive data (including user
data) over a network (e.g., smart phone, smart TV, computer,
refrigerator, car, etc. ).
 IoT devices are connected to the Internet and send information about
themselves or about their surroundings (e.g. information sensed by
the connected sensors) over a network (to other devices or
servers/storage) or allow actuation upon the physical
entities/environment around them remotely

Dr. Uma Narayanan, CSE, RSET


 A home automation device that allows remotely monitoring the status
of appliances and controlling the appliances.
 An industrial machine which sends information abouts its operation
and health monitoring data to a server.
 A car which sends information about its location to a cloud-based
service.
 A wireless-enabled wearable device that measures data about a
person such as the number of steps walked and sends the data to a
cloud-bsed service.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Raspberry Pi is a small, affordable, and versatile computer board that
was originally developed to promote the teaching of basic computer
science in schools. However, it has now become a popular tool for a
wide range of applications, including Internet of Things (IoT)
projects.
 The Raspberry Pi board is designed to be highly customizable and
can be configured with various hardware components and sensors to
create IoT applications. With its low power consumption, small form
factor, and wide range of interfaces, the Raspberry Pi is an ideal
platform for building IoT devices.

Dr. Uma Narayanan, CSE, RSET


 Raspberry Pi is a low-cost mini-computer with the physical size of a
credit card.
 Raspberry Pi runs various flavors of Linux and can perform almost
all tasks that a normal desktop computer can do.
 Raspberry Pi also allows interfacing sensors and actuators through
the general purpose I/O pins.
 Since Raspberry Pi runs Linux operating system, it supports Python
"out of the box”

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Raspberry Pi has several interfaces that allow it to interact with various
hardware components and sensors. Here is an overview of the different
interfaces available on Raspberry Pi and their functionalities:
 GPIO (General Purpose Input/Output) Pins: These pins allow the Raspberry Pi
to interact with external hardware components such as sensors, LEDs, and
motors. The GPIO pins can be programmed to be either input or output pins,
allowing for bi-directional communication between the Raspberry Pi and
external devices.
 USB (Universal Serial Bus) Ports: These ports allow the Raspberry Pi to connect
to USB devices such as keyboards, mice, and cameras. USB devices can be used
for data transfer or as input devices for the Raspberry Pi.

Dr. Uma Narayanan, CSE, RSET


 Ethernet Port: This port allows the Raspberry Pi to connect to a network via an
Ethernet cable. This enables communication between the Raspberry Pi and
other devices on the network, as well as access to the internet.
 HDMI Port: This port allows the Raspberry Pi to connect to a display monitor.
This is useful for displaying data or graphics generated by the Raspberry Pi.
 Camera Port: This port allows the Raspberry Pi to connect to a camera module.
This enables the Raspberry Pi to capture images and video, which can be useful
for applications such as security cameras or image recognition.

Dr. Uma Narayanan, CSE, RSET


 Examples of how these interfaces can be used in IoT applications are:
 Using GPIO pins to connect sensors and actuators to the Raspberry Pi and
controlling them with Python code.
 Using USB ports to connect external storage devices to the Raspberry Pi for
data storage.
 Using Ethernet port to connect the Raspberry Pi to a network and control IoT
devices remotely.
 Using HDMI port to display sensor data or real-time video feeds from
cameras.
 Using camera port to capture images and video for applications such as
security monitoring or object recognition.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Raspbian
 Raspbian Linux is a Debian Wheezy port optimized for Raspberry Pi.

 Arch
 Arch is an Arch Linux port for AMD devices.

 Pidora
 Pidora Linux is a Fedora Linux optimized for Raspberry Pi.

 RaspBMC
 RaspBMC is an XBMC media-center distribution for Raspberry Pi.

 OpenELEC
 OpenELEC is a fast and user-friendly XBMC media-center distribution.

 RISC OS
 RISC OS is a very fast and compact operating system
Dr. Uma Narayanan, CSE, RSET
 To interact with the Raspberry Pi interfaces using Python, you can use
libraries such as "RPi.GPIO" to control the GPIO pins and
"Adafruit_Python_DHT" to read data from temperature and humidity
sensors. You can also use Python to control LEDs, read button presses,
and collect sensor data.
 Python also has several libraries and frameworks that can be used for
IoT applications on Raspberry Pi.
 Flask is a popular web framework that can be used to build web
interfaces for controlling IoT devices.
 Pygame is a library for creating games and multimedia applications
on Raspberry Pi, which can be used for IoT applications such as
creating user interfaces for smart home devices.
 PySerial is a library that can be used for serial communication
between Raspberry Pi and other devices, such as Arduino boards.
Dr. Uma Narayanan, CSE, RSET
 GPIO Zero: GPIO Zero is a Python library that simplifies the process
of controlling Raspberry Pi's GPIO pins. It provides a simple and
intuitive API for working with buttons, LEDs, motors, and other GPIO-
connected components. GPIO Zero is often used for building
interactive projects and prototyping hardware ideas.
 Picamera: Picamera is a Python library for controlling the Raspberry
Pi camera module. It provides a simple interface for capturing
images and video, as well as controlling camera settings like
exposure and white balance. Picamera is often used for creating
timelapse videos, security systems, and video streaming applications
on Raspberry Pi.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
 Serial
 The serial interface on Raspberry Pi has receive (Rx) and transmit (Tx) pins
for communication with serial peripherals.
 SPI
 Serial Peripheral Interface (SPI) is a synchronous serial data protocol used for
communicating with one or more peripheral devices.
 MISO (Master In Slave Out) : Master line for sending data to the peripherals.
 MOST (Master Out Slave In) : Slave line for sending data to the master.
 SOK (Serial Clock) : Clock generated by master to synchronize data transmission
 CEO (Chip Enable 0) : To enable or disable devices.
 CEO (Chip Enable I) : To enable or disable devices.

 I2C
 The I2C interface pins on Raspberry Pi allow you to connect hardware
modules. I2C interface allows synchronous data transfer with just two pins -
SDA (data line) and SCL (clock line)
Dr. Uma Narayanan, CSE, RSET
Reading button presses:
To read button presses, you can use the RPi.GPIO library and set up the GPIO
pin connected to the button as an input pin.
Here's an example code to detect a button press on GPIO pin 23:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(23)
if input_state == False:
print('Button Pressed')
time.sleep(0.2)
Dr. Uma Narayanan, CSE, RSET
Collecting sensor data:
To collect sensor data, you need to connect the sensor to the appropriate
GPIO pins and use a library specific to the sensor.
Here's an example code to collect temperature data using
the Adafruit_DHT library with a DHT11 sensor connected to GPIO pin 4:
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temperature={0:0.1f}C Humidity={1:0.1f}%'.format(temperature,
humidity))
else:
print('Failed to retrieve data from sensor')
Dr. Uma Narayanan, CSE, RSET
 PROGRAM TO BLINKING LED
 import RPi.GPIO as GPIO
 import time
 GPIO.setmode(GPIO.BCM)
 GPIO.setup(18, GPIO.OUT)
 while True:
 GPIO.output(18, True)
 time.sleep(1)
 GPIO.output(18, False)
 time.sleep(1)

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
 pcDuino
 pcDuino is an Arduino-pin compatible single
board mini-computer that comes with a
1GHz ARM Cortex-A8 processor
 peDuino is a high performance and cost
effective device that runs PC like OS such as
Ubuntu and Android ICS.
 Like,Raspberry Pi, it has an HEIM!
video/audio interface.
 pcDuino supports various programming
languages including C,C++ (with.GNU tool
chain), Java (with standard Android SDK) and
Python
Dr. Uma Narayanan, CSE, RSET
 BeagleBone Black
 BeagleBone B1ack is similar to Raspberry Pi, but a more
powerful device.
 It is based on the ARM Cortex-A8 processor and runs a
variant of the Linux operating system.
 It has GPIO pins, analog inputs, and various interfaces
such as USB and Ethernet that can be used to interface
with electronic components.
 It supports multiple programming languages including
Python, C, and JavaScript.
 It has built-in support for the Cloud9 IDE, allowing you to
program it using a web-based interface.
 BeagleBone Black is a powerful and flexible platform for
building a variety of applications, especially those
requiring real-time processing or control.
Dr. Uma Narayanan, CSE, RSET
 Cubieboard
 Cubieboard is powered by a dual core ARM Cortex A7 processor
and has a range of input/output interfaces including USB, HDMI, IR,
serial, Ethernet, SATA, and a 96 pin extended interface.
 Cubieboard also provides SATA support, The board can run both
Linux and Android operating systems
 Cubieboard is a flexible and affordable platform for building a
variety of applications, especially those requiring multimedia
capabilities

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Cloud storage is a model of data storage in which data is stored on
remote servers that can be accessed over the internet. The servers are
maintained, operated, and managed by a cloud storage service provider,
who provides data storage space and resources to individuals and
organizations in exchange for a fee.
 Cloud storage providers typically offer various storage models, such as
object storage, block storage, file storage, and archive storage, each with
its own unique characteristics, use cases, and pricing models.

Dr. Uma Narayanan, CSE, RSET


 Scalability: Cloud storage can be easily scaled up or down based on the
volume of data generated by IoT devices, allowing organizations to handle
large volumes of data without the need for costly hardware upgrades.
 Accessibility: Cloud storage can be accessed from anywhere with an
internet connection, making it easy to share data between devices and
users.
 Reliability: Cloud storage providers typically offer high levels of
redundancy and data backups, ensuring that data is always available and
protected against data loss.
 Cost-effectiveness: Cloud storage eliminates the need for organizations to
purchase and maintain their own storage hardware, reducing hardware
costs and maintenance expenses.
Dr. Uma Narayanan, CSE, RSET
 1.Object Storage:
 Characteristics: Object storage is a type of storage that stores data as objects
rather than files or blocks. Objects contain data along with metadata that
describes the data, such as its type, size, and creation date. Objects are typically
accessed using HTTP RESTful APIs.
 Use cases: Object storage is ideal for storing large volumes of unstructured
data, such as images, audio, and video files. It is commonly used in cloud-based
applications, backup and recovery systems, and content delivery networks.
 Advantages and disadvantages: Object storage is highly scalable, reliable, and
offers high availability. It also supports advanced data management features
such as versioning, metadata tagging, and lifecycle policies. However, it is less
performant than block storage and may have slower access times due to the
additional metadata.
Dr. Uma Narayanan, CSE, RSET
 2.Block Storage:
 Characteristics: Block storage is a type of storage that stores data in fixed-
sized blocks, typically accessed using a Storage Area Network (SAN) or
Network Attached Storage (NAS) protocol. Blocks are typically formatted with
a file system and can be used as the underlying storage for virtual machines or
databases.
 Use cases: Block storage is ideal for storing structured data that requires high-
performance storage, such as databases or virtual machine images. It is
commonly used in enterprise applications, database systems, and virtualized
environments.
 Advantages and disadvantages: Block storage is highly performant and offers
low latency access times. It also supports advanced features such as snapshots,
clones, and replication. However, it is less scalable and less cost-effective than
object storage.
Dr. Uma Narayanan, CSE, RSET
 3.File Storage:
 Characteristics: File storage is a type of storage that stores data as files,
typically accessed using Network File System (NFS) or Server Message Block
(SMB) protocols. Files are stored in a hierarchical directory structure, similar to
a traditional file system.
 Use cases: File storage is ideal for storing user-generated content or files that
need to be shared across multiple users or systems, such as documents,
images, or videos. It is commonly used in content management systems, file
sharing platforms, and collaborative applications.
 Advantages and disadvantages: File storage is easy to use and provides shared
access to files across multiple users or systems. It also supports features such
as file locking, file permissions, and access control. However, it may have
slower access times and lower scalability than object storage.
Dr. Uma Narayanan, CSE, RSET
 4.Archive Storage:
 Characteristics: Archive storage is a type of storage that is designed for long-
term retention of data that is rarely accessed. It typically provides lower-cost
storage with longer access times than other types of storage.
 Use cases: Archive storage is ideal for storing data that must be retained for
compliance or regulatory purposes, such as legal documents or financial
records. It is also used for storing large volumes of data that do not require
frequent access, such as backup data or scientific research data.
 Advantages and disadvantages: Archive storage provides cost-effective, long-
term storage with low access costs. It also supports advanced features such as
retention policies, data encryption, and data immutability. However, it may
have longer access times and lower availability than other types of storage.
Dr. Uma Narayanan, CSE, RSET
 1.Amazon Web Services (AWS) S3:
 Features: AWS S3 offers highly scalable, durable, and secure object storage
with advanced data management features such as versioning, lifecycle
policies, and access control. It also offers different storage classes with
varying access times and costs.
 Use cases: AWS S3 is commonly used for backup and recovery, content
delivery, and data analytics.
 2. Microsoft Azure Blob Storage:
 Features: Azure Blob Storage offers highly scalable and secure object storage
with advanced data management features such as versioning, lifecycle
policies, and access control. It also offers different tiers with varying access
times and costs.
 Use cases: Azure Blob Storage is commonly used for backup and recovery,
media storage, and content delivery.
Dr. Uma Narayanan, CSE, RSET
 3.Google Cloud Storage:
 Features: Google Cloud Storage offers highly scalable and secure object
storage with advanced data management features such as versioning,
lifecycle policies, and access control. It also offers different storage classes
with varying access times and costs.
 Use cases: Google Cloud Storage is commonly used for backup and
recovery, media storage, and data analytics.
 4.IBM Cloud Object Storage:
 Features: IBM Cloud Object Storage offers highly scalable and secure
object storage with advanced data management features such as
versioning, lifecycle policies, and access control. It also offers different tiers
with varying access times and costs.
 Use cases: IBM Cloud Object Storage is commonly used for backup and
recovery, content delivery, and data analytics.
Dr. Uma Narayanan, CSE, RSET
 5. Dropbox:
 Features: Dropbox offers file storage with advanced collaboration features
such as file sharing, commenting, and versioning. It also offers integration
with other applications and services.
 Use cases: Dropbox is commonly used for personal file storage and
collaboration, as well as business file sharing and collaboration.

Dr. Uma Narayanan, CSE, RSET


 Object Storage:
 Advantages: Object storage is a scalable and cost-effective option for
storing large volumes of unstructured data, such as images, videos, and
sensor data generated by IoT devices. It also offers advanced data
management features, such as versioning, lifecycle policies, and access
control, which are important for managing IoT data over time.
 Examples of IoT use cases: Object storage can be used in a variety of IoT
use cases, such as smart cities for storing video surveillance footage,
connected vehicles for storing sensor data, and industrial IoT for storing
machine data.

Dr. Uma Narayanan, CSE, RSET


 Time-Series Databases:
 Advantages: Time-series databases are designed to handle time-stamped
data, making them an ideal storage option for IoT applications that
generate data in real-time. They offer fast data ingestion, indexing, and
querying, enabling real-time analytics and insights.
 Examples of IoT use cases: Time-series databases are used in a variety of
IoT use cases, such as smart homes for monitoring energy usage,
connected healthcare for monitoring patient vitals, and precision
agriculture for monitoring crop conditions.

Dr. Uma Narayanan, CSE, RSET


 Edge Storage:
 Advantages: Edge storage refers to the storage of data on IoT devices or
gateways at the edge of the network, rather than in a centralized cloud.
This reduces the latency and bandwidth requirements of sending all data
to the cloud, enabling faster response times and lower costs. It also
provides greater security and privacy for sensitive data.
 Examples of IoT use cases: Edge storage can be used in a variety of IoT
use cases, such as industrial IoT for storing machine data locally, smart
cities for storing video footage locally, and connected vehicles for storing
sensor data locally.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Web Application Messaging Protocol (WAMP) is a sub-protocol of Websocket
which provides publish-subscribe and remote procedure call (RPC)
messaging patterns.
 Using WAMP for IoT allows you to build web applications that can
communicate with IoT devices in real-time. This can be useful in a variety of
scenarios, such as controlling devices remotely, monitoring sensor data, or
collecting data from multiple devices.
 To use WAMP for IoT, you would typically set up a WAMP router, which acts as
a centralized hub for sending and receiving messages between devices and
web applications. Devices would then connect to the router and send
messages using the WAMP protocol, while web applications would connect to
the router and subscribe to messages from devices.
 WAMP routers can be implemented using a variety of programming
languages and frameworks, including Python, Node.js, and Java. For example,
you could use the Crossbar.io framework to set up a WAMP router in Python.
Dr. Uma Narayanan, CSE, RSET
 Transport: Transport is 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 publish-
subscribe model client can have 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.

Dr. Uma Narayanan, CSE, RSET


 In RPC model client can have 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 back to the caller.
 Router: Routers are peers that perform generic call and event routing. In
publish-subscribe model Router has the role of a Broker:
 – Broker: Broker acts as a router and routes messages published to a topic to all
subscribers subscribed to the topic.
 In RPC model Router has the role of a Broker:
 – Dealer: Dealer acts a router and routes RPC calls from the Caller to the
Callee and routes results from Callee to Caller.
 Application Code: Application code runs on the Clients (Publisher,
Subscriber, Callee or Caller)
Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
Dr. Uma Narayanan, CSE, RSET
1.Install Autobahn: Install the Autobahn framework on the computer that will
act as the WAMP router. You can do this using pip, the Python package
manager, with the command pip install autobahn.
2.Configure the router: Create a configuration file for the WAMP router using
the Autobahn configuration format. This file should include settings for the
router's IP address, port, realm, and authentication credentials. You can also
configure the router to use SSL encryption for secure communication.
3.Start the router: Start the WAMP router by running the crossbar start
command in the command prompt or terminal. This will start the router and
connect it to the configured network interface.
Dr. Uma Narayanan, CSE, RSET
4.Connect devices to the router: Devices can connect to the WAMP router using
the Autobahn Python library, which provides a client implementation of the
WAMP protocol. Devices can connect to the router by specifying the router's IP
address, port, and realm, and providing any necessary authentication
credentials.
5.Subscribe to messages: Devices can subscribe to topics on the WAMP router to
receive messages from other devices or web applications. To do this, devices can
use the subscribe method provided by the Autobahn Python library, and specify
the topic they wish to subscribe to.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Django is an open source web application framework for developing web
applications in Python.
 A web application framework in general is a collection of solutions,
packages and best practices that allows development of web applications
and dynamic websites.
 Django is based on the Model-Template-View architecture and provides a
separation of the data model from the business rules and the user
interface.
 Django provides a unified API to a database backend.

Dr. Uma Narayanan, CSE, RSET


 Web applications built with Django can work with different databases
without requiring any code changes.
 With this fiexibility in web application design combined with the powerful
capabilities of the Python language and the Python ecosystem, Django is
best suited for cloud applications.
 Django consists of an object-relational mapper, a web templating system
and a regular-expression- based URL dispatcher

Dr. Uma Narayanan, CSE, RSET


 Django provides a robust web application framework that can be used to
create IoT dashboards, control panels, and web interfaces for IoT devices.
 Django includes a built-in ORM (Object-Relational Mapping) that allows for
easy database management, which can be used to store data collected from
IoT devices.
 Django can be used to develop REST APIs, which can be used to send and
receive data between IoT devices and web applications.
 Django has built-in support for user authentication and authorization, which
can be used to secure access to IoT devices and data

Dr. Uma Narayanan, CSE, RSET


 Django supports real-time communication through the use of
WebSockets, which can be used to send and receive real-time data from
IoT devices.
 Django includes a number of third-party packages and libraries that can
be used for IoT, such as Django Channels for handling WebSockets,
Django REST framework for building REST APIs, and Django MQTT for
communicating with MQTT brokers.
 Django can be deployed on a variety of platforms, such as cloud
providers like AWS or Azure, or on-premises servers, making it a
versatile option for IoT applications.

Dr. Uma Narayanan, CSE, RSET


 Model: This represents the data and database schema of your application. It
defines the structure of your data and how it is stored in the database. Django
provides a built-in Object-Relational Mapping (ORM) layer that allows you to
interact with the database using Python classes.
 View: In Django, a view is a Python function that takes a web request and
returns a web response. The view function is responsible for processing the
request and generating the response. The response can be an HTML page,
JSON data, or any other format.
 Template: A template is a file that defines the structure and layout of your
web pages. It is responsible for rendering the data returned by the view
function into HTML that can be displayed in a browser.

Dr. Uma Narayanan, CSE, RSET


 Install Django: Make sure you have Django installed on your system. You
can use the command pip install django to install it.
 Create a new Django project: Use the command django-admin
startproject projectname to create a new Django project. This will create
a new directory with the name projectname that contains the basic
structure for a Django project.
 Create a new app: Use the command python manage.py startapp
appname to create a new Django app. This will create a new directory
with the name appname inside the projectname directory.
 Define the app's models: In the models.py file of your app, define the
data models that your app will use. This includes creating classes that
represent database tables and defining the fields of those tables.

Dr. Uma Narayanan, CSE, RSET


 Create database tables: Use the command python manage.py
makemigrations appname to create migrations for your app's models.
Then, use the command python manage.py migrate to apply those
migrations and create the database tables.
 Define views: In the views.py file of your app, define the functions that
will handle HTTP requests and generate responses. These views can
render templates or return JSON data, depending on the needs of your
app.
 Define URLs: In the urls.py file of your app, define the URLs that will be
used to access your views. This includes mapping URLs to specific view
functions.

Dr. Uma Narayanan, CSE, RSET


 Define templates: In the templates directory of your app, create
HTML templates that will be used to render the user interface of
your app.
 Run the development server: Use the command python
manage.py runserver to start the development server. You can
then access your app in a web browser by visiting
http://localhost:8000/.

Dr. Uma Narayanan, CSE, RSET


 #Create a new project  #Install MySQL
django-admin.py startproject  sudo apt-get install mysql-server mysql-
blogproject client
 #Create an application within the sudo mysqladmin -u root -h localhost
project password 'mypassword‘
python mangage.py startapp myapp  #Configuring a Database
 #Starting development server
 python manage.py runserver
#Django uses port 8000 by default
#The project can be viewed at the URL:
#http://localhost:8000

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Define the resources: Identify the resources that your API needs to expose.
A resource is anything that can be accessed or manipulated through the
API. Examples of resources might include users, products, or orders.
 Identify the operations: For each resource, identify the operations that
clients should be able to perform. Common operations include GET
(retrieve a resource), POST (create a new resource), PUT (update an
existing resource), and DELETE (delete a resource).
 Define the URL structure: Define a URL structure that allows clients to access
the resources and operations in your API. Use a consistent and intuitive URL
structure that is easy to understand and remember.
 Define the request and response formats: Define the format of requests and
responses for each operation. Use a standard format such as JSON or XML
to ensure that clients can easily parse and generate requests and
responses.
Dr. Uma Narayanan, CSE, RSET
 Define the authentication and authorization mechanism: Define the
authentication and authorization mechanism to ensure that only
authorized clients can access your API.
 Define error handling: Define the error handling mechanism to return
appropriate error responses in case of errors.
 Define the API documentation: Document the API using tools like
Swagger or OpenAPI to make it easy for clients to understand and use
your API.
 Test the API: Test the API using a tool like Postman to ensure that it
works as expected.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET
 Amazon Web Services (AWS): AWS provides a range of services for IoT,
including AWS IoT Core, AWS IoT Analytics, and AWS Greengrass. These
services allow users to securely connect, manage, and process data from
IoT devices, and build scalable IoT applications.
 Microsoft Azure IoT: Azure IoT provides a suite of tools and services for
building and managing IoT applications, including Azure IoT Hub, Azure
IoT Edge, and Azure Stream Analytics. These services allow users to
connect, manage, and process data from IoT devices, and build
intelligent and scalable IoT applications.
 Google Cloud IoT: Google Cloud IoT provides a range of tools and
services for building and managing IoT applications, including Google
Cloud IoT Core, Google Cloud IoT Edge, and Google Cloud Pub/Sub.
These services allow users to securely connect, manage, and process
data from IoT devices, and build scalable and intelligent IoT
applications.
Dr. Uma Narayanan, CSE, RSET
 IBM Watson IoT: IBM Watson IoT provides a suite of services for building
and managing IoT applications, including Watson IoT Platform, Watson
IoT Edge, and Watson IoT Analytics. These services allow users to
securely connect, manage, and analyze data from IoT devices, and build
scalable and intelligent IoT applications.
 Oracle IoT: Oracle IoT provides a range of tools and services for
building and managing IoT applications, including Oracle IoT Cloud
Service, Oracle IoT Asset Monitoring Cloud, and Oracle IoT Fleet
Monitoring Cloud. These services allow users to securely connect,
manage, and process data from IoT devices, and build scalable and
intelligent IoT applications.

Dr. Uma Narayanan, CSE, RSET


 Boto is a Python package that provides
interfaces to Amazon Web Services
(AWS)
 In this example, a connection to EC2
service is fi rst established by calling
boto.ec2.connect_to_region.
 The EC2 region, AWS access key and
AWS secret key are passed to this
function. After connecting to EC2 , a new
instance is launched using the
conn.run_instances function.
 The AMI-ID, instance type, EC2 key
handle and security group are passed to
this function
Dr. Uma Narayanan, CSE, RSET
 AutoScaling Service
 A connection to AutoScaling service is first established
by calling boto.ec2.autoscale.connect_to_region
function.
 Launch Configuration
 After connecting to AutoScaling service, a new launch
configuration is created by calling
conn.create_launch_con f iguration. Launch
configuration contains instructions on how to launch
new instances including the AMI-ID, instance type,
security groups, etc.
 AutoScaling Group
 After creating a launch configuration, it is then
associated with a new AutoScaling group. AutoScaling
group is created by calling
conn.create_auto_scaling_group. The settings for
AutoScaling group such as the maximum and minimum
number of instances in the group, the launch
configuration, availability zones, optional load balancer
to use with the group, etc*
Dr. Uma Narayanan, CSE, RSET
 AutoScaling Policies
 After creating an AutoScaling group, the
policies for scaling up and scaling down
are defined.
 In this example, a scale up policy with
adjustment type ChangeInCapacity and
scaling_ad justment = 1 is defined.
 Similarly a scale down policy with
adjustment type ChangeInCapacity and
scaling_ad justment = -1 is defined.

Dr. Uma Narayanan, CSE, RSET


 CloudWatch Alarms
 With the scaling policies defined, the next
step is to create Amazon CloudWatch alarms
that trigger these policies.
 The scale up alarm is defined using the
CPUUtilization metric with the Average
statistic and threshold greater 70% for a
period of 60 sec. The scale up policy created
previously is associated with this alarm. This
alarm is triggered when the average CPU
utilization of the instances in the group
becomes greater than 70% for more than 60
seconds.
 The scale down alarm is defined in a similar
manner with a threshold less than 50%

Dr. Uma Narayanan, CSE, RSET


 In this example, a connection to S3 service
is first established by calling
boto.connect_s3 function.
 The upload_to_s3_bucket_path function
uploads the file to the S3 bucket specified
at the specified path.

Dr. Uma Narayanan, CSE, RSET


 In this example, a connection to RDS
service is first established by calling
boto.rds.connect_to_region function.
 The RDS region, AWS access key and AWS
secret key are passed to this function.
 After connecting to RDS service, the
conn.create_dbinstance function is called to
launch a new RDS instance.
 The input parameters to this function
include the instance ID, database size,
instance type, database username,
database password, database port,
database engine (e.g. MySQL5.1), database
name, security groups, etc.
Dr. Uma Narayanan, CSE, RSET
 In this example, a connection to DynamoDB
service is first established by calling
boto.dynamodb.connect_to_region.
 After connecting to DynamoDB service, a
schema for the new table is created by
calling conn.create_schema.
 The schema includes the hash key and
range key names and types.
 A DynamoDB table is then created by
calling conn.create_table function with the
table schema, read units and write units as
input parameters.
Dr. Uma Narayanan, CSE, RSET
 Amazon Kinesis is a fully managed commercial service that allows real-
time processing of streaming data.
 Kinesis scales automatically to handle high volume streaming data
corning from large number of sources.
 The streaming data collected by Kinesis can be processed by
applications running on Amazon EC 2 instances or any other compute
instance that can connect to Kinesis.
 Kinesis is well suited for IoT systems that generate massive scale data
and have strict real-time requirements for processing the data.
 Kinesis enables users to process and analyze data in real-time using
various tools like AWS Lambda, Kinesis Data Analytics, and Kinesis Data
Firehose.
Dr. Uma Narayanan, CSE, RSET
 Amazon Simple Queue Service (SQS) is a fully managed message
queuing service offered by Amazon Web Services (AWS).
 It enables decoupling and scaling of microservices, distributed
systems, and serverless applications.
 Amazon SQS offers a highly scalable and reliable hosted queue for
storing messages as they travel between distinct components of
applications.
 SQS guarantees only that messages arrive, not that they arrive in the
same order in which they were put in the queue.
 While Kinesis is meant for real-time applications that involve high data
ingress and egress rates, SQS is simply a queue system that stores and
releases messages in a scalable manner.
Dr. Uma Narayanan, CSE, RSET
 Amazon Elastic MapReduce (EMR) is a cloud-based big data processing
service offered by Amazon Web Services (AWS).
 Amazon EMR is a web service that utilizes Hadoop framework running
on Amazon EC2 and Amazon S3.
 It enables you to easily process vast amounts of data using open-source
tools such as Apache Hadoop, Apache Spark, Apache Hive, Apache
HBase, and more.
 EMR allows processing of massive scale data, hence, suitable for IoT
applications that generate large volumes of data that needs to be
analyzed.
 Data processing jobs are formulated with the MapReduce parallel data
processing model.
Dr. Uma Narayanan, CSE, RSET
 MapReduce is a parallel data processing model for processing and
analysis of massive scale data.
 MapReduce model has two phases: Map and Reduce.
 MapReduce programs are written in a functional programming style to
create Map and- Reduce functions. The input data to the map and
reduce phases is in the form of key-value pairs.
 EMR allows you to process and analyze various types of data such as log
files, genomic data, and social media data.

Dr. Uma Narayanan, CSE, RSET


Dr. Uma Narayanan, CSE, RSET

You might also like