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

IoT Advance Complete Notes

Uploaded by

Riya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

IoT Advance Complete Notes

Uploaded by

Riya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 173

INTERNET OF THINGS (ADVANCE)

UNIT 1
PYTHON BASICS
LECTURE 1

INTRODUCTION
What is Python?
• Python is a high-level programming language created by Guido Van Rossum.
• Python was first released in 1991.
• Today Python interpreters are available for many Operating Systems including
Windows and Linux.
Reasons for Popularity
❑ Free:
Python is free to use and distribute. It is supported by community. Python interpreter
is available for every major platform.
❑ Software quality:
Better than traditional and scripting languages. Readable code, hence reusable and
maintainable.
❑ Developer productivity:
Much better than statically typed languages. Much smaller code. Less to type, debug
and maintain. No lengthy compile and link steps.
❑ Program portability:
Python programs run unchanged on most platforms. Porting program to a new
platform usually need only cut and paste. This is true even for GUI, DB access,
Web programming, OS interfacing,

Where is Python used?

Python is used for multiple purposes. These include:


(a) System programming
(b) Building GUI applications
1|Page
INTERNET OF THINGS (ADVANCE)

(c) Internet scripting


(d) Component integration
(e) Database programming
(f) Rapid prototyping
(g) Numeric and Scientific programming
(h) Game programming
(i) Robotics programming

Many organizations use Python for varied purposes. These include:


(a) Google - In web search system
(b) YouTube - Video Sharing service
(c) Bit-torrent - Peer to Peer file sharing system
(d) Intel, HP, Seagate, IBM, Qualcomm - Hardware testing
(e) Pixar, Industrial Light and Magic - Movie animation
(f) JP Morgan, Chase, UBS - Financial market forecasting
(g) NASA, FermiLab - Scientific programming
(h) iRobot - Commercial robot vacuum cleaners
(i) NSA - Cryptographic and Intelligence analysis

Python Specification

Python is a specification for a language that can be implemented in different ways.


There are many implementations of this specification written in different languages.

Different popular Python implementations are:


❖ CPython is the reference implementation, written in C.
❖ PyPy - Written in a subset of Python language called RPython.

2|Page
INTERNET OF THINGS (ADVANCE)

❖ Jython - Written in Java.


❖ IronPython - Written in C#.
All the implementations are compilers as well as interpreters. The compiler converts
the Python program into intermediate bytecode. This bytecode is then interpreted by
the interpreter.

3|Page
INTERNET OF THINGS (ADVANCE)

UNIT 1
PYTHON BASICS
LECTURE 2
INSTALLATION OF PYTHON
Python Installation under Windows
• Python has evolved over the years. The latest version for Windows and Linux
environments was Python 3.8.2.
• Python is not shipped as part of Windows OS. So, we need to install it
separately. For this we need to download the Python installer from
www.python.org/downloads/. (http://www.python.org/downloads/.) While
downloading ensure that you choose the appropriate installer from the following,
based on whether you wish to install it on a 32- bit machine or a 64-bit machine:
❖ 64-bit machine: Download Windows x86-64 executable installer
❖ 32-bit machine: Download Windows x86 executable installer
• Once you have chosen and downloaded an installer, execute it by double-
clicking on the downloaded file. A dialog shown in Figure will appear on the
screen.
• In this dialog check the check box 'Add Python 3.8 to PATH'

• Click on 'Install Now' and the installation will happen in a few minutes. Python
files will get installed in the directory:
4|Page
INTERNET OF THINGS (ADVANCE)

C:\Users\SAS\AppData\Local\Programs\Python\Python38-32
• In this path ‘SAS' will be substituted by your user’s name and 'Python38-32' by
version number of Python installation that you have downloaded and installed.
WORKING WITH PYTHON
▪ Once Python is installed, program development can be done using the built-in
Python Integrated Development and Learning Environment (IDLE).
▪ IDLE is a software application that helps programmers develop software code
efficiently.
▪ IDLE is a good development tool. It offers handy features like syntax
highlighting, context-sensitive help and debugging.
▪ Syntax highlighting feature display keywords, functions, methods and strings in
different colors making it easy to identify them.
Program development in Python can be done in 3 ways:
• Using built-in IDLE.
• Using third-party IDEs.
• Using online Python shells.
1. Using Built in IDLE
It is basic integrated learning platform available with the standard python package. It
need not be installed separately. Debuggers are commonly used in built IDLE.
2. Using third-party IDEs
There are third-party packages available for doing almost everything. For Example:
• NumPy: Advanced mathematical operations library with support for large multi-
dimensional arrays and matrices.
• SciPy: Scientific computing library for optimization, integration, interpolation,
signal processing, image processing, etc.
• Pandas: Library for manipulating numerical tables and time series.
• Matplotlib: 2D and 3D Data visualization library.
• OpenCV: Open-source Computer vision library.
3. Using online Python shells.
If you do not wish to install any Python development tool on your machine, then you
can use any of the following online Python shells:
5|Page
INTERNET OF THINGS (ADVANCE)

• https://www.python.org/shell/ (https://www.python.org/shell/)
• https://ideone.com/ (https://ideone.com/)
• https://repl.it/languages/python3 (https://repl.it/languages/python3)
More Sophisticated Tools
Many tools have come into existence to help Python programmers build and
document their program or scripts. These include:
1. Jupyter Notebook - It is a very flexible browser-based tool that lets us to
interactively work with Python (and many other languages). It lets us put our
Python code, output of the code and any kind of visualization or plot etc. in the
same document called Notebook. It is a great tool doing modular program
development.
2. Google Colab - This tool provides a free Jupyter notebook environment to
execute code on Google's cloud servers. As a result, you can leverage the
power of Google's hardware.
3. Spyder - This tool provides a Scientific Python Development Environment with
sophisticated testing and debugging features.
Both Jupyter and Spyder are part of a very popular software distribution called
Anaconda. So, once you download and install Anaconda, you get Jupyter and Spyder
ready-made.

6|Page
INTERNET OF THINGS (ADVANCE)

UNIT 1
PYTHON BASICS
LECTURE 3
PYTHON PRINT FUNCTION ()
The word print is a Function in Python.

What is a function?
A function is a block of code that can perform a specific action. In addition to this,
these blocks of code don’t execute until you call the function.

There are two types of Functions in Python

• Built-in functions - The functions that are pre-defined in Python are known as
Built-in functions.
• User-defined functions - The functions that are created by the programmers
or developers in Python are called User-defined functions.

The function print () takes zero or more arguments and displays them on the screen.
The print () is sending the data to an output device, i.e., console. The print () function
does not evaluate anything.

Types of print () functions


1. Empty print () Statement
It is the Python print function without any arguments. It simply prints a new line.

Let's see it practically. Open the IDE and run the following code:

# empty print statement


print()

7|Page
INTERNET OF THINGS (ADVANCE)

2. Single Argument print () statement


It is a print statement with single argument

Let's see an example.

# argument with quotes


print("ToolsQA")
Note: You can also use the single-quotes in place of double-quotes. In other words,
both work the same in Python.

3. Multiple Argument print () statement


It is a print statement with multiple arguments

8|Page
INTERNET OF THINGS (ADVANCE)

Another example:

# demonstrating new line with empty print statement


print("ToolsQA")
print()
print("Python PCEP Course")

You can see a line in between the "ToolsQA" and "Python PCEP Course". As
mentioned, the empty print statements give us a new line.

What happens when we pass multiple lines as an argument to the print function.
Let's see it.

# multiple lines in a print statement


print ("ToolsQA
Python PCEP Course")

9|Page
INTERNET OF THINGS (ADVANCE)

Consequently, add quotes at the end of the first-line text and start of the second-line
text. You can see the code in the block below.

10 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 1
PYTHON BASICS
LECTURE 4
ESCAPE CHARACTER SEQUENCE

What is an Escape Character?

• The programmers call the "backslash (\)" character as an escape character.

• In other words, it has a special meaning when we use it inside the strings.

• As the name suggests, the escape character escapes the characters in a string
for a brief moment to introduce unique inclusion.

• Backlash signifies that the next character after it has a different meaning. It
could be printing double quotes or indicating a new line.

• Let's see what escape sequences are and how to use them in Escape
Sequences in Python.

Common Escape Sequences in Python

The sequence of characters after a backslash is known as an escape sequence.

Moreover, in Python, we have different escape sequences that have a unique


meaning.

Let's see the most common examples of escape sequences.

a) \" and \'


Let’s try to print "ToolsQA" using print(""ToolsQA"") statement, we will get an error.
It's because of the quotes that we have used in the text. We have used double quotes
to close the text and, at the same time, used double quotes inside the outer pair of
double-quotes.

11 | P a g e
INTERNET OF THINGS (ADVANCE)

It confuses the interpreter. In other words, the interpreter accepts only one pair of
quotes of a similar type. But, in our example, we have a double pair of the same kinds
of quotes.

That's the reason why we get an error. Consequently, run the same example and see
the output.

Examples:

# wrong quotes
print(""ToolsQA"")

Put a backslash before the quote that you wish to have in your text. Let's run the code
below.

# double-quotes inside a doubled quotes


print("\"ToolsQA\"")

12 | P a g e
INTERNET OF THINGS (ADVANCE)

In other words, we have used the double quote and backslash in combination (\").
That combination is one of the escape sequences in Python. This escape sequence
tells Python that it needs to remove the backslash and put the quote in the string.

b) \ - Double Backslash Escape Sequence


We know how to print double quotes and single quotes but what if we need to print
the backslash () itself? From what we have learned so far, we will probably write the
below code. Therefore, let's try to run it.

# trying to print \
print("\")

13 | P a g e
INTERNET OF THINGS (ADVANCE)

Python gives an error. When you write \, Python expects an escape sequence. But
there is no escape sequence in the text.
So we got an error. To print a backslash, we have to use the double backslashes (\\).
Let's try it.
# trying to print \
print("\\")

c) \n - New Line Escape Sequence

\n means a new line. We will get a new line when we use the escape sequence \n in
the print function. Let's see what happens when we put the escape sequence \n in
the middle of the text.

14 | P a g e
INTERNET OF THINGS (ADVANCE)

# \n usage
print("I am from\nToolsQA")
Can you guess the output? I think most of you already guessed it.

d) \t - Tab Space Escape Sequence

It gives a tab space in the output. Let say we have a text "I am from\tToolsQA", then
the output will contain a tab space between the words from and ToolsQA. Additionally,
let's see the example in IDE.

# \t usage
print("I am from\tToolsQA")

15 | P a g e
INTERNET OF THINGS (ADVANCE)

16 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 1
PYTHON BASICS
LECTURE 5
PYTHON VARIABLES

What is Literal?

Literals are some data that can be identified by themselves. For example, if you take
a number 759, we can quickly recognize it by simply seeing it.

Any data that can be recognized by seeing is known as a literal.

Some examples of literals are 151, 7.59, 0.11, "ToolsQA," etc. We have used
double-quotes for the ToolsQA example, and it is a string literal. So far, we have
mentioned it as a text. The real number 7.59, 0.11 is known as floats.

What are Data Types?

A specific kind of data item defined by its value is known as Data Types.

Now we know that the values are literals.

Python divided the literals into four different types of data.

Data types are the building blocks for any programming language.

Python Data types

Python Data types are:

1. Integers
2. Floats
3. Characters
4. Strings
5. Booleans

1. Python Data Type - Integer

The numbers that don't have any fractional parts are known as Integers.
17 | P a g e
INTERNET OF THINGS (ADVANCE)

It can be positive, negative, or zero. See the integers number line.

Some examples of integers are 759, -759, 123, 4, -5, etc.

How to represent integers in Python.

We can use the integers directly as we use it generally. In other words, there is no
special notation for the integers in Python.

Run the following example code.

What if we want to store large numbers like 123,456,789?

Python doesn't allow us to put commas in between the digits of a number. Let's see
what happens if we write them in the print statement?
18 | P a g e
INTERNET OF THINGS (ADVANCE)

We didn't get any errors. In other words, the print statement takes them as three
different numbers and prints them.

But that's not what we want. We want the entire number as 123456789. So, in order
to write long integers we do the following.

Using underscore (_ ) in place of the comma (,) and space ( ) in the number, we can
achieve the goal.

Examples

19 | P a g e
INTERNET OF THINGS (ADVANCE)

How to represent negative integers?

Use the hyphen (-) before the number to make it a negative number. In other words,
everything else is similar to a positive number. If we don't put a hyphen (-) before a
number, then Python considers it as a positive integer.

Example with negative integers.

int() function
The function int () helps to convert a string or float into an integer.

The function int(argument) takes an optional argument. Therefore, if we don't pass


anything to the int () function, then it returns a zero.

Let's see some examples of the conversion of other data types into an integer.

Examples

# converting string literal to integer

print(int("123"))

20 | P a g e
INTERNET OF THINGS (ADVANCE)

# converting string literal to integer

print(int("ToolsQA2019"))

If you pass float to the int() function, it returns the integer part of the float. In other
words, say you pass the value 7.59 to the int() function. It returns the integer part,
i.e., 7.

# converting string literal to integer

21 | P a g e
INTERNET OF THINGS (ADVANCE)

print(int(7.59))

2. Python Data Type - Floats


Floats contain values with fractional parts.

It has values both before and after the decimal point.

They have a unique name in programming called floating-point numbers.

Examples of floating-point numbers are 7.59, -95.7, .7, 7., etc.

# floating-point numbers

print(7.59)

As shown above, we are printing the floating-point number.

22 | P a g e
INTERNET OF THINGS (ADVANCE)

Scientific Notation

If the floating-point values are huge numbers, then we will use scientific notation to
represent them. In other words, we have to use the alphabet e or E in the scientific
notation.

If you see the number 7590000000000.0, it is complicated to type all the zeroes. In
other words, instead of typing all the zeroes, we can represent it as 759 x 1010, which
is 759E10 in scientific notation.

7590000000000.0 = 759x1010 = 759E10

In scientific notation, the part after the E must be an integer. In addition to this, before
part of the E may be integer or float. Let's see some examples.

• 7.59 x 10-25 = 7.59e-25

• 0.000007 = 7 x 10-6 = 7E-6

Whenever we use E or e to represent a number, then it is a floating-point number in


Python. Let's do some practice

# floating-point numbers

print(0.000007)

23 | P a g e
INTERNET OF THINGS (ADVANCE)

As shown above, Python chooses the appropriate notation to display the floating-point
numbers based on the value.

Therefore, Python smartly chooses to represent the output in scientific notation.

float () function
The float () function works similar to the int () function.

It takes an object as an argument and returns the value as a float-point value.

