UNIT 3 Developing IoTs-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

UNIT –III

DEVELOPING IOTs

IoT design methodology - Motivation for using Python- Logical

Design using Python - Control Flow – Packages - File Handling -

Classes - Python Packages of Interest for IoT - Case Study on IoT

System for Weather Monitoring


IoT design methodology
IoT design methodology

• Designing IoT systems can be a complex and challenging task as


these systems involve interactions between various components.
• A wide range of choices are available for each component.
• IoT designers often tend to design the system keeping specific
products in mind.
• IoT systems designed with this methodology will have reduced
design time, testing time, maintenance time, complexity and better
interoperability.
Steps:
1. Purpose and Requirements Specification

• First step is to define the purpose and requirements of the system. In


this step, the system purpose, behavior and requirements are
captured.
• Requirements can be:
 Data collection requirements
 Data analysis requirements
 System management requirements
 Security requirements
 User interface requirements
2. Process Specification
• The use cases of the IoT system are formally described based on or derived
from the purpose and requirements specifications.
• The process specification for home automation system is as shown below.
3. Domain Model Specification
• The domain model describes the main concepts, entities and objects
in the domain of the IoT system to be designed.
• Domain model defines the attributes of the objects and relationships
between objects.
• The domain model is independent of any specific technology or
platform.
• Using domain model, system designers can get an understanding of
the IoT domain for which the system is to be designed.
• The entities, objects and concepts defined in the domain model of
home automation system include the following:
4. Information Model Specification
• Information model defines the structure of all the information
in the IoT system.
• Does not describe how the information is stored and
represented.
• To define the information model, we first list the virtual
entities.
• Later more details like attributes and relationships are added.
• The information model specification for home automation
system is as shown below:
Information Model Specification for Home Automation
5. Service Specifications

The service specification defines the following:


• Services in the system
• Service types
• Service inputs/output
• Service endpoints
• Service schedules
• Service preconditions
• Service effects
6. IoT Level Specification
• Based on the requirements we
will choose the IoT application
deployment level.
• The deployment level for home
automation system is shown in the
below figure.
7. Functional View Specification

• The functional view defines the functions of the IoT systems


grouped into various functional groups.
• Each functional group provides functionalities for interacting with
concepts in the domain model and information related to the
concepts.
• The functional groups in a functional view include: Device,
Communication, Services, Management, Security, and Application.
• The functional view specification for home automation system is
shown in the below figure:
8. Operational View Specification

In this step, various options related to the IoT system deployment and
operation are defined, such as:
• Service hosting options
• Storage options
• Device options
• Application hosting options
9. Device and Component Integration
• In this step the devices like sensors, computing devices and
other components are integrated together.
• The interconnection of different components in our home
automation system are as shown in the figure given below.
10. Application Development
• Using all the information from previous steps, we will develop the
application (code) for the IoT system.
• The application interface for home automation system is shown
below.
Control Flow
Control Flow

• Python program control flow is regulated by various types


of conditional statements, loops, and function calls.
Control Flow
 if statement
 for statement
 while statement
 range statement
 break/continue statement
 pass statement
Control Flow-if statement
• The if statement in Python is similar to the if statement in
other languages.
Control Flow-for statement
• 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 an initialization, incrementing and stopping
criteria are provided.
Control Flow-while statement
• The while statement in Python executes the statements within the
while loop as long as the while condition is true.
Control Flow-range statement
• The range statement in Python generates a list of numbers in
arithmetic progression.
Control Flow- break/continue statement
• The break and continue statements in Python are similar to the
statements in C.
Control Flow- pass statement
• 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.
Python Modules and Packages
Modules
#student module - saved as student.py #Using student module
• Python allows organizing the program def averageGrade(students): >>>import student
code into different modules which sum = 0.0 >>>students = '1': 'name': 'Bob', 'grade': 2.5,
improves the code readability and for key in students: '2': 'name': 'Mary', 'grade': 3.5,
management. sum = sum + students[key]['grade'] '3': 'name': 'David', 'grade': 4.2,
average = sum/len(students) '4': 'name': 'John', 'grade': 4.1,
'5': 'name': 'Alex', 'grade': 3.8
• A module is a Python file that defines return average

some functionality in the form of functions def printRecords(students): >>>student.printRecords(students)


or classes. print "There are %d students" %(len(students)) There are 5 students
i=1 Student-1:
• Modules can be imported using the import for key in students: Name: Bob
Grade: 2.5
keyword. print "Student-%d: " % (i)
Student-2:
print "Name: " + students[key]['name']
print "Grade: " + str(students[key]['grade']) Name: David
• Modules to be imported must be present i = i+1 Grade: 4.2
in the search path. Student-3:
Name: Mary
# Importing a specific function from a module Grade: 3.5
>>>from student import averageGrade Student-4:
Name: Alex
# Listing all names defines in a module Grade: 3.8
>>>dir(student) Student-5:
Name: John
Grade: 4.1