Examples for the conversion in the code below.

24 | P a g e
INTERNET OF THINGS (ADVANCE)

3. Python Literal - Characters


Char (or characters) is not a very important data type in Python.

It is merely a String which is of one character.

It is used to identify special characters and ASCII codes (American Standard Code
for Information Interchange).

Computers only understand the numbers (binary). What if we want to represent


characters like A, @, $? We want numbers to represent each character.

We have a method chr () in Python to convert a number into the respective character.

Also, ord () method work opposite to chr().

chr() and ord() functions


We can use the chr() function to convert an ASCII value into a character.

chr() function takes only one argument and returns the corresponding character.

# converting the 65 to character

print(chr(65))

The number that we have given is the ASCII value of A. Therefore; the output is A.

25 | P a g e
INTERNET OF THINGS (ADVANCE)

Similar to the chr(), we have ord() function that works opposite to the chr().

In other words, the ord() function takes any character and returns the ASCII value of
the given character.

For example, if you give character A to the ord(), then it returns the number 65 -
ASCII value of A.

# getting the ASCII value of A

print(ord('A'))

As a result, the output of the above code is 65.

26 | P a g e
INTERNET OF THINGS (ADVANCE)

4. Python Literal - Strings

Text that has single or double quotes at the starting and ending is known as a string.

Examples of strings are "ToolsQA," '759', etc. Moreover, there is no particular


representation for strings in Python. We can use the examples directly in Python
programs. Let's practice some coding.

Write the following code in the IDE and run it.

# string

print("ToolsQA")

Consequently, the output of the above code is ToolsQA. Let's see the same example
with single-quotes.

# string

print('ToolsQA')

27 | P a g e
INTERNET OF THINGS (ADVANCE)

str()function
str() is similar to the functions int and float.

It helps to convert objects into a string.

And it takes one or zero arguments. In other words, if we don't pass anything to
the str() function, then it returns an empty string.

# str without any arguments

print(str())

As a result, the function str without any arguments returns an empty string.

See an example of converting the integer to a string. We can directly pass


the integer to the str function.

28 | P a g e
INTERNET OF THINGS (ADVANCE)

5. Python Literals - Boolean


Python literal Boolean has two values.

One is True, and another one is False.

Any non-zero value is True, and the value zero is False.


Additionally, 1 and 0 represent True and False, respectively.

Python has a method called bool() to convert any object into a Boolean value.

bool() function
The function bool() returns either True or False based on the argument.

It takes one or zero arguments.

If we didn't pass anything to the bool(), then it will return False.

For any non-zero value bool() returns True.

29 | P a g e
INTERNET OF THINGS (ADVANCE)

Let's see some examples.

# boolean value of a non-zero

print(bool(5))

The output of the above code is True. We have passed a non-zero value. Therefore,
it returns True.

# boolean value of zero

print(bool(0))

30 | P a g e
INTERNET OF THINGS (ADVANCE)

What is a Variable in Python Programming?


Variables are used to store the values.

Variables contain mainly two parts, one is a name, and another one is value.
Moreover, Values may be of different data types.

Python Variable Syntax

In Python, we use an operator called assignment operator(=) to assign or store the


values into a variable.

An assignment operator is nothing but equals to (=) symbol. The left side of the
assignment contains a name, the right side of the assignment includes a value.

variable_name = value

The variable_name is the name of the variable

The value is the information or data to be stored in the variable.

Python Variable Naming Convention


Python has some rules to define the names of variables. Therefore, we should follow
the below rules while naming the variables.

• Firstly, Python allows using only alphabets, digits, and underscores (_) for
the naming of variables.

• Secondly, Variable names must start with _ or alphabets. Moreover, the


alphabets may be lowercase or uppercase.

• Thirdly, we cannot use the built-in keywords of Python as a variable name.


Some keywords are reserved words of Python, which has unique functionality.

• Lastly, variables names in Python are case-sensitive, i.e., uppercase letters


are different from lowercase letters. For example, Techmec is different
from techmech.
31 | P a g e
INTERNET OF THINGS (ADVANCE)

Let's see some valid and invalid variables.

• _3 is a valid variable name, as it follows all the above rules.

• Techmech is also a valid name.


• 3Techmech is an invalid variable name, as it starts with a digit. We can't begin
the variable with a figure.
• tech@mech is an invalid name, as it contains a unique character @.
• Tech mech is an invalid name, as it contains a space.

We can't use keywords as variable names. Let's see some such keywords.

Python Keywords

Keywords are the reserved words in Python. Moreover, these keywords have
different meanings for various purposes. See the list of keywords.

['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']

We can't use the above keywords to name variables in our code. But we can use
them by changing the case of any letter in the keyword. For example,

We can't name our variable as follows, as print is a keyword in Python.

print

But, we can name our variable by changing the case of any letter in the keyword print.

Print

32 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 1
PYTHON BASICS
LECTURE 6
PYTHON OPERATORS

Introduction on Python Operators

Let's discuss a few terminologies.

2 + 3 is an expression. Moreover, + is an operator, and 2, 3 are operands.

• The combination of operators and operands is known as an expression.

• An operator is a symbol that can perform some operation on the data.

• For example, + can give you the sum of two numbers.

Python has different types of operators.


✓ Python Binary Operators

✓ Python Unary Operators

1. Python Binary Operators


It works on two operands. Some Important binary operators are:

Python Arithmetic Operators

Python Arithmetic operators take numeric values as operands and return a single
value as a result.

33 | P a g e
INTERNET OF THINGS (ADVANCE)

We have the following arithmetic operators in Python.

Symbol Operator

** Exponentiation

* Multiplication

/ Division

// Floor Or Integer Division

% Modulo

+ Addition

- Subtraction

Let's discuss these in detail.

a. Exponentiation Operator ()**

The symbol, double-stars ()**, is an exponential operator in Python.

The left operand of the operator is base and the right one is an exponent.

For example, we will represent the 2 to the power of 5 as 25. Conclusively, we can
calculate the value of 25 using the ** operator as 2 ** 5.

Try the following examples in IDE.

# exponential operator

print(2 ** 5)

print(2. ** 5)

print(2 ** 5.)

print(2. ** 5.)

34 | P a g e
INTERNET OF THINGS (ADVANCE)

• Firstly, when all the operands of exponentiation are integers, then the result is
an integer too.

• Secondly, when at least one operand is a float, then the result is a float.

b. Multiplication Operator () in Python*

The multiplication operator multiplies any two numbers and gives the result.

We represent it using the asterisk ()* symbol in Python.

Let's run the below code:

35 | P a g e
INTERNET OF THINGS (ADVANCE)

The multiplication operator also follows the same rules as exponentiation for
calculating integer or float values.

c. Division Operator (/) in Python

The division operator helps to divide a number with another number. We can
recognize the division operator using the symbol slash (/).

See the below code.

36 | P a g e
INTERNET OF THINGS (ADVANCE)

The result of the division operator is always a float irrespective of the type of
operands.

d. Floor Or Integer Division (//) in Python

The double slash (//) is the symbol used to represent floor division (or Integer
division).

It will round off the result to an integer value.

For example,

# floor division operator

print(5 // 2)

print(5. // 2)

print(5 // 2.)

print(5. // 2.)

37 | P a g e
INTERNET OF THINGS (ADVANCE)

If you see the output/ result of the first operation, i.e., integer by integer is an integer
value. Similarly, the remaining results are floats. Moreover, it's on the same lines as
exponentiation and multiplication.

The rounding off happens to the nearest integer value that is less than the actual
result. In the above case, the nearest integer that is less than 1.5 is 1. For example,

print (11//3) = 3

print (5//5) = 1

Let's try some negative numbers now.

print(3 // -2)

print(-3. // 2)

The result of the code with / operator is -1.5 and -1.5. The floor division (//) rounds
the result to the nearest and lesser integer value. That is to say, -2 is lesser than
-1. Therefore, the output is -2 and -2.0.

e. Modulo Operator (%) in Python

The percent (%) sign is the symbol to represent the modulo operator.

It will give you the remainder left after performing the floor division.

The result of the expression 5 % 2 is 1.

Let's run the following example.

# modulo operator

print(5 % 2)

38 | P a g e
INTERNET OF THINGS (ADVANCE)

f. Addition Operator (+) in Python

We have to use the plus (+) sign for the addition operation.

It gives the sum of the operands.

For example,

g. Subtraction Operator (-) in Python

We use the same minus (-) that we use in the usual maths for subtraction.

For example,

39 | P a g e
INTERNET OF THINGS (ADVANCE)

2. Unary Operators (+, -) in Python


The operators that we have learned so far are called binary operators. In other
words, it means that we need two operands to carry out an operation.

Similarly, unary operators need only one operand to perform their respective
operations.

We have already seen + and - as binary operators (addition and subtraction), Let's
see how we can use them as Unary operators.

For example,

40 | P a g e
INTERNET OF THINGS (ADVANCE)

Now mix the binary operator (+ and -) with the Unary operator (+ and -).

41 | P a g e
INTERNET OF THINGS (ADVANCE)

Precedence and Associativity


The concept of Precedence and Associativity comes into picture only when there are
two or more operators in one expression.

Understand this with an example.

Compute the expression 2 + 5 * 7

Based on which operator you evaluate first, you will either get 37 or 49 as an answer.

Precedence

The correct answer for the expression 2 + 5 * 7 is 37.

We get the result by performing multiplication first, and then the addition operation.
The expression evaluates as 2 + 5 * 7 => 2 + 35 => 37.

Run the same example in IDE and check the answer.

Look at the precedence table, which defines in which order the operators evaluate.

Precedence Table

Precedence Operators

1 +, - (unary)

2 **

42 | P a g e
INTERNET OF THINGS (ADVANCE)

Precedence Operators

3 *, /, %, //

4 +, - (Binary)

The operators with number 1 have the highest precedence, and the operators with
number 4 have the lowest precedence.

Multiple operators in a row mean that they all have the same precedence.

For example,

print( 75 / 2)*

Based on what we have learned so far, both * and / have the same precedence. So
how do we evaluate this one? We need to learn another concept called associativity
to get to this answer.

Associativity Or Binding

Associativity (also called as bindings) defines the order of evaluation performed


by the equal precedence operators. There are two types of bindings,
i.e., left and right binding.

Most of the Python's operators have left associativity.

Which means the evaluation of the expression happens from left to right.

Some operators have the right associativity, and the flow of execution is from right to
left. For example,

# associativity

print(7 - 4 - 1)

We can perform the above expression from left to right or right to left. Look at the
result from both directions.

43 | P a g e
INTERNET OF THINGS (ADVANCE)

• left to right: 7 - 4 - 1 => 3 - 1 => 2

• right to left: 7 - 4 - 1 => 7 - 3 => 4

We got two different results. Run the example in IDE to find out the associativity of
the - operator.

We got the result as 2. So, that shows that the associativity of - is left.

Let's take an example to see the right associativity operator from the list of operators
we have discussed.

# associativity

print(5 ** 1 ** 2)

• left to right: 5 ** 1 ** 2 => 5 ** 2 => 25

• right to left: 5 ** 1 ** 2 => 5 ** 1 => 5

Evaluate the expression in Python IDE and compare it.

44 | P a g e
INTERNET OF THINGS (ADVANCE)

The answer is 5. Hence the associativity of the exponential operator is right.

Let's have a look at the associativity of the operators we have learned so far.

Operators Associativity

+, - (unary) left to right

** right to left

*, /, %, // left to right

+, - (Binary) left to right

Remember - We use Associativity only when the operators are of equal


precedence.

45 | P a g e
INTERNET OF THINGS (ADVANCE)

Python Tuples

A Python Tuple is a group of items that are separated by commas. The indexing,
nested objects, and repetitions of a tuple are somewhat like those of a list, however
unlike a list, a tuple is immutable.

The distinction between the two is that while we can edit the contents of a list, we
cannot alter the elements of a tuple once they have been assigned.

Example

1. ("Suzuki", "Audi", "BMW"," Skoda ") is a tuple.

Features of Python Tuple

o Tuples are an immutable data type, which means that once they have been
generated, their elements cannot be changed.

o Since tuples are ordered sequences, each element has a specific order that
will never change.

Creating of Tuple:

To create a tuple, all the objects (or "elements") must be enclosed in parenthesis (),
each one separated by a comma. Although it is not necessary to include
parentheses, doing so is advised.

46 | P a g e
INTERNET OF THINGS (ADVANCE)

A tuple can contain any number of items, including ones with different data types
(dictionary, string, float, list, etc.).

Code:

1. # Python program to show how to create a tuple

2. # Creating an empty tuple

3. empty_tuple = ()

4. print("Empty tuple: ", empty_tuple)

5.

6. # Creating tuple having integers

7. int_tuple = (4, 6, 8, 10, 12, 14)

8. print("Tuple with integers: ", int_tuple)

9.

10. # Creating a tuple having objects of different data types

11. mixed_tuple = (4, "Python", 9.3)

12. print("Tuple with different data types: ", mixed_tuple)

13.

14. # Creating a nested tuple

15. nested_tuple = ("Python", {4: 5, 6: 2, 8:2}, (5, 3, 5, 6))

16. print("A nested tuple: ", nested_tuple)

Output:

Empty tuple: ()

Tuple with integers: (4, 6, 8, 10, 12, 14)

Tuple with different data types: (4, 'Python', 9.3)

47 | P a g e
INTERNET OF THINGS (ADVANCE)

A nested tuple: ('Python', {4: 5, 6: 2, 8: 2}, (5, 3, 5, 6))

Tuples can be constructed without using parentheses. This is known as triple packing.

Code

1. # Python program to create a tuple without using parentheses

2. # Creating a tuple

3. tuple_ = 4, 5.7, "Tuples", ["Python", "Tuples"]

4. # Displaying the tuple created

5. print(tuple_)

6. # Checking the data type of object tuple_

7. print(type(tuple_) )

8. # Trying to modify tuple_

9. try:

10. tuple_[1] = 4.2

11. except:

12. print(TypeError )

1. Dict = {"Name": "Chris", "Age": 20}

Output:

(4, 5.7, 'Tuples', ['Python', 'Tuples'])

<class 'tuple'>

<class 'TypeError'>

The construction of a tuple from a single member might be hard.

48 | P a g e
INTERNET OF THINGS (ADVANCE)

Simply adding parenthesis around the element is insufficient. To be recognised as a


tuple, the element must be followed by a comma.

Python Dictionary

An effective data structure for storing data in Python is dictionaries, in which can
simulate the real-life data arrangement where some specific value exists for some
particular key.

o Python Dictionary is used to store the data in a key-value pair format.

o It is the mutable data-structure.

o The elements Keys and values is employed to create the dictionary.

o Keys must consist of just one element.

o Value can be any type such as list, tuple, integer, etc.

In other words, we can say that a dictionary is the collection of key-value pairs where
the value can be of any Python object. In contrast, the keys are the immutable Python
object, i.e., Numbers, string, or tuple. Dictionary entries are ordered as of Python
version 3.7. In Python 3.6 and before, dictionaries are generally unordered.

Creating the Dictionary

The simplest approach to create a Python dictionary is by using curly brackets {}, but
there are other methods as well. The dictionary can be created by using multiple key-
value pairs enclosed with the curly brackets {}, and each key is separated from its
value by the colon (:). The syntax to define the dictionary is given below.

49 | P a g e
INTERNET OF THINGS (ADVANCE)

Syntax:

In the above dictionary Dict, The keys Name and Age are the strings which comes
under the category of an immutable object.

Let's see an example to create a dictionary and print its content.

Code

1. Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE


"}

2. print(type(Employee))

3. print("printing Employee data .... ")

4. print(Employee)

Output

<class 'dict'>

printing Employee data ....

{'Name': 'John', 'Age': 29, 'salary': 25000, 'Company': 'GOOGLE'}

Python provides the built-in function dict() method which is also used to create the
dictionary.

The empty curly braces {} is used to create empty dictionary.

Code

1. # Creating an empty Dictionary

2. Dict = {}

3. print("Empty Dictionary: ")

4. print(Dict)

5.
50 | P a g e
INTERNET OF THINGS (ADVANCE)

6. # Creating a Dictionary

7. # with dict() method

8. Dict = dict({1: 'Microsoft', 2: 'Google', 3:'Facebook'})

9. print("\nCreate Dictionary by using dict(): ")

10. print(Dict)

11.

12. # Creating a Dictionary

13. # with each item as a Pair

14. Dict = dict([(4, 'Praneeth'), (2, 'Varma')])

15. print("\nDictionary with each item as a pair: ")

16. print(Dict)

Output

Empty Dictionary:

{}

Create Dictionary by using dict():

{1: 'Microsoft', 2: 'Google', 3: 'Facebook'}

Dictionary with each item as a pair:

{4: 'Praneeth', 2: 'Varma'}

Accessing the dictionary values

We've discussed about using indexing to access data stored in lists and tuples.
However, because the dictionary's keys are distinct from one another, it is possible to
51 | P a g e
INTERNET OF THINGS (ADVANCE)

get the values by utilising the keys. The dictionary values can be accessed in the
following way.

Code

1. Employee = {"Name": "David", "Age": 30, "salary":55000,"Company":"GOOGL


E"}

2. print(type(Employee))

3. print("printing Employee data .... ")

4. print("Name : %s" %Employee["Name"])

5. print("Age : %d" %Employee["Age"])

6. print("Salary : %d" %Employee["salary"])

7. print("Company : %s" %Employee["Company"])

Output

<class 'dict'>

printing Employee data ....

Name : David

Age : 30

Salary : 55000

Company : GOOGLE

Python - Arrays

Array is a container which can hold a fix number of items and these items should be
of the same type. Most of the data structures make use of arrays to implement their
algorithms. Following are the important terms to understand the concept of Array.

52 | P a g e
INTERNET OF THINGS (ADVANCE)

• Element− Each item stored in an array is called an element.

• Index − Each location of an element in an array has a numerical index,


which is used to identify the element.

Array Representation

Arrays can be declared in various ways in different languages. Below is an illustration.

As per the above illustration, following are the important points to be considered.

• Index starts with 0.

• Array length is 10 which means it can store 10 elements.

• Each element can be accessed via its index. For example, we can fetch
an element at index 6 as 9.

Basic Operations

Following are the basic operations supported by an array.

• Traverse − print all the array elements one by one.

• Insertion − Adds an element at the given index.

• Deletion − Deletes an element at the given index.

• Search − Searches an element using the given index or by the value.

53 | P a g e
INTERNET OF THINGS (ADVANCE)

• Update − Updates an element at the given index.

Array is created in Python by importing array module to the python program. Then the
array is declared as shown eblow.

from array import *

arrayName = array(typecode, [Initializers])

Typecode are the codes that are used to define the type of value the array will hold.
Some common typecodes used are:

Typecode Value

b Represents signed integer of size 1 byte/td>

B Represents unsigned integer of size 1 byte

c Represents character of size 1 byte

i Represents signed integer of size 2 bytes

I Represents unsigned integer of size 2 bytes

f Represents floating point of size 4 bytes

d Represents floating point of size 8 bytes

Before lookign at various array operations lets create and print an array using python.

The below code creates an array named array1.

from array import *

54 | P a g e
INTERNET OF THINGS (ADVANCE)

array1 = array('i', [10,20,30,40,50])

for x in array1:

print(x)

When we compile and execute the above program, it produces the following result −

Output

10

20

30

40

50

Accessing Array Element

We can access each element of an array using the index of the element. The below
code shows how

from array import *

array1 = array('i', [10,20,30,40,50])

print (array1[0])

55 | P a g e
INTERNET OF THINGS (ADVANCE)

print (array1[2])

When we compile and execute the above program, it produces the following result −
which shows the element is inserted at index position 1.

Output

10

30

Insertion Operation

Insert operation is to insert one or more data elements into an array. Based on the
requirement, a new element can be added at the beginning, end, or any given index
of array.

Here, we add a data element at the middle of the array using the python in-built insert()
method.

from array import *

array1 = array('i', [10,20,30,40,50])

array1.insert(1,60)

for x in array1:

print(x)
56 | P a g e
INTERNET OF THINGS (ADVANCE)

When we compile and execute the above program, it produces the following result
which shows the element is inserted at index position 1.

Output

10

60

20

30

40

50

Deletion Operation

Deletion refers to removing an existing element from the array and re-organizing all
elements of an array.

Here, we remove a data element at the middle of the array using the python in-built
remove() method.

from array import *

array1 = array('i', [10,20,30,40,50])

array1.remove(40)

for x in array1:
57 | P a g e
INTERNET OF THINGS (ADVANCE)

print(x)

When we compile and execute the above program, it produces the following result
which shows the element is removed form the array.

Output

10

20

30

50

Search Operation

You can perform a search for an array element based on its value or its index.

Here, we search a data element using the python in-built index() method.

from array import *

array1 = array('i', [10,20,30,40,50])

print (array1.index(40))

When we compile and execute the above program, it produces the following result
which shows the index of the element. If the value is not present in the array then th
eprogram returns an error.

Output

Update Operation

58 | P a g e
INTERNET OF THINGS (ADVANCE)

Update operation refers to updating an existing element from the array at a given
index.

Here, we simply reassign a new value to the desired index we want to update.

from array import *

array1 = array('i', [10,20,30,40,50])

array1[2] = 80

for x in array1:

print(x)

When we compile and execute the above program, it produces the following result
which shows the new value at the index position 2.

Output

10

20

80

40

50

Previous Page Print PageNext Page

Multidimensional arrays

Python - 2-D Array

59 | P a g e
INTERNET OF THINGS (ADVANCE)

Previous Page

Next Page

Two dimensional array is an array within an array. It is an array of arrays. In this type
of array the position of an data element is referred by two indices instead of one. So
it represents a table with rows an dcolumns of data.

In the below example of a two dimensional array, observer that each array element
itself is also an array.

Consider the example of recording temperatures 4 times a day, every day. Some
times the recording instrument may be faulty and we fail to record data. Such data for
4 days can be presented as a two dimensional array as below.

Day 1 - 11 12 5 2

Day 2 - 15 6 10

Day 3 - 10 8 12 5

Day 4 - 12 15 8 6

The above data can be represented as a two dimensional array as below.

T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]

Accessing Values

The data elements in two dimesnional arrays can be accessed using two indices. One
index referring to the main or parent array and another index referring to the position
of the data element in the inner array.If we mention only one index then the entire
inner array is printed for that index position.

Example

The example below illustrates how it works.

from array import *

60 | P a g e
INTERNET OF THINGS (ADVANCE)

T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]

print(T[0])

print(T[1][2])

Output

When the above code is executed, it produces the following result −

[11, 12, 5, 2]

10

To print out the entire two dimensional array we can use python for loop as shown
below. We use end of line to print out the values in different rows.

61 | P a g e
INTERNET OF THINGS (ADVANCE)

Conditional Statements in Python

What is a conditional statement in Python?

A conditional statement in python, also called a condition constructs, is a statement


that accommodates a condition inside itself. This condition is constructed using the
bitwise, boolean, and comparison operators in Python. We already talked in great
detail about it in previous posts. A conditional statement always generates a
boolean output that is either true or false. (Note that true is represented as True in
Python and false as False). After generating the output, the statement decides
whether to move inside the conditional block or leave it as it is. The code inside the
conditional block is executed if and only if the conditional statement returns
true. (from expressions inside the construct)

The next sections will clear the doubts on conditional statements in Python. We will
start our learnings on conditional statements with the most used conditional
statement not only in Python but in any language i.e. the if statement.

If Conditional Statement in Python

The simplest and most used conditional statement in Python is the "if " statement. A
lot of the times, you have to decide whether to do "A " or do "B ". The "if
" statement, as its name suggests evaluates the expression. Moreover, it executes
the conditional block only when the statement is true. You can remember the
statement as:

if (something is True)

//execute the statements

So, for example, I have a variable age whose value is 40. Then, with the given
below code, the print statement will be executed only if the age is 40.

age = 40

62 | P a g e
INTERNET OF THINGS (ADVANCE)

if(age == 40):

print("The age is 40")

To refresh your memories, recall that Python does not use braces to represent the
code blocks and uses colon instead. All the code intended to be inside the
conditional statement should b indented properly and in alignment. Misalignment of
even one space can lead to exceptions and errors.

Executing the above code will return the following output:

Great! This was what we expected. Now the next step is, what if the condition turns
out to be False and we then want to print something *(or anything else)? *This
comes out as the "else " conditional statement in Python.

Else Statement In Python

Else conditional statement is a simple response to the "if " conditional statement
such as if this does not happen what else would? Therefore, whenever the "if
" statement returns False and conditional block from "if " skips, the conditional
block from "else " executes.

Continuing from the previous example, now my age is 35 and I have an "if
" statement which prints the age. If my age is 40, it will print otherwise another print
statement will execute, telling that my age is not 40.

age = 35

if(age == 40):

print("The age is 40")

else:
63 | P a g e
INTERNET OF THINGS (ADVANCE)

print("Age is not 40")

The above execution would return the following results:

Alright! We now know how to execute some code based on certain conditions. In
other words, if the condition is true (execute if block) otherwise execute else block if
the condition is false. But there is one more use case in the conditional statements.
What if we want to put up one more check once the "if " condition fails and not
execute the else statement directly?

Elif Conditional Statement in Python

Elif is a rather unique term as other programming languages don’t use it. Other
programming languages use "else if " to put up one more condition. While Python
combines "else and if " and makes it an "elif " conditional statement. The usage of
the "elif " statement will get more clear through the following given code.

Continuing on the same example, we will try to put up one more check in case
the "if " conditional statement fails. Guess the output for the following code:

age = 35

if(age == 40):

print("The age is 40")

elif(age == 35):

print("Age is 35")

You are right if you guessed the following output:

64 | P a g e
INTERNET OF THINGS (ADVANCE)

Since the indentation in Python is similar to the "{ " in other programming
languages, we can skip the indentation if there is only a single statement that we
have to execute. The same practice we follow in other languages too! So, writing
the "if " statement as follows:

if(condition): print("If statement Executed")

is equivalent to the following:

if(condition):

print("If statement Ecxecuted")

In addition to this, you can also combine various "if-elif-else " statements giving
rise to a cascading conditional block which we will discuss in the next section.

65 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 1
LOOPS IN PYTHON

What is loop?
Loops help to execute a sequence of instructions until a condition is satisfied.

There are two major types of loops in Python.

✓ For loops
✓ While loops

Python while Loop


Python while loop is used to run a block code until a certain condition is met.

The syntax of while loop is:

while condition:

# body of while loop

Here,

1) A while loop evaluates the condition


2) If the condition evaluates to True, the code inside the while loop is executed.
3) Condition is evaluated again.
4) This process continues until the condition is False.
5) When condition evaluates to False, the loop stops.

1|Page
INTERNET OF THINGS (ADVANCE)

Flowchart of Python while Loop

Example

Output

2|Page
INTERNET OF THINGS (ADVANCE)

Steps of execution

Variable Condition: i <= n Action

i=1
True 1 is printed. i is increased to 2.
n=5

i=2
True 2 is printed. i is increased to 3.
n=5

i=3
True 3 is printed. i is increased to 4.
n=5

i=4
True 4 is printed. i is increased to 5.
n=5

i=5
True 5 is printed. i is increased to 6.
n=5

i=6
False The loop is terminated.
n=5

A while loop might not even execute once if the condition is not met.

Infinite Loops

Infinite loops are the ones where the condition is always true.

3|Page
INTERNET OF THINGS (ADVANCE)

The above code is an example of an infinite loop. There is no command to alter the
value of x, so the condition "x is greater than or equal to 1" is always true. This will
make the loop run forever.

Do-While Loop
There are two variations of the while loop – while and do-While. The difference
between the two is that do-while runs at least once.

A while loop might not even execute once if the condition is not met. However, do-
while will run once, then check the condition for subsequent loops.

Python does not have a native do-while statement. But you can easily emulate a do-
while loop using other approaches, such as functions.

Let's try the do-while approach by wrapping up the commands in a function.

4|Page
INTERNET OF THINGS (ADVANCE)

The above code runs the "run_commands()" function once before invoking the while
loop. Once the while loop starts, the "run_commands" function will never be executed
since x is equal to 20.

5|Page
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 2

LOOP CONTROL IN PYTHON

The execution of the program in python loops can be controlled using different
functions. The most common loop control functions are

✓ Python Break Statement

✓ Python Continue Statement

✓ Python Pass Statement

Python break statement

• Break statement in Python is a loop control statement.

• A break statement breaks the python loop flow regardless of the loop's natural
completion.

• In simple words, a break statement can terminate the current iteration and exit
the loop. Once a break statement is met, the loop cannot continue.

• The break statement can be written by the word "break" anywhere inside the
Python program.

Python break statement example:

A simple example of a python break statement is to iterate the word "ToolsQA" and
break the loop when we encounter the letter "Q."

for c in "ToolsQA":

if c == "Q":

6|Page
INTERNET OF THINGS (ADVANCE)

break

else:

print(c)

The above loop prints the characters starting from "T" until a “Q” encounter. The above
code uses for loop in Python.

Output:

The output shows that the statement breaks the loop when we encounter a "Q "

Flowchart for Python break statement

The flowchart of the Python break statement is as follows:

7|Page
INTERNET OF THINGS (ADVANCE)

Python Continue Statement

• The Python continue statement skips the current iteration and lets the loop
execute or "continue" naturally.

• If the "continue" conditions meet, the loop is executed only before the continue
statement.

• All the statements after "continue" get skipped, and the next iteration follows.

• The continue statement can be written by the word "continue" inside the Python
loop. A "continue" statement can be put anywhere inside a loop but only with
caution as it affects a loop's flow.

The Python continue statement example:

The following example iterates over the word "ToolsQA" and implements a continue
statement when the character "Q " is iterating.

for c in "ToolsQA":

if c == "Q":

continue

else:

print(c)

Output:

8|Page
INTERNET OF THINGS (ADVANCE)

In the above program, the iteration skips as soon as we find the character "Q." But,
unlike the break statement, the loop continues naturally until all the characters of
"ToolsQA" don't iterate.

Flowchart for Python Continue Statement


The flowchart of the Python continue statement is as follows:

9|Page
INTERNET OF THINGS (ADVANCE)

Python Pass Statement

• Python pass statement is an empty check which does not interrupt the normal
flow of the loop.

• Python pass statements are constructive when a developer wants to keep the
code as it is and write the logic afterwards.

• Instead, they can write "pass" in place of that logic to check the program's
execution without the code.

• A Python pass statement resembles a null operation.

Python pass statement example:

In the below example, we have a pass statement that denotes a piece of code that
will be implemented later.

for c in "ToolsQA":

if c == "Q":

pass

else:

print(c)

Output:

The above Python code uses the "pass" statement whenever we encounter a "***Q
***." The result: Python compiler does nothing and lets the loop continue. However,
the pass statement in Python is different from the continue statement as in the pass
10 | P a g e
INTERNET OF THINGS (ADVANCE)

statement; the loop will execute all the code after "pass," whereas, in the continue
statement, we skip the code.

Flowchart for Python pass statement


The flowchart for the Python pass statement is as follows:

11 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 3

PYTHON OOPS

Basic Object-Oriented Programming (OOP) Concepts in Python

➢ Python is similar to most general-purpose programming languages with an


Object-Oriented environment system since its existence.

➢ Being an Object-Oriented Programming language, Python provides ease to the


users for developing applications with an Object-Oriented approach.

➢ Python also provides an easy way to create and make use of classes and
objects.

An Object can be identified with the following significant characteristics:

1) Identity:

Some information that can help identify the class's object can be termed as
Identity. For example, an employee's Identity is his /her name, the company Id
and many more.

2) Properties:

Properties are said to the attributes of that object. For example, these attributes
can be the gender, age, Date of Birth for an employee, or the type of processor,
size of RAM and ROM for a smartphone and many more.

3) Behavior:

12 | P a g e
INTERNET OF THINGS (ADVANCE)

The functions that an object can perform are said to its behavior. Object-
Oriented Programming makes the assignment of the functions to class objects
possible. For example, the smartphone can provide high performance and
better picture quality and many more.

➢ The OOPs concept in Python mainly focuses on reusable code development.

➢ This concept is also called DRY (abbreviated for Don't Repeat Yourself).

The benefits of using OOP methodology in python.

There are several benefits to using Object-Oriented Programming (OOP)


methodology in Python. Here are some of the key advantages:

1. Modularity and code reusability:

OOP promotes modular programming by organizing code into objects, which


encapsulate data and behaviour. This makes it easier to reuse and maintain code, as
objects can be created and reused in different parts of the program or in other
programs.

2. Encapsulation and data abstraction:

OOP allows you to encapsulate related data and methods within objects, hiding
internal details and providing a clear interface. This abstraction helps to manage
complexity, improves code organization, and enhances security by preventing direct
access to sensitive data.

3. Code organization and readability:

OOP promotes a structured approach to programming, making it easier to understand


and maintain code.

4. Inheritance and code reuse:


13 | P a g e
INTERNET OF THINGS (ADVANCE)

Inheritance is a powerful feature in OOP that allows you to create new classes by
inheriting properties and behaviors from existing classes. This promotes code reuse
and saves development time.

5. Polymorphism and flexibility:

Polymorphism allow objects of different classes to be treated as interchangeable


entities. This flexibility enables you to write code that can work with objects of different
types, providing a more dynamic and adaptable solution.

6. Easy maintenance and debugging:

OOP's modular and encapsulated structure makes it easier to locate and fix bugs or
make updates. Changes can be isolated to specific objects or classes, reducing the
impact on the rest of the codebase.

7. Scalability and extensibility:

OOP allows you to scale your codebase by adding new objects and classes as your
program grows. This makes it easier to manage large and complex projects and
provides a foundation for building robust and scalable applications.

14 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 4

CLASS AND OBJECTS

CLASS

➢ A Collection of objects can be known as the Class.

➢ A Class is a logical entity that comprises of some particular properties and


methods.

➢ Thus, we can also say that it is a blueprint for the object.

➢ The Syntax for a Class is shown below:

class ClassName:

<statement_1>

<statement_2>

<statement_N>

In the above syntax, we have used the keyword class to define a class ClassName.

Using class, we can construct instances.

A particular object that is constructed from a specific class is known as an instance.

For example –

15 | P a g e
INTERNET OF THINGS (ADVANCE)

If we have a cellphone class, it should comprise properties and methods such as


Model Name, Platform OS, Chipset, GPU, CPU, Memory, Camera, Price, and many
more.

Based on these descriptions and specifications, we can study the cellphone. Here, a
cellphone is an object.

The Syntax for Cellphone Class can be:

class Cellphone:

pass

In the above syntax, we have defined an empty class Cellphone.

OBJECT
➢ An instantiation of a class is known as an Object or Instance of that class.
➢ The class contains the description of the object.

The example for the object of Cellphone class can be:

obj = Cellphone()

Here, obj is an object of the class Cellphone.

Suppose we have information about cellphones. Now, we are building the class and
objects of Cellphone.

Example : Defining Class and Object in Python

class Cellphone:

# class attribute

cellphone_type = "Smartphone"

# instance attribute

def __init__(self, model_name, price):

16 | P a g e
INTERNET OF THINGS (ADVANCE)

self.model_name = model_name

self.price = price

# instantiating the Cellphone class

phone_1 = Cellphone("Apple iPhone 12", 78999)

phone_2 = Cellphone("OnePlus 8T", 42999)

# accessing the class attributes

print("Apple iPhone 12 is a {}".format(phone_1.__class__.cellphone_type))

print("OnePlus 8T is also a {}".format(phone_2.__class__.cellphone_type))

# accessing the instance attributes

print("The Price of {} is INR {}.".format( phone_1.model_name, phone_1.price))

print("The Price of {} is INR {}.".format( phone_2.model_name, phone_2.price))

Output:

Apple iPhone 12 is a Smartphone

OnePlus 8T is also a Smartphone

The Price of Apple iPhone 12 is INR 78999.

The Price of OnePlus 8T is INR 42999.

Explanation:

In the above program, we have defined a class with the name Cellphone. Then, we
defined the attributes. These attributes are the characteristics of the object.

We have defined these attributes inside the __init__ method of the class. It acts as an
initializer for executing the code as soon as the object is defined.

17 | P a g e
INTERNET OF THINGS (ADVANCE)

Then, we have created instances of the Cellphone class. Here, phone_1 and phone_2
are values (or references) to our new objects.

The class attribute can be accessed using __class__.species. The Class attributes
act similarly for every instance of a class. The instance attributes can be accessed in
the same way, using phone_1.model_name and phone_1.price. However, they are
different for every class’s instance.

18 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 5

INHERITANCE AND CONSTRUCTORS

INHERITANCE

➢ Inheritance refers to creating a new class for utilizing the information of an


already existing class without making any changes to it.
➢ The newly designed class acts like a child class or derived class.
➢ And similarly, the already existing class acts as a parent class or base class.

Example: Using Inheritance in Python

# parent class

class Cellphone:

def __init__(self):

print("This is a Cellphone")

def who(self):

print("Cellphone")

def performance(self):

print("High performance")

# child class

class iPhone(Cellphone):

def __init__(self):

# calling super() function

19 | P a g e
INTERNET OF THINGS (ADVANCE)

super().__init__()

print("iPhone is also a Cellphone")

def who(self):

print("Apple iPhone 12 Pro")

def refreshrate(self):

print("120Hz Refresh Rate")

phone = iPhone()

phone.who()

phone.performance()

phone.refreshrate()

Output:

This is a Cellphone

iPhone is also a Cellphone

Apple iPhone 12 Pro

High performance

120Hz Refresh Rate

In the above program, we have defined two classes, i.e., Cellphone (parent class) and
iPhone (child class). The functions of the parent class are inherited from the child
class. It can be seen from the performance () method.

We have used the super() function inside the __init__() method. This function helps
the users execute the parent class __init__() method inside the child class.

20 | P a g e
INTERNET OF THINGS (ADVANCE)

CONSTRUCTOR
A constructor is defined as the special kind of function or method that is used for
instance variables initialization during the creation of an object of a class.

The constructor's task is to assign values(initialize) to the instance members of the


class when a class object is created.

Creating a constructor:

The __init__ method or function is used for creating a constructor of the class and it
is also used when an object is created.

Any number of arguments can be passed at the time of creating an object of a class,
once the __init__() function is defined.

Each class is required to have a constructor, still if it just relies on the default
constructor.

Syntax:

def __init__(self):

# body

Example:

class DummyClass:

# constructor

def __init__(self):

# initializing instance variable

self.num=200

21 | P a g e
INTERNET OF THINGS (ADVANCE)

# a method

def read_number(self):

print(self.num)

# creating object of the class

obj = DummyClass()

# using obj to call the instance method

obj.read_number()

Output:

200

22 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 6

STRING
STRING
In computer programming, a string is a sequence of characters. For example, "hello"
is a string containing a sequence of characters 'h', 'e', 'l', 'l', and 'o'.

We use single quotes or double quotes to represent a string in Python. For example,

# create a string using double/single quotes

string1 = "Python programming"

string1 = 'Python programming'

In Python, strings are immutable sequences of characters, and there are several built-
in methods that allow you to manipulate and work with strings.

The commonly used string methods:

1. Replace:

The replace () method replaces all occurrences of a specified substring with another
substring within a string.

For example:

23 | P a g e
INTERNET OF THINGS (ADVANCE)

2. Join:

The join () method concatenates a list of strings into a single string, using the specified
string as a separator.

For example:

3. Split:

The split() method splits a string into a list of substrings based on a specified delimiter.
By default, the delimiter is a whitespace.

For example:

4. Reverse:

Strings don't have an inbuilt reverse method, but you can achieve it using slicing.

For example:

5. Uppercase and lowercase:

24 | P a g e
INTERNET OF THINGS (ADVANCE)

The upper() method converts a string to uppercase, while the lower() method converts
it to lowercase.

For example:

6. Count:

The count() method returns the number of occurrences of a specified substring within
a string.

For example:

7. Find:

The find() method searches for the first occurrence of a specified substring within a
string and returns its index.

If the substring is not found, it returns -1.

For example:

25 | P a g e
INTERNET OF THINGS (ADVANCE)

8. Length:

The len() function returns the length (the number of characters) of a string.

For example:

26 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 7
PYTHON FUNCTION
PYTHON FUNCTION

➢ A Python function is a reusable, organized block of code that is used to perform


the specific task.
➢ The functions are the appropriate way to divide an extensive program into a
useful block.
➢ It also provides reusability to our program.
➢ A code block can be reused by calling the function.

In Python, there are two types of functions:

1. Built-in functions –

➢ These functions are the part of the Python libraries and packages.
➢ These are also called as pre-defined functions.
➢ Python provides a wide range of built-in functions that are readily available for
use.
➢ These functions are part of the Python standard library and cover various
operations, including mathematical computations, string manipulation, file
handling, and more.

Some commonly used built-in functions include:

o print(): Outputs text or variables to the console.


o len(): Returns the length of a sequence or collection.
o input(): Reads input from the user.

27 | P a g e
INTERNET OF THINGS (ADVANCE)

o int(), float(), str(): Convert values to integers, floats, or strings, respectively.


o max(), min(): Returns the maximum or minimum value from a collection.
o range(): Generates a sequence of numbers.
o open(), read(), write(): File handling functions for reading from and writing to
files.

Here's an example of using a built-in function:

2. User-defined functions –

➢ These functions are defined by the user as per their requirement.


➢ Python allows you to define your own functions to perform specific tasks.
➢ User-defined functions provide modularity and code reuse.
➢ You can define functions using the def keyword, followed by the function name,
parentheses for parameters (if any), and a colon.
➢ The function body is indented and contains the code to be executed.

Here's an example of a user-defined function:

In this example, the greet() function takes a name parameter and prints a greeting
message using the provided name.

User-defined functions can have return values using the return statement.

28 | P a g e
INTERNET OF THINGS (ADVANCE)

For example:

In this case, the add() function takes two parameters and returns their sum.

Creating a function
The basic steps to create a user-defined function are:

➢ The def keyword is used to define function followed by the function name.
➢ Arguments should be written inside the opening and closing parentheses of the
function, and end the declaration with a colon.
➢ Write the program statements to be executed within the function body.
➢ The return statement is optional. It should be written at the end of the function.

The syntax is given below:

def function_name(argument list):

The function body

………………

………………

return

➢ The argument list can contain none or more arguments.


➢ The arguments are also called parameters.
➢ The function body contains indented statements.
➢ The function body gets executed whenever the function is called.

29 | P a g e
INTERNET OF THINGS (ADVANCE)

Calling a Function
After declaring a function, it must be called using function name followed by
parentheses with appropriate argument.

Note: It is necessary to define a function before calling; otherwise, it will give an error.

Consider the following examples:

Example-1

def hello():

print('Hello')

hello()

Output:

Hello

Example-2

def sum(a,b):

# define a function sum with two argument

c=a+b

return c

#returning the value to calling function

z=sum(10,20)

print("The sum is:",z)

Output: The sum is: 30

30 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 2

PYTHON ADVANCE

LECTURE 8
LAMBDA FUNCTION

A Lambda Function in Python programming is an anonymous function or a


function having no name. It is a small and restricted function having no
more than one line. Just like a normal function, a Lambda function can have
multiple arguments with one expression.

In Python, lambda expressions (or lambda forms) are utilized to construct


anonymous functions. To do so, you will use the lambda keyword (just as
you use def to define normal functions). Every anonymous function you
define in Python will have 3 essential parts:

• The lambda keyword.


• The parameters (or bound variables), and
• The function body.

A lambda function can have any number of parameters, but the function
body can only contain one expression. Moreover, a lambda is written in a
single line of code and can also be invoked immediately.

Syntax and Examples

The formal syntax to write a lambda function is as given below:

lambda p1, p2: expression

Here, p1 and p2 are the parameters which are passed to the lambda
function. You can add as many or few parameters as you need.
31 | P a g e
INTERNET OF THINGS (ADVANCE)

However, notice that we do not use brackets around the parameters as we


do with regular functions. The last part (expression) is any valid python
expression that operates on the parameters you provide to the function.

Example

Now that you know about lambdas let’s try it with an example. So, open
your IDLE and type in the following:

adder = lambda x, y: x + y

print (adder (1, 2))

Here is the output:

32 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 3

CLOUD FEATURES

LECTURE 1
CLOUD COMPUTING AND IoT CLOUD

WHAT IS CLOUD COMPUTING?

Cloud Computing is defined as storing and accessing of data and


computing services over the internet.

It doesn’t store any data on your personal computer.

It is the on-demand availability of computer services like servers, data


storage, networking, databases, etc.

Examples of Cloud Computing Services: AWS, Azure

Why the Name Cloud?

The term “Cloud” came from a network design that was used by network
engineers to represent the location of various network devices and their
inter-connection. The shape of this network design was like a cloud.

1|Page
INTERNET OF THINGS (ADVANCE)

IOT CLOUD (INTERNET OF THINGS CLOUD)

• IoT cloud is a specific subset of cloud computing that is personalized


to support the unique requirements of Internet of Things devices and
applications.
• It focuses on managing and processing data generated by IoT
devices, which are typically small, resource-constrained devices that
collect and transmit data over the internet.
• IoT cloud platforms offer specialized services to handle large-scale
data collection, storage, real-time data processing, and analytics from
IoT devices.

Examples of IoT cloud platforms: AWS IoT Core, Microsoft Azure IoT
Hub, Google Cloud IoT Core, and IBM Watson IoT Platform.

Benefits And Functions of IoT Cloud:

There are many benefits of combining these services –

➢ IoT Cloud Computing provides many connectivity options, implying


large network access. People use a wide range of devices to gain
access to cloud computing resources: mobile devices, tablets,
laptops.
➢ Developers can use IoT cloud computing on-demand. In other words,
it is a web service accessed without special permission or any help.
The only requirement is Internet access.
➢ Based on the request, users can scale the service according to their
needs.

2|Page
INTERNET OF THINGS (ADVANCE)

➢ Fast and flexible means you can expand storage space, edit software
settings, and work with the number of users.
➢ Cloud Computing means the pooling of resources.
➢ As the number of IoT devices and automation in use grows, security
concerns emerge. Cloud solutions provide companies with reliable
authentication and encryption protocols.

3|Page
INTERNET OF THINGS (ADVANCE)

UNIT 3

CLOUD FEATURES

LECTURE 2
TYPES OF CLOUDS

TYPES OF CLOUDS

PUBLIC PRIVATE HYBRID COMMUNITY


CLOUD CLOUD CLOUD CLOUD

Public Cloud

➢ Public clouds are managed by third parties which provide cloud


services over the internet to the public, these services are available
as pay-as-you-go billing models.
➢ They offer solutions for minimizing IT infrastructure costs and become
a good option for handling peak loads on the local infrastructure.
➢ Public clouds are the go-to option for small enterprises, which can
start their businesses without large investments by completely relying
on public infrastructure for their IT needs.
➢ A public cloud is meant to serve multiple users, not a single customer.

4|Page
INTERNET OF THINGS (ADVANCE)

Advantages of using a Public Cloud are:

1. High Scalability
2. Cost Reduction
3. Reliability and flexibility
4. Disaster Recovery

Disadvantages of using a Public cloud are:

1. Loss of control over data


2. Data security and privacy
3. Limited Visibility
4. Unpredictable cost

Private cloud

➢ Private clouds are distributed systems that work on private


infrastructure and provide the users with dynamic provisioning of
computing resources.
➢ Instead of a pay-as-you-go model in private clouds, there could be
other schemes that manage the usage of the cloud and proportionally
billing of the different departments or sections of an enterprise.
➢ Private cloud providers are HP Data Centers, Ubuntu, Elastic-Private
cloud, Microsoft, etc.

5|Page
INTERNET OF THINGS (ADVANCE)

The advantages of using a private cloud

1. Customer information protection: In the private cloud security


concerns are less since customer data and other sensitive information
do not flow out of private infrastructure.
2. Infrastructure ensuring SLAs (Service Level Agreements): Private
cloud provides specific operations such as appropriate clustering,
data replication, system monitoring, and maintenance, disaster
recovery, and other uptime services.
3. Compliance with standard procedures and operations: Specific
procedures have to be put in place when deploying and executing
applications according to third-party compliance standards. This is not
possible in the case of the public cloud.

Disadvantages of using a private cloud are:

1. The restricted area of operations: Private cloud is accessible within a


particular area.
2. Expertise requires: In the private cloud security concerns are less
since customer data and other sensitive information do not flow out of
private infrastructure. Hence skilled people are required to manage &
operate cloud services.

6|Page
INTERNET OF THINGS (ADVANCE)

Hybrid cloud

➢ A hybrid cloud is a distributed system formed by combining facilities


of the public cloud and private cloud. For this reason, they are also
called heterogeneous clouds.
➢ A major drawback of private deployments is the inability to scale on-
demand and efficiently address peak loads. Here public clouds are
needed. Hence, a hybrid cloud takes advantage of both public and
private clouds.

Advantages of using a Hybrid cloud are:

1. Cost: Available at a cheap cost than other clouds because it is formed


by a distributed system.
2. Speed: It is efficiently fast with lower cost, It reduces the latency of the
data transfer process.
3. Security: Most important thing is security. A hybrid cloud is totally safe
and secure because it works on the distributed system network.

Disadvantages of using a Hybrid cloud are:

1. It’s possible that businesses lack the internal knowledge necessary to


create such a hybrid environment.
7|Page
INTERNET OF THINGS (ADVANCE)

2. Managing security may also be more challenging.


3. Different access levels and security considerations may apply in each
environment.

Community cloud:

➢ Community clouds are distributed systems created by integrating the


services of different clouds to address the specific needs of an
industry, a community, or a business sector.
➢ But sharing responsibilities among the organizations is difficult.
➢ In the community cloud, the infrastructure is shared between
organizations that have shared concerns or tasks.
➢ An organization or a third party may manage the cloud.

Advantages of using Community cloud are:

1. Because the entire cloud is shared by numerous enterprises or a


community, community clouds are cost-effective.
2. Because it works with every user, the community cloud is adaptable
and scalable.
3. Users can alter the documents according to their needs and
requirements.
8|Page
INTERNET OF THINGS (ADVANCE)

4. Public cloud is less secure than the community cloud, which is more
secure than private cloud.

Disadvantages of using Community cloud are:

1. Not all businesses should choose community cloud.


2. It’s challenging for corporations to share duties

9|Page
INTERNET OF THINGS (ADVANCE)

UNIT 3
CLOUD FEATURES
LECTURE 3

CLOUD SERVICES LIKE SaaS, PaaS AND IaaS

Cloud services are categorized into three main models:

a. Software as a Service (SaaS)


b. Platform as a Service (PaaS)
c. Infrastructure as a Service (IaaS).

Each model offers different levels of control to users.

Here are the features of each cloud service model:

a. Software as a Service (SaaS):

I. Ready-to-use applications:
SaaS provides fully functional software applications over the internet,
eliminating the need for users to install, configure, or maintain the
software on their devices.
II. Accessibility:
Users can access SaaS applications through web browsers, making
them accessible from any device with an internet connection.
III. Automatic updates:
The service provider handles updates and patches, ensuring that
users are always using the latest version of the software.
IV. Scalability:

10 | P a g e
INTERNET OF THINGS (ADVANCE)

SaaS applications can easily scale up or down based on the user's


needs, allowing flexibility in resource allocation.
V. Multi-tenancy:
Multiple users or organizations can use the same software
application, with data and configurations kept separate and secure.

Examples of SaaS: Google Workspace (formerly G Suite), Microsoft 365,


Salesforce, Slack.

Advantages of SaaS

➢ It is a cloud computing service category providing a wide range of


hosted capabilities and services. These can be used to build and
deploy web-based software applications.
➢ It provides a lower cost of ownership than on-premises software. The
reason is it does not require the purchase or installation of hardware
or licenses.
➢ It can be easily accessed through a browser.
➢ No cost is required for initial setup.
➢ Low maintenance costs.
➢ Installation time is less, so time is managed properly.

Disadvantages of SaaS

➢ Low performance.
➢ It has limited customization options.
➢ It has security and data concerns.

b. Platform as a Service (PaaS):

I. Development environment:
11 | P a g e
INTERNET OF THINGS (ADVANCE)

PaaS provides a platform where developers can build, deploy, and


manage applications without worrying about the underlying
infrastructure.
II. Pre-built tools and frameworks:
PaaS offers a set of development tools, middleware, and runtime
environments, enabling faster application development.
III. Automatic scaling:
PaaS platforms can automatically scale resources based on demand,
ensuring optimal performance during peak times and cost savings
during low-traffic periods.
IV. Collaboration:
Developers from different locations can collaborate on the same
application using the platform's integrated development and version
control tools.

Examples of PaaS: Microsoft Azure App Service, Google App Engine,


Heroku, AWS Elastic Beanstalk.

Advantages of PaaS

➢ Programmers need not worry about what specific database or


language the application has been programmed in.
➢ It offers developers the to build applications without the cost of the
underlying operating system or infrastructure.
➢ Provides the freedom to developers to focus on the application’s
design while the platform takes care of the language and the
database.
➢ It is flexible and portable.
12 | P a g e
INTERNET OF THINGS (ADVANCE)

➢ It is quite affordable.
➢ It manages application development phases in the cloud very
efficiently.

Disadvantages of PaaS

➢ Data is not secure and is at big risk.


➢ As data is stored both in local storage and cloud, there are high
chances of data mismatch while integrating the data.

c. Infrastructure as a Service (IaaS):

I. Virtualized infrastructure:
IaaS provides virtualized computing resources over the internet,
including virtual machines, storage, and networking.
II. Flexibility and control:
Users have full control over the virtualized infrastructure, allowing
them to customize the environment according to their requirements.
III. Resource management:
Users can easily scale resources up or down based on demand,
paying only for the resources they consume.
IV. Rapid provisioning:
IaaS platforms can quickly provision new virtual machines and
resources, reducing deployment time for applications.

Examples of IaaS: Amazon Web Services (AWS) EC2, Microsoft Azure


Virtual Machines, Google Cloud Compute Engine.

Advantages of IaaS

13 | P a g e
INTERNET OF THINGS (ADVANCE)

➢ The resources can be deployed by the provider to a customer’s


environment at any given time.
➢ Its ability to offer the users to scale the business based on their
requirements.
➢ The provider has various options when deploying resources including
virtual machines, applications, storage, and networks.
➢ It has the potential to handle many number of users.
➢ It is easy to expand and saves a lot of money.
➢ Enhanced scalability and quite flexible.
➢ Dynamic workloads are supported.

Disadvantages of IaaS

➢ Security issues are there.


➢ Service and Network delays are quite an issue in IaaS.

Difference between IaaS, PaaS and SaaS :

Basis IAAS PAAS SAAS


Stands for Infrastructure as aPlatform as a Software as a
service. service. service.
Uses IAAS is used by PAAS is used by SAAS is used by the
network architects.developers. end user.
Access IAAS gives access PAAS gives access SAAS gives access
to the resources to run time to the end user.
like virtual
environment to
machines and
deployment and
virtual storage. development tools
for application.
Model It is a service It is a cloud It is a service model
model that computing model in cloud computing
provides that delivers tools that hosts software
virtualized that are used for the to make it available
computing development of to clients.
resources over the applications.
internet.
14 | P a g e
INTERNET OF THINGS (ADVANCE)

Technical It requires Some knowledge is There is no


understanding. technical required for the requirement about
knowledge. basic setup. technicalities
company handles
everything.
Popularity It is popular among It is popular among It is popular among
developers and developers who consumers and
researchers. focus on the companies, such as
development of file sharing, email,
apps and scripts. and networking.
Usage Used by the skilled Used by mid-level Used among the
developer to developers to build users of
develop unique applications. entertainment.
applications.
Examples Amazon Web Facebook, and MS Office web,
Services, sun, Google search Facebook and
vCloud Express. engine. Google Apps.

15 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 3

CLOUD FEATURES

LECTURE 4
CLOUD CONNECTIVITY AND DATA STORAGE

Cloud Storage is a service that allows to save data on offsite storage


system managed by third-party and is made accessible by a web services
API (Application Programming Interface).

Cloud Storage Classes

Cloud storage can be broadly classified into two categories:

• Unmanaged Cloud Storage


• Managed Cloud Storage
1. Unmanaged Cloud Storage

o Unmanaged cloud storage means the storage is preconfigured for the


customer.

o The customer can neither format, nor install his own file system or
change drive properties.

2. Managed Cloud Storage

o Managed cloud storage offers online storage space on-demand.

o The managed cloud storage system appears to the user to be a raw


disk that the user can partition and format.

16 | P a g e
INTERNET OF THINGS (ADVANCE)

Creating Cloud Storage System

➢ The cloud storage system stores multiple copies of data on multiple


servers, at multiple locations.

➢ If one system fails, then it is required only to change the pointer to the
location, where the object is stored.

➢ To aggregate the storage assets into cloud storage systems, the cloud
provider can use storage virtualization software known
as StorageGRID.

➢ It creates a virtualization layer that fetches storage from different


storage devices into a single management system.

➢ It can also manage data from CIFS (Common Internet File


System) and NFS (Network File System) file systems over the
Internet.

The following diagram shows how StorageGRID virtualizes the storage into
storage clouds:

17 | P a g e
INTERNET OF THINGS (ADVANCE)

Benefits of Cloud Storage

➢ Cost effectiveness
➢ Increased agility
➢ Faster deployment
➢ Efficient data management
➢ Virtually unlimited scalability
➢ Business continuity

18 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 3

CLOUD FEATURES

LECTURE 5
ARDUINO ARCHITECTURE, PROGRAMING AND APPLICATION

➢ An Arduino is actually a microcontroller-based kit which can be either


used directly by purchasing from the vendor or can be made at home
using the components, because of its open-source hardware feature.
➢ It is basically used in communications and in controlling or operating
many devices.
➢ It was founded by Massimo Banzi and David Cuartielles in 2005.

Arduino Architecture:

➢ Arduino’s processor basically uses the Harvard architecture where the


program code and program data have separate memory.
➢ It consists of two memories- Program memory and the data memory.
➢ The code is stored in the flash program memory, whereas the data is
stored in the data memory.

19 | P a g e
INTERNET OF THINGS (ADVANCE)

Arduino Uno consists of 14 digital input/output pins (of which 6 can be used
as PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB
connection, a power jack, an ICSP (In-circuit serial programming) header,
and a reset button.

a) Power Jack:
Arduino can be power either from the pc through a USB or through
external source like adaptor or a battery. It can operate on a external
supply of 7 to 12V.
b) Digital Inputs:
It consists of 14 digital inputs/output pins, each of which provide or
take up 40mA current. Some of them have special functions like pins
0 and 1, which act as Rx and Tx respectively, (The TX pin sends out
(transmits) the digital signal, and the RX pin listens (receives) for a
digital signal.) for serial communication.
c) Analog inputs:
It has 6 analog input/output pins, each providing a resolution of 10
bits.
d) ARef:
It provides reference to the analog inputs
e) Reset:
It resets the microcontroller when low.