>>>avg = student. averageGrade(students)


>>>print "The average garde is: %0.2f" % (avg)
3.62
Book website: http://www.internet-of-things-book.com Bahga & Madisetti, © 2015
Packages

• Python package is hierarchical file structure that consists of # skimage package listing
modules and subpackages. skimage/ Top level package
__init__.py Treat directory as a package
• Packages allow better organization of modules related to a single
application environment. color/ color color subpackage
__init__.py
colorconv.py
colorlabel.py
rgb_colors.py

draw/ draw draw subpackage


__init__.py
draw.py
setup.py

exposure/ exposure subpackage


__init__.py
_adapthist.py
exposure.py

feature/ feature subpackage


__init__.py
_brief.py
_daisy.py
...

Book website: http://www.internet-of-things-book.com Bahga & Madisetti, © 2015


File Handling
File Handling

• Python allows reading and writing to files using the file object.
• The open(filename, mode) function is used to get 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.
File Handling - Examples
Ex: To use seek function to set the position of the file pointer within
a file
Data.txt file: PrepBytes is an Ed-Tech Company

file=open(“data.txt”,’r’)
file.seek(10)
data=file.read(5)
print(data)
file.close() Output: is an
Python Packages of Interest for IoT
Python Packages of Interest for IoT

• JSON
• XML
• HTTPLib & URLLib
• SMTPLib
• NumPy
• Scikit-learn
Python Packages of Interest for IoT
JSON
• Java Script Object Notation (JSON) is an easy to read and write data-
interchange format.
• It is an alternative to XML and is easy for machines to parse and generate.
• It is built on two structures- a collection of name-value pairs (eg:-a Python
dictionary) and ordered lists of values (eg:- a Python List)

XML
• XML (Extensible Markup Language) is a data format for structured document
interchange.
• The Python minidom library(accessing and modifying XML documents)
provides a minimal implementation of the document object model interface
and has API similar to that in other languages.
Python Packages of Interest for IoT

HTTPLib & URLLib


• HTTPLib2 and URLLib2 are Python libraries used in network/
internet programming.
• URLLib2 - handles opening and reading URLs.
• HTTPLib2 - handles http request
SMTPLib
• Simple Mail Transfer Protocol (SMTP) is a protocol which handles
sending email and routing e-mail between mail servers.
• The Python smtplib module provides an SMTP client session object
that can be used to send email.
Python Packages of Interest for IoT
NumPy
• NumPy is a package for scientific computing in Python.
• NumPy provides support for large multi-dimensional arrays and
matrices.
Scikit-learn
• It is an open source machine learning library for Python that
provides implementations of various machine learning algorithms
for classification, clustering, regression and dimension reduction
problems.
Case Study on IoT System for Weather
Monitoring
Weather Monitoring
• The purpose of the weather monitoring system is to collect data on
environmental conditions such as temperature, pressure, humidity
and light in an area using multiple end nodes.
• The end nodes send the data to the cloud where the data is
aggregated and analyzed.
• Weather alerts can be sent to the subscribed users from such
applications.
• AirPi is a weather and air quality monitoring kit capable of
recording and uploading information about temperature, humidity,
air pressure, light levels, UV levels, carbon monoxide, nitrogen
dioxide and smoke level to the internet.
AirPi
Weather Monitoring
Weather Monitoring
• Here, the tier 1 provides information about the parameters under the
region which is to be monitored for noise and air pollution control.
• Tier 2 deals with the sensor devices with suitable characteristics,
features and each of these sensor devices are operated and controlled
based on their sensitivity as well as the range of sensing.
• In between tier 2 and tier 3 necessary sensing and controlling actions
will be taken depending upon the conditions, like fixing the
threshold value, periodicity of sensing, messages (alarm or buzzer or
LED) etc.
• Based on the data analysis performed in between tier 2 and tier 3
and also from previous experiences the parameter threshold values
during critical situations or normal working conditions are
determined.
Weather Monitoring
• Tier 3 describes about the data acquisition from sensor devices and also
includes the decision making.
• In the proposed model tier 4 deals with the intelligent environment,
Which means it will identify the variations in the
sensor data and fix the threshold value depending
on the identified level of CO or noise levels.
• In this tier sensed data will be processed, stored
in the cloud i.e.in to the Google spread sheets and
also it will show a trend of the sensed parameters with
respect to the specified values.
• The end users can browse the data using mobile phones, PCs etc.
Weather Monitoring (Controller Service)
• The controller service run as a native service on the device and
monitors temperature, pressure, humidity and light once every 15
seconds.
• The controller service calls the REST service to store these
measurements in the cloud.
Weather Monitoring
(Deployment design for the system)
Weather Monitoring
(Deployment design for the system)

You might also like