Arduino Programming

Programs written in Arduino are known as sketches. A basic sketch


consists of 3 parts

20 | P a g e
INTERNET OF THINGS (ADVANCE)

1. Declaration of Variables

2. Initialization: It is written in the setup () function.

3. Control code: It is written in the loop () function.

Few of basic Adruino functions are:

➢ digitalRead(pin): Reads the digital value at the given pin.


➢ digitalWrite(pin, value): Writes the digital value to the given pin.
➢ pinMode(pin, mode): Sets the pin to input or output mode.
➢ analogRead(pin): Reads and returns the value.
➢ analogWrite(pin, value): Writes the value to that pin.
➢ serial.begin(baud rate): Sets the beginning of serial communication
by setting the bit rate.

Applications of Arduino Technology

➢ The Obstacle Avoidance Robot Operated with Arduino


➢ Arduino based Controlling of Electrical Appliances using IR
➢ Arduino based Home Automation
➢ Underground Cable Fault Recognition using the Arduino Board

21 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 3

CLOUD FEATURES

LECTURE 6
RASPBERRY PI

➢ Raspberry Pi, commonly abbreviated as RPI is a low-cost device with


size of a card that can be held on palm having the capacity of
functioning as a full-fledged computer.
➢ And with this small device, one can design and realize several
applications and prototype models with the minimum knowledge of
programming.

22 | P a g e
INTERNET OF THINGS (ADVANCE)

Raspberry Pi Architecture

1. Memory

The raspberry pi model Aboard is designed with 256MB of SDRAM and


model B is designed with 512MB.Raspberry pi is a small size PC
compare with other PCs. The normal PCs RAM memory is available in
gigabytes. But in raspberry pi board, the RAM memory is available more
than 256MB or 512MB

2. CPU (Central Processing Unit)

The Central processing unit is the brain of the raspberry pi board and
that is responsible for carrying out the instructions of the computer
through logical and mathematical operations.

3. GPU (Graphics Processing Unit)

The GPU is a specialized chip in the raspberry pi board and that is


designed to speed up the operation of image calculations.

4. Ethernet Port

The Ethernet port of the raspberry pi is the main gateway for


communicating with additional devices. The raspberry pi Ethernet port is
used to plug your home router to access the internet.

5. GPIO Pins

The general-purpose input & output pins are used in the raspberry pi to
associate with the other electronic boards. These pins can accept input
& output commands based on programming raspberry pi. The raspberry
pi affords digital GPIO pins. These pins are used to connect other
electronic components. For example, you can connect it to the
temperature sensor to transmit digital data.

6. XBee Socket

The XBee socket is used in raspberry pi board for the wireless


communication purpose.
23 | P a g e
INTERNET OF THINGS (ADVANCE)

7. Power Source Connector

The power source cable is a small switch, which is placed on side of the
shield. The main purpose of the power source connector is to enable an
external power source.

8. UART

The Universal Asynchronous Receiver/ Transmitter is a serial input &


output port. That can be used to transfer the serial data in the form of
text and it is useful for converting the debugging code.

9. Display

The connection options of the raspberry pi board are two types such as
HDMI and Composite. Many LCD and HD TV monitors can be attached
using an HDMI male cable and with a low-cost adaptor. The versions of
HDMI are 1.3 and 1.4 are supported and 1.4 version cable is
recommended.

Applications of Raspberry Pi.

1. Desktop PC

2. Wireless print server

3. Media Usage

4. Game Servers

5. Retro Gaming Machine

6. Robot Controller

7. Stop Motion Camera

8. Time-lapse Camera

9. FM Radio Station

10. Web Servers


24 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 1
Network
✓ A computer network is a collection of two or more computer systems
that are linked together.
✓ A network connection can be established using either cable or
wireless media.
✓ Hardware and software are used to connect computers and devices
in any network.

On basis of physical medium, there are 2 types of networks:

Networks

Wired Wireless

a) Wired Network:
▪ The term “wired” refers to any physical medium made up of cables.
▪ Copper wire, twisted pair, or fibre optic cables are all options.
▪ A wired network employs wires to link devices to the Internet or
another network, such as laptops or desktop PCs.
▪ They are sometimes also called bound media.

1|Page
INTERNET OF THINGS (ADVANCE)

Types of wired network

Wired Networks
Coaxial Fibre Optic
Twisted Pair Cable
Cable Cable

Unshielded • Shielded Twisted


Twisted Pair (UTP) Pair (STP)

There are three common types of wired media in the data transmission.
They are

• Twisted-Pair Cable,

• Coaxial Cable, and

• Fibre-Optic Cable.

Twisted Pair Cable

➢ A twisted pair consists of two conductors (normally copper), each with


its own plastic insulation, twisted together.
➢ One of these wires is used to carry signals to the receiver, and the
other is used only as ground reference.
➢ In addition to the signal sent by the sender on one of the wires, noise
and crosstalk may affect both wires and create unwanted signals.

Twisted Pair is of two types:

2|Page
INTERNET OF THINGS (ADVANCE)

a. Unshielded Twisted Pair (UTP)


b. Shielded Twisted Pair (STP)

a. Unshielded Twisted Pair Cable

➢ It consists of two insulating copper wires (1mm thick).


➢ The wires are twisted together in a helical form to reduce electrical
interference from similar pair.
➢ Identification is the reason behind coloured plastic insulation.

Advantages

• It has high speed capacity.

• Higher grades of UTP are used in LAN technologies like Ethernet.

Disadvantages

• Bandwidth is low when compared with Coaxial Cable.

• Provides less protection from interference.

b. Shielded Twisted Pair Cable

➢ This cable has a metal foil or braided-mesh.


➢ Electromagnetic noise penetration is prevented by metal casing.

3|Page
INTERNET OF THINGS (ADVANCE)

➢ Shielding also eliminates crosstalk.


➢ It is faster than unshielded and coaxial cable.

Advantages

• It can be used for Analog or Digital transmission

• It increases the signalling rate.

• It eliminates crosstalk.

Disadvantages

• It is difficult to manufacture

Coaxial Cable

➢ Coaxial is called by this name because it contains two conductors that


are parallel to each other.
➢ Copper is used in this as a central conductor and is surrounded by
PVC insulation.
➢ Outer metallic wrapping is used as a shield against noise and as a
second conductor which completes the circuit.
➢ The outer conductor is also encased in an insulating cover.
➢ The outermost part is the plastic cover which protects the whole cable.

4|Page
INTERNET OF THINGS (ADVANCE)

Advantages

• It is used in long distance telephone lines.

• It transmits digital signals at a very high rate of 10Mbps.

•It has higher noise immunity.

• It transmits data without distortion.

• They can span to longer distance at higher speeds as they have better
shielding when compared to twisted pair cable

Disadvantages

• Single cable failure can fail the entire network.

• If the shield is imperfect, it can lead to grounded loop.

Fiber Optic Cable

➢ A fibre-optic cable is made of glass or plastic and transmits signals in


the form of light.
➢ In fibre optical cable, light moves only in one direction.
➢ For two-way communication to take place a second communication
link must be made between the two devices.

5|Page
INTERNET OF THINGS (ADVANCE)

➢ Optical fibres use total internal reflection to guide light through a


channel.
➢ A glass or plastic core is surrounded by a cladding of less dense glass
or plastic.
➢ The difference in density of the two materials must be such that a
beam of light moving through the core is reflected off the cladding
instead of being refracted into it.

Advantages

Fibre optic has several advantages over metallic cable:

• It is resistant to corrosion.

• It shows greater immunity to tapping.

Disadvantages

• It has unidirectional light propagation.

6|Page
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 2

b. Wireless Network
➢ “Wireless” means without wire, media that is made up of
electromagnetic waves (EM Waves) or infrared waves.
➢ Antennas or sensors will be present on all wireless devices.
➢ Cellular phones, wireless sensors, TV remotes, satellite disc
receivers, and laptops with WLAN cards are all examples of wireless
devices.
➢ For data or voice communication, a wireless network uses
radiofrequency waves rather than wires.

Types of Wireless Communication Technologies

Wireless Network
Ultra
Bluetooth Infrared WiFi ZigBee Wide
Band

7|Page
INTERNET OF THINGS (ADVANCE)

1. Bluetooth

• It is named after a Danish king named Harald Bluetooth.


• Bluetooth is used to connect different electronic devices wirelessly to
a system for transferring and sharing data.
• Cell phones are connected to hands-free earpieces, wireless
keyboard, mouse and mike to laptops with the help of Bluetooth as it
transmits information from one device to another device.

2. Infrared

• Infrared technology is a type of wireless communication technology to


transfer data between two infrared enabled devices through infrared
radiation.
• Unlike Wi-Fi and Bluetooth technologies, infrared network signals
cannot penetrate walls or other obstructions and work only with a
direct line of sight.
• Due to its short-range communication system, the use of an infrared
communication system in one room will not be affected by the use of
another system in the next room.
• This is why using an infrared TV remote control in our home will not
interfere with the use of our neighbour’s infrared TV remote control.
8|Page
INTERNET OF THINGS (ADVANCE)

3. Wi-Fi

• Wi-Fi is a low-cost wireless communication technology.


• A WiFi setup consists of a wireless router which serves a
communication hub, linking portable device with an internet
connection.
• This network facilitates connection of many devices depending on the
router configuration.
• These networks are limited in range due to the low power
transmission, allowing the user to connect only in the close proximity.

9|Page
INTERNET OF THINGS (ADVANCE)

4. ZigBee

• Zigbee is an IEEE 802.15.4-based specification for a suite of high-


level communication protocols.
• It is used to create PANs (Personal Area Networks) with small, low-
power digital radios, such as for home automation and medical device
data collection.
• It is also used in small scale projects which need wireless connection.
• In short, Zigbee is a low-power, low data rate, and close proximity (i.e.,
personal area) wireless network.
• Zigbee is considered to be simpler and less expensive than other
wireless PANs (WPANs), such as Bluetooth or Wi-Fi.

5. UWB (Ultra-wide band)

• Ultra-wideband (also known as UWB) is a radio technology that can


use a very low energy level for short-range, high-bandwidth
communications over a large portion of the radio spectrum.
10 | P a g e
INTERNET OF THINGS (ADVANCE)

• UWB has traditional applications in radar imaging.


• Most recent applications are sensor data collection, precision
locating, and tracking applications.
• As of September 2019, UWB support has started to appear in high-
end smartphones.
• UWB transmits in a manner that does not interfere with conventional
narrowband and carrier wave transmission in the same frequency
band.

Comparison of some important wireless communication


technologies

11 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 3
M2M (Machine-to-Machine)

• M2M communication is a concept that refers to communication that


involves the exchange of data between two or more machines without
the use of a human interface or intervention.
• Intelligent machines can exchange information and even coordinate
and perform actions without the need for human intervention.
• The network of communication between machines can be wired or
wireless, and it works in combination with IoT technology.
• M2M communication is commonly used to refer to cellular
communication for embedded devices.
• M2M communication is a type of point-to-point communication in
which the network transmits data using public networking
technologies such as Ethernet and cellular networks.

Application

➢ Sensor telemetry is one of the M2M applications.


➢ M2M is being used by businesses to remotely monitor variables such
as temperature, energy consumption, moisture, pressure, and so on.
➢ ATM is the second example of M2M. The internal computer of the ATM
is in constant communication with a host computer, which routes

12 | P a g e
INTERNET OF THINGS (ADVANCE)

appropriate banks and accounts. The bank returns approval codes via
the host computer, allowing transactions to proceed.

Types of Machine-to-Machine Communication

M2M communication can be classified into two types:

a. wired communication
b. wireless communication.

a. Wired M2M Communication:

➢ The data transfer between devices in wired M2M communication


takes place over a wired transfer medium.
➢ Fiber optic cables, EtherCAT, or even coaxial cables can be used.
➢ Communication between devices in the same LAN network
connected only by wires is also included in wired M2M
communication.
➢ Wired communication networks are becoming increasingly scarce.
The majority of use cases are shifting to wireless networks.
➢ When wireless signals are susceptible to interference, wired networks
are used.
➢ It is also used in systems where upgrading communication networks
to a wireless system can be difficult.

b. Wireless M2M Communication:

13 | P a g e
INTERNET OF THINGS (ADVANCE)

➢ Wireless M2M communication occurs when machines use wireless


communication methodologies to communicate between devices.
➢ The Internet of Things, or IoT, refers to M2M communication that
primarily uses a wireless network for communication.
➢ Wireless communication methodologies may use radio waves to the
most recent 5G technology.

Some common M2M Wireless communication technologies are:

1. RFID (Radio Frequency Identification)

o RFID technology uses radio wave frequency to communicate and


transfer data wirelessly.
o It is now widely used in the logistics industry to track a package from
beginning to end.

2. NFC (Near-Field Communication)

o NFC is similar to RFID, but it can only be used for short-range data
transfer.
o NFC technology is used to transfer data in payment applications such
as Apple Pay and contactless credit cards.

3. WiFi (Wireless Fidelity)

o It is a popular method of wireless internet access in homes and


offices.
o Data can also be transferred between devices connected to the same
WiFi network using the same network.

4. Cellular networks

14 | P a g e
INTERNET OF THINGS (ADVANCE)

o Cellular networks can be used for wireless M2M communication as


well.
o The first wireless credit card readers communicated using GSM or
other 2G technologies. Communication was later possible via HSPA
(3G) and LTE (4G) networks.

15 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4
IoT NETWORKING AND APPLICATION
LECTURE 4

Different Generations of Mobile Network Technology:


The different generations of mobile network technology are as
follows

1. 2G (Second Generation):

▪ 2G, or Second Generation, is the first digital cellular network


technology.
▪ It was introduced in the early 1990s and replaced the earlier analog
networks.
▪ 2G allowed for digital voice communication and brought several
improvements, including better call quality, higher capacity, and
reduced interference.
▪ The most common 2G technologies were GSM (Global System for
Mobile Communications) and CDMA (Code Division Multiple Access).

2. 3G (Third Generation):

▪ 3G, or Third Generation, emerged in the early 2000s and represented


a significant leap forward in mobile communications.
▪ It brought faster data transfer rates, enabling mobile internet access,
video calling, and multimedia services.

16 | P a g e
INTERNET OF THINGS (ADVANCE)

▪ 3G technologies included UMTS (Universal Mobile


Telecommunications System) and CDMA2000.

3. 4G (Fourth Generation):

▪ 4G, or Fourth Generation, was a major advancement in mobile


technology introduced in the late 2000s and early 2010s.
▪ It significantly improved data speeds and capacity, making it possible
to stream high-definition video, use advanced mobile apps, and
access the internet at much higher speeds.
▪ The two main 4G technologies were LTE (Long-Term Evolution) and
WiMAX (Worldwide Interoperability for Microwave Access).

4. 5G (Fifth Generation):

▪ 5G, or Fifth Generation, is the latest generation of mobile network


technology.
▪ It started to roll out globally in the late 2010s and continues to expand.
▪ 5G promises significantly faster data speeds, lower latency, and
increased capacity compared to 4G.
▪ It enables technologies like augmented reality (AR), virtual reality
(VR), autonomous vehicles, and the Internet of Things (IoT) to
flourish.
▪ 5G operates on multiple frequency bands, including sub-6 GHz and
millimeter-wave (mmWave).

17 | P a g e
INTERNET OF THINGS (ADVANCE)

18 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 5
Low Power Wide Area Network (LPWAN)
Low power wide area networks (LPWAN) are a type of wireless network
designed for long-range communication in a quiet bandwidth environment.

LPWANs can collect data from sensors or meters in remote areas where
traditional cellular networks are not available or costly.

The main aim of LPWANs is to optimize two critical IoT factors:

a. Low power:

IoT sensors and devices must transfer data regularly so the battery life of
these devices must be extended as much as possible.

b. Wide area coverage:

For IoT devices to be helpful, they must be able to maintain a network


connection wherever they are required.

Types of LPWANs

a. Sigfox
Today, one of the most widely deployed LPWANs is the proprietary,
unlicensed Sigfox. The ultra-narrowband technology operates over a
public network in the 868 MHz or 902 MHz bands and is limited to a
single operator per country.

19 | P a g e
INTERNET OF THINGS (ADVANCE)

b. LoRaWAN
The LoRa Alliance-specified and backed unlicensed LoRa transmits
at several sub-gigahertz frequencies, making it less susceptible to
interference. A LoRaWAN network server enhances internet
bandwidth and power consumption.
c. RPMA
Random phase multiple access, RPMA, is an Ingenu Inc. proprietary
LPWAN. Despite its shorter range, it provides better bidirectional
communication than Sigfox.
d. NB-IOT
NB-IoT is a wireless broadband technology for Internet of Things (IoT)
applications. It operates in the license-free sub 1 GHz spectrum with
a bandwidth of 200 kHz and has a latency of 10 ms or less.
e. LTE-M
LTE-M is an evolution of LTE for low power, low data rate machine-to-
machine communications in license-free spectrum bands. It provides
high throughput with ultra-low latency and long battery life,

Advantages of LPWAN

➢ LPWAN networks can provide more reliable connectivity to devices


that are located in remote areas.
➢ LPWAN networks can be cheaper than other forms of wireless
communication because they require less power and infrastructure.
➢ It can connect machines and sensors, which increases efficiency and
productivity.

20 | P a g e
INTERNET OF THINGS (ADVANCE)

➢ Low Power Wide Area Network (LPWAN) has a Data rate of 624kbps
for uplink and 156kbps for downlink.
➢ It provides a low-power solution for IoT devices that need to be
connected.

Disadvantages of LPWAN

➢ LPWAN only supports low data rates, so it cannot be used for high
data rate applications.
➢ It has a high latency between end nodes. As a result, LPWAN is not
suitable for low latency applications.

21 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 6

SigFox, LoRaWAN
▪ SigFox, LoRaWAN are the examples of LPWAN technology.
▪ Both LoRaWAN and SigFox implements wireless data integration for
the long range, low power division.
▪ However, LoRaWAN and SigFox are different technologies.

1. SigFox :

➢ SigFox uses bidirectional functionality, that is DBPSK in one direction


and GFSK in the other direction.
➢ DBPSK stands for Differential binary phase-shift keying and GFSK
stands for Gaussian frequency shift keying.
➢ SigFox and their partners set up receivers on towers and receives
data transmissions from different nodes of different devices.

2. LoRaWAN :

➢ LoRaWAN is a MAC layer protocol, which is designed for large scale


public networks.
➢ LoRaWAN is built using Semtech’s LoRa technology.
➢ But the important is that, LoRa and LoRaWAN are two different things.
LoRa and LoraWAN comes under the non-cellular LPWAN wireless
communication network protocols.
22 | P a g e
INTERNET OF THINGS (ADVANCE)

Difference between LoRaWan and Sigfox

S.NO Comparison SigFox LoRaWAN

01 Modulation It follows Binary phase- LoRaWAN follows Chirp


shift keying modulation. spread spectrum
modulation.
02 Bandwidth In SigFox the bandwidth is For LoRaWAN the
100Hz. bandwidth is 250KHz and
125KHz.
03 Maximum data It can send up to 100bps . In case of LoRaWAN the
rate maximum data rate is
50Kbps.
04 Functionality SigFox is limited LoRaWAN is fully
bidirectional/Half-duplex bidirectional/ Half-Duplex
05 Maximum Uplink=12 bytes, The maximum payload
payload length Downlink=8 bytes. length is 243 bytes.

06 Range The Range of SigFox is The Range of


10 km in urban area, LoRaWAN is 5 km in
40 km in rural area. urban, 20 km in rural
area respectively.

Narrowband IoT
➢ Narrowband Internet of Things (NB-IoT) is a low-power, wide-area
network (LPWAN) technology designed to enable efficient
communication for a large number of Internet of Things (IoT) devices.
➢ It is a part of the 3GPP (3rd Generation Partnership Project) standard
and is specifically designed to address the needs of IoT applications
that require long battery life, extended coverage, and low data rates.

23 | P a g e
INTERNET OF THINGS (ADVANCE)

Key features of Narrowband IoT include:

a. Low Power Consumption:


NB-IoT devices are optimized for low power consumption, allowing
them to operate for several years on a single battery.
b. Wide Area Coverage:
NB-IoT provides excellent coverage in both urban and rural areas,
penetrating deep indoors and underground. Its signal range can be
up to several kilometres, depending on the deployment and
environment.
c. Low Data Rates:
NB-IoT is designed for applications that require intermittent data
transmission with low data rates. It is not suitable for high-bandwidth
applications but is perfect for sending small packets of data at regular
intervals.
d. Cost-Effective:
Due to its simple and efficient design, NB-IoT offers cost advantages,
making it an attractive choice for large-scale IoT deployments.
24 | P a g e
INTERNET OF THINGS (ADVANCE)

e. Coexistence with LTE Networks:


NB-IoT can be deployed in a variety of ways, including standalone
deployments, in-band deployments (sharing the same spectrum as
LTE), and guard-band deployments (using the unused space between
LTE channels).
f. Security:
NB-IoT incorporates robust security mechanisms to protect data
transmitted over the network and ensure the security and
confidentiality of communications.

Some common use cases for Narrowband IoT include:

I. Smart Metering:

Remote monitoring and management of utility meters, such as


electricity, water, and gas meters, to know resource consumption and
billing processes.

II. Smart Agriculture:

Monitoring soil conditions, weather, and crop health to optimize


irrigation, fertilization, and overall crop yield.

III. Asset Tracking:

Tracking and managing the location and status of valuable assets, such
as containers, vehicles, and equipment.

IV. Smart Cities:

Implementing various IoT solutions in urban areas, such as smart


lighting, waste management, parking, and environmental monitoring.

25 | P a g e
INTERNET OF THINGS (ADVANCE)

V. Industrial IoT:

Connecting sensors and devices in industrial settings to enhance


efficiency, predictive maintenance, and process optimization.

26 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 7
RFID (Radio Frequency IDentification)
➢ Radio Frequency IDentification is commonly known as RFID.
➢ The objective of RFID is to track and identify objects or products
through tags.
➢ The RFID are in the form of a small chip that can receive and transmit
information through electromagnetic fields.
➢ RFIDs are frequently used for all sorts of products, from
pharmaceuticals to warehouses, clothing, and accessories to
transportation and logistics.

The RFIDs are majorly divided into three types.

1) Low Frequency RFID


2) High Frequency RFID
3) Ultra-High Frequency RFID

1. Low Frequency RFID

The Low-Frequency RFID generally has the following features


27 | P a g e
INTERNET OF THINGS (ADVANCE)

✓ Primary Frequency Range varies from 125 – 134 kHz


✓ Read Range for the Readers or Interrogators: Within Contact – 10
Centimeters

2. High Frequency RFID

The High-Frequency RFID generally has the following features

✓ Primary Frequency Range varies from13.56 MHz


✓ Read Range for the Readers or Interrogators: Within Contact – 30
Centimeters

3. Ultra-High Frequency RFID

The Ultra High-Frequency RFID generally has the following features

✓ General Frequency Range varies from 300 – 3000 MHz


✓ Primary Frequency Range varies from 433 MHz, 860 – 960 MHz

What are RFID Tags?

❖ RFID and RFID Tags are two separate things.


❖ RFID is a small chip that contains data or information and uses radio
frequency to transfer information.
❖ RFID tags are the tags or labels that have the RFID chip installed in
it. It is these RFID tags that are attached to products in order to track
them.

RFID Tags, mainly of three types:

1) Active Tags:

The Active Tags run on their own battery, and transmit their own ID
signal.

28 | P a g e
INTERNET OF THINGS (ADVANCE)

2) Passive Tags:

The Passive Tags are small in size, have no batteries of their own, and
instead uses the Reader’s energy source.

3) Battery-assisted Passive Tags:

The Battery-assisted Passive Tags consist of a small battery (Not full-


fledged battery like an Active Tag). This battery gets activated only in the
presence of the Readers.

Differences between Active and Passive RFID Tags

No Basis Active RFID Tags Passive RFID Tags

1 Power Runs on own Battery Uses the Tag Reader


Source Energy

2 Readability 30 Meters to 100 Within Contact to 25 Meters


Range Meters

3 Operations An Active Tag has its A Passive Tag needs to be


own Battery, thus, in the presence of the
always active Reader

4 Battery Life Maximum Life is upto 5 Life Expectancy is Very


years High. It survives over a
Lifetime

5 Storage Larger amounts of data Data storage is limited to


Capacity can be stored 128 Bytes

29 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 4

IoT NETWORKING AND APPLICATION

LECTURE 8
Components of RFID Systems
RFID is a technology that uses radio waves to wirelessly identify and track
objects.

An RFID system consists the following main components:

a) Tags (RFID Tags):


• RFID tags are small electronic devices that contain a microchip and
an antenna.
• The microchip stores data, and the antenna allows the tag to
communicate with RFID readers.
• RFID tags come in different forms, such as passive, active, and semi-
passive, depending on their power source and communication
capabilities.
b) Antennas:
• RFID antennas are responsible for transmitting radio waves and
receiving signals from RFID tags.
• They are a crucial part of the system as they enable communication
between the reader and the tags.
c) Readers (RFID Readers):

30 | P a g e
INTERNET OF THINGS (ADVANCE)

• RFID readers are devices that generate radio signals to activate RFID
tags within their range and then receive and interpret the data from
the tags.
• Readers can be fixed or handheld, and they come with different
communication interfaces to connect with other systems.
d) Connectors:
• Connectors are used to establish connections between the RFID
reader and other equipment, such as antennas or controllers.
e) Cables:
• Cables are necessary to link the various components of the RFID
system, such as connecting antennas to readers.
f) Encoder/Printers for Smart Labels:
• To create RFID smart labels, which are adhesive labels with
embedded RFID tags, specialized devices called encoder/printers are
used.
• These devices can program data into the RFID tags and print human-
readable information on the label surface.
g) Controllers:
• RFID controllers manage the communication between the readers
and the software.
• They help coordinate the flow of data and manage multiple readers
within a larger RFID system.
h) Software:

31 | P a g e
INTERNET OF THINGS (ADVANCE)

• The software is an essential part of the RFID system as it handles


data collection, processing, and integration with other business
systems.
• The software can perform tasks such as inventory management,
asset tracking, and analytics based on the data collected from RFID
tags.

RFID advantages over Bar codes


RFID (Radio Frequency Identification) and barcodes are two different
technologies used for automatic identification and data capture.

Barcodes:

✓ A barcode is a visual representation of data that consists of a series


of parallel lines, bars, and spaces.
✓ The data in a barcode is encoded in the width and spacing of these
lines.
✓ Barcodes are read using optical scanners or barcode readers.
✓ They are commonly used for product identification, inventory
management, and point-of-sale transactions.

RFID:

RFID is a technology that uses radio waves to wirelessly identify and track
objects.

Here are some key advantages of RFID over barcodes:

a) Read Range and Speed:

32 | P a g e
INTERNET OF THINGS (ADVANCE)

RFID does not require line-of-sight scanning like barcodes. RFID tags
can be read from a distance, and multiple tags can be read
simultaneously.

b) Data Capacity:

RFID tags can store more data than barcodes. Some RFID tags can hold
kilobytes of information but barcodes typically store limited information.

c) Durability:

RFID tags are more durable and robust than barcodes. They can
withstand harsh environmental conditions, such as extreme
temperatures, moisture, and chemicals, without affecting their
readability. Barcodes, on the other hand, may become damaged due to
wear and tear.

d) Automation and Efficiency:

RFID enables automation of various processes. For instance, in


inventory management, RFID technology allows for real-time tracking of
items but bar codes have no such features.

e) Readability in Bulk:

RFID tags can be read in bulk, which is highly advantageous for


inventory counts or asset management but bar codes have no such
features

f) Versatility:

RFID is applicable in a wide range of scenarios, from retail and supply


chain management to healthcare, automotive, agriculture, and more. It

33 | P a g e
INTERNET OF THINGS (ADVANCE)

can be used in situations where barcodes may not be feasible or


practical.

g) Integration with IoT:

RFID can seamlessly integrate with the Internet of Things (IoT), enabling
real-time data communication and interaction between physical objects
and digital systems but bar codes have no such features.

34 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 5
IoT APP DEVELOPMENT
LECTURE 1
FRAMEWORK SELECTION FOR IoT APP DEVELOPMENT

When identifying a suitable framework for IoT app development, consider


the following parameters to ensure a successful and efficient development
process:

Device Compatibility
Communication Protocols
Scalability and Performance
APP DEVELOPMENT
SELECTION FOR IoT

Security Features
FRAMEWORK

Data Management
Ease of Integration
Developer-Friendly

Real-Time Capabilities

Edge Computing Support

Cost and Licensing

Industry Adoption

1. Device Compatibility:

1|Page
INTERNET OF THINGS (ADVANCE)

Check if the framework supports the types of IoT devices and platforms
you plan to use in your project. It should be compatible with a wide range
of devices, sensors, and actuators to accommodate the diverse IoT
ecosystem.

2. Communication Protocols:

Ensure that the framework supports the necessary communication


protocols for your IoT devices. The framework should allow seamless
integration with these protocols.

3. Scalability and Performance:

Evaluate the framework's scalability to handle a growing number of


devices and data. It should be able to manage the increased load without
compromising performance.

4. Security Features:

Security is critical in IoT applications. The framework should offer robust


security mechanisms for device authentication, data encryption, and
secure communication.

5. Data Management:

Consider how the framework handles data storage and management. It


should provide options for efficient data storage, retrieval, and analysis.

6. Ease of Integration:

The chosen framework should be easy to integrate with other systems


and services, such as cloud platforms, databases, and analytics tools.

7. Developer-Friendly:

2|Page
INTERNET OF THINGS (ADVANCE)

Look for frameworks that offer a developer-friendly environment with


good documentation, active community support, and helpful resources
like tutorials and sample projects.

8. Real-Time Capabilities:

Consider whether the framework supports real-time communication and


event handling, which are crucial for many IoT applications, especially
those involving real-time monitoring and control.

9. Edge Computing Support:

Some applications require processing data at the edge (on the IoT
devices themselves). So, look for frameworks that support edge
computing capabilities. This can reduce data transmission and latency,
improving overall system performance.

10. Cost and Licensing:

Assess the cost implications of using the framework, including any


licensing fees, cloud service costs, or additional expenses.

11. Industry Adoption:

Consider the popularity and adoption of the framework within the IoT
development community. A widely used framework is more likely to have
better support, frequent updates, and a larger pool of resources.

3|Page
INTERNET OF THINGS (ADVANCE)

SOME POPULAR FRAMEWORKS FOR IOT APPLICATIONS


DEVELOPMENT

POPULAR FRAMEWORKS FOR IOT


APPLICATIONS DEVELOPMENT
1.IoTivity
2.Node-RED
3.Cylon.js
4.Arduino IDE and Libraries
5.Particle
6.AWS IoT Core
7.Google Cloud IoT Core

1. IoTivity:
➢ IoTivity is an open-source framework developed by the Open
Connectivity Foundation (OCF).
➢ It provides a standardized approach to IoT device connectivity and
communication.
➢ IoTivity supports various transport protocols such as MQTT
(Message Queuing Telemetry Transport) and HTTP (Hypertext
Transfer Protocol), making it suitable for different types of IoT
devices and platforms.
➢ It emphasizes interoperability and security, making it suitable for
large-scale IoT deployments.
2. Node-RED:

4|Page
INTERNET OF THINGS (ADVANCE)

➢ Node-RED is a flow-based programming tool that allows


developers to visually connect devices, APIs, and services for IoT
application development.
➢ It provides a user-friendly graphical interface, making it easier to
create complex IoT workflows without much coding.
➢ Node-RED is highly extensible and integrates well with MQTT,
which is a popular protocol for IoT communication.
3. Cylon.js:
➢ Cylon.js is a JavaScript framework specifically designed for IoT
development.
➢ It supports multiple platforms and communication protocols,
including Arduino, Raspberry Pi, MQTT, and more.
➢ Cylon.js enables developers to interact with various sensors,
actuators, and devices using JavaScript.
4. Arduino IDE and Libraries:
➢ For IoT projects involving Arduino boards, the Arduino IDE and its
libraries provide a solid foundation for programming and
communication.
➢ It is suitable for simple to moderately complex IoT applications.
5. Particle:
➢ Particle is an IoT platform that offers a comprehensive set of tools
for building and managing IoT applications.
➢ It includes a cloud platform, device management features, and a
web-based integrated development environment (IDE).
➢ Particle supports cellular, Wi-Fi, and mesh networking for device
connectivity.
5|Page
INTERNET OF THINGS (ADVANCE)

6. AWS IoT Core:


➢ Amazon Web Services (AWS) IoT Core is a cloud-based platform
that offers various services to connect, manage, and analyze IoT
devices.
➢ It supports MQTT and HTTP protocols and integrates well with
other AWS services, providing scalability, reliability, and security for
IoT applications.
7. Google Cloud IoT Core:
➢ Google Cloud IoT Core is Google's IoT platform that enables device
connection, data storage, and device management.
➢ It is well-integrated with other Google Cloud services and supports
MQTT and HTTP for communication.

6|Page
INTERNET OF THINGS (ADVANCE)

UNIT 5
IoT APP DEVELOPMENT
LECTURE 2
DEVELOPMENT OF AN IoT APPLICATION

Once the required framework for IoT application development is finalized it


is time for development of the application. The main steps involved in
development of such applications are as follows:

1. Define the requirements for the application

➢ An important step in developing an IoT application is to define the goal


and scope of your app. This helps in defining the objectives.
➢ The scope of your application will include the features that you
require. This could include:
o Device Management

7|Page
INTERNET OF THINGS (ADVANCE)

o Dashboarding
o Device to Mobile Communication
o Over-the-air updates
o Metadata management
o Data visualization

2. Choosing the right hardware

➢ The type of hardware depends on your application requirements.


➢ It could be sensors, GPS trackers, or even wearables. But it is
important to pick devices that are reliable and relevant to the
application.

3. Find the right connectivity protocols

➢ There are several network protocols that you can use like WiFi, 2G,
5G, Bluetooth, LoRa, NB-IoT, or Zigbee.
➢ Depending on the devices used and the availability of resources, one
needs to pick the right channels for connectivity.
➢ For example: If devices are usually used in a home or office
environment, one can use WiFi for data transmission. Whereas if your
devices are going to be in motion or in remote locations, one may use
GSM.

4. Ensure the firmware is well equipped

➢ Firmware are the technical terms for the program that runs your
hardware.

8|Page
INTERNET OF THINGS (ADVANCE)

➢ It is essential to ensure that your firmware is well equipped, or else


one could experience data loss or spend a lot more on data storage
and transmission than necessary.
➢ Make sure that the firmware has the following capabilities:
o Retries for pushing data on network disconnections so that
connectivity issues do not lead to data loss.
o Disk persistence in the absence of network for long periods of
time.
o Batching & compression to save data costs.
o Data encryption using TLS (Transport Layer Security) allows you
to ensure data security for sensitive data.

5. Pick the right cloud platform

➢ The right IoT platform will provide the necessary tools to create an
application that serves the purpose.
➢ In order to choose an IoT cloud platform, the following factors needs
to be considered:
o Uptime
o Data security
o Debugging
o Feature stability
o Security
o Migration capabilities
o Connectivity, and
o Scalability

6. Secure your application


9|Page
INTERNET OF THINGS (ADVANCE)

➢ In IoT security is very important.


➢ IoT is a comparatively new and dynamic technology, which means that
there are constant changes in the process.
➢ Due to this, the security protocols for most IoT projects are not
properly defined.
➢ Also, each device in your project can be a security issue, if not
secured appropriately.

10 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 5
IoT APP DEVELOPMENT
LECTURE 3
IMPLEMENT AND DEPLOY THE APPLICATION IN IoT

Implementing, and deploying an IoT app typically involves the following


stages:

1. Define the IoT Application:

Clearly define the purpose and goals of your IoT application. Identify the
devices and sensors you'll use, the data to be collected, and the actions
app will perform based on that data.

2. Select the IoT Platform or Framework:

Choose a suitable IoT platform or framework that aligns with the project
requirements and provides the necessary tools for developing and
managing IoT devices and data.

3. Hardware and Device Integration:

Set up and connect IoT devices, sensors, and actuators to the selected
platform. This may involve programming and configuring the devices to
communicate with the platform using the supported protocols.

4. Develop the Application Backend:

Create the backend infrastructure for the IoT app. This includes setting
up servers, databases, and cloud services to store and manage data
received from IoT devices.

5. Develop the Frontend Application:

11 | P a g e
INTERNET OF THINGS (ADVANCE)

Create the user interface (UI) for the IoT app. This can be a web
application, a mobile app, or both, depending on your target audience
and use cases.

6. Implement Data Processing and Analytics:

Add data processing and analytics capabilities to the IoT app backend.
This may involve real-time data processing and generating action from
the collected data.

7. Test and Debug:

Thoroughly test the IoT app at different stages of development to ensure


its reliability, accuracy, and performance. Identify and fix any bugs or
issues that arise during testing.

8. Security Measures:

Implement robust security measures to safeguard the IoT devices, data,


and communications. Use encryption, secure authentication methods,
and access control to protect the system from unauthorized access.

9. Deployment:

Once the app is thoroughly tested and deemed ready for deployment,
prepare it for release. Deploy the backend services on the chosen
hosting infrastructure or cloud platform and make the frontend
accessible to users.

10. Monitor and Maintain:

Continuously monitor the app's performance, data flow, and device


connectivity to ensure everything is functioning as expected. Regularly

12 | P a g e
INTERNET OF THINGS (ADVANCE)

update the app to add new features, fix bugs, and enhance security as
needed.

11. User Support and Updates:

Provide ongoing support to users, addressing their inquiries or issues


related to the app. Regularly update the app to enhance its functionality
and accommodate changing requirements.

13 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 5
IoT APP DEVELOPMENT
LECTURE 4

TESTING AND INTEGRATION FOR IoT APPLICATIONS

Testing and integration are crucial stages in the development of an IoT app
to ensure that the application works seamlessly with IoT devices and
services.

The steps involved in testing and integration of an IoT app are as follows:

➢ Unit Testing:
• Perform unit testing on individual components of the IoT app,
including backend services, APIs, and frontend modules.
• This ensures that each unit functions correctly and as expected
in isolation.
➢ Integration Testing:
• Test the integration between different components of the IoT app.
• Verify that the frontend can communicate with the backend, and
data flows correctly between the app and IoT devices.
➢ Device Integration Testing:
• Integrate real IoT devices into the app and test their connectivity,
data transmission, and functionality.
• Ensure that the app can communicate effectively with these
devices and interpret the data received correctly.
➢ Communication Protocol Testing:

14 | P a g e
INTERNET OF THINGS (ADVANCE)

• Test the communication protocols used in the IoT app, such


as MQTT or CoAP, to ensure that data is transmitted
accurately and securely between the app and IoT devices.
➢ Data Validation and Verification:
• Verify the accuracy and integrity of data collected from IoT
devices.
➢ Performance Testing:
• Test the performance of the IoT app under various conditions,
such as high device loads, data traffic, and concurrent user
connections.
➢ Security Testing:
• Conduct security testing to identify potential weaknesses in
the IoT app. Test for secure authentication, encryption, and
access control measures to protect data and devices from
unauthorized access.
➢ Compatibility Testing:
• Ensure that the IoT app works seamlessly across different
devices, operating systems, and web browsers.
➢ Network Connectivity Testing:
• Test the IoT app's performance under different network
conditions, including poor network connectivity and irregular
connection loss.
➢ User Acceptance Testing (UAT):
• Involve end-users in the testing process to validate that the
IoT app meets their expectations and requirements. Gather

15 | P a g e
INTERNET OF THINGS (ADVANCE)

feedback and make necessary improvements based on user


input.
➢ Load and Stress Testing:
• Conduct load and stress testing to determine the app's
behaviour under heavy user and device loads.
➢ Edge Device Testing:
• If your IoT app involves edge computing, test the app's
functionality and performance on edge devices to ensure
smooth operation at the edge of the network.
➢ Monitoring and Debugging:
• Implement monitoring tools to continuously monitor the app's
performance, device connectivity, and data flow. Use
debugging tools to identify and resolve any issues that may
arise in real-time.

16 | P a g e
INTERNET OF THINGS (ADVANCE)

UNIT 5
IoT APP DEVELOPMENT
LECTURE 5

MAINTAIN AND IMPROVE IoT APPLICATIONS

Maintaining and continuously improving an IoT app based on feedback is


essential to meet users' evolving needs and address any issues that arise
during its usage.

Steps to effectively maintain and improve the IoT app based on feedback
are as follows:

1. Collect User Feedback:

Encourage users to provide feedback on their experiences with the IoT


app. Gather feedback through various channels like feedback forms,
surveys, social media, and customer support interactions.

2. Analyse Feedback Data:

Thoroughly analyse the collected feedback data to identify common


issues and areas for improvement.

3. Prioritize Improvement Areas:

Based on the feedback analysis, prioritize the identified improvement


areas. Focus on addressing critical issues and high-impact features.

4. Iterative Development:

Adopt an iterative development approach to implement updates and


improvements.
17 | P a g e
INTERNET OF THINGS (ADVANCE)

5. Bug Fixing:

Address reported bugs and issues punctually. Fix critical bugs


immediately to prevent further disruptions to the app's functionality.

6. Enhance User Interface (UI) and User Experience (UX):

Take user feedback into account while improving the app's UI and UX.
Make the app more user-friendly.

7. Performance Optimization:

Continuously monitor the app's performance and identify areas for


optimization i. e. reduce latency and improve response times to enhance
user experience.

8. Security Updates:

Stay alert about security threats and address any reported security
issues quickly.

9. A/B Testing and Experimentation:

Conduct A/B testing and experimentation for new features or design


changes. This approach allows you to compare different versions of the
app and understand user preferences.

10. User Training and Documentation:

If necessary, provide user training materials or documentation for new


features and changes. Clear communication can help users understand
and utilize new functionalities effectively.

18 | P a g e

You might also like