FSIoT Chapter4
FSIoT Chapter4
INTRODUCTION TO PYTHON
PROGRAMMING
1
2.1 Sensors and Actuators
2
Cont’
Figure 2.1 The outline of a simple sensing operation
⚫ Actuators are devices that use energy to perform a specific task or to control a
system.
⚫ They are often used to convert electrical signals into physical motion or other types
of energy.
⚫ Examples of actuators include motors, solenoids, relays, and hydraulic cylinders.
3
Figure 2.2 The outline of a simple actuation mechanism
2.5 Raspberry pi Platform and
Processor
⚫ Raspberry Pi is a small, low-cost computer developed by the
Raspberry Pi Foundation, a UK-based charity organization.
4
Cont’
⚫ Raspberry Pi 4, have even more powerful processors, with options
ranging from a 1.5 GHz quad-core ARM Cortex-A72 processor to a
2.0 GHz 64-bit Hexa-core ARM Cortex-A72 processor.
⚫ These pins are located on the Raspberry Pi circuit board's top edge and
labeled with their function and numbering.
⚫ There are a total of 40 pins on the Raspberry Pi, which are divided into
two rows of 20 pins each.
⚫ These pins include power and ground pins and a range of digital
input/output (GPIO) pins that can be used to read digital signals or
control devices such as LEDs or motors.
8
9
10
⚫ Total pins on Raspberry
Pi
11
12
13
Architecture of Raspberry Pi
14
15
16
17
Interfacing Raspberry Pi with basic
peripherals
Introduction
24
25
2.6 Raspberry pi Vs. Arduino
Sno Arduino Raspberry pi
Control unit of Arduino is from Atmega While control unit of Raspberry Pi is from
1.
family. ARM family.
While Raspberry Pi is based on a
2. Arduino is based on a microcontroller.
microprocessor.
26
S.no Arduino Raspberry pi
It has a higher I/O current drive While Raspberry Pi has a lower I/O
9.
strength. current drive strength.
While it consumes about 700 MW of
10. It consumes about 200 MW of power.
power.
13. It has higher current drive strength. It has lower current drive strength.
16 two tiny cores Arduino with 32 Mhz Single core and 700 MHz
27
Introduction to Python Programming
Python is a high-level, versatile programming language known for its
simplicity and readability, making it an excellent choice for beginners
and experienced developers alike.
Created by Guido van Rossum and first released in 1991, Python
emphasizes code readability and allows developers to express
concepts with fewer lines of code than many other programming
languages.
28
Why Learn Python?
Easy to Learn: Python has simple syntax (rules of
writing code), which makes it less complex than other
programming languages.
Versatile: You can use Python for almost anything –
from building websites to analyzing data, creating video
games, or even controlling robots.
Large Community Support: Since Python is so
popular, there’s a huge community of programmers
ready to help with resources, tutorials, and forums.
29
Key Features of Python:
1. Simple and Readable Syntax: Python’s syntax is clean and easy to
understand, which makes it ideal for beginners. The use of indentation instead
of braces makes code look neat and improves readability.
2. Interpreted Language: Python is an interpreted language, meaning that it
executes code line by line, which allows for easier debugging and faster
development cycles.
3. Dynamically Typed: Variables in Python do not need explicit declaration, and
the type of a variable can change during runtime, making coding flexible.
4. Extensive Standard Library: Python comes with a rich set of libraries and
frameworks that support a wide range of programming tasks, from web
development to scientific computing, machine learning, and automation.
5. Cross-platform Compatibility: Python can be run on various operating
systems such as Windows, macOS, and Linux, making it a portable language.
6. Open Source and Community Support: Python is free and open-source,
supported by a large and active community that contributes to its vast
repository of packages and tools.
30
Python Syntax and Basics
Let’s start with the basics of Python. Here are some important concepts:
1. Variables: In Python, you don’t need to declare a variable's type. Python
automatically understands whether it’s a number, string, or something else.
age = 18 # Integer
name = "Alice" # String
2. Printing: To output something in Python, we use the print() function.
print("Hello, World!")
3. Data Types:
o Integers: Whole numbers like 5, 10, -3.
o Floats: Decimal numbers like 3.14, 0.5.
o Strings: Text inside quotes, like "Python", "Coding".
o Booleans: True or False values.
31
4. Arithmetic: Python can handle basic math operations:
x = 5 + 3 # Addition
y = 10 - 2 # Subtraction
z = 4 * 2 # Multiplication
a = 10 / 2 # Division
5. Conditional Statements: Python allows you to make
decisions in your program using if, else, and elif
(else if) statements.
age = 18
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.") 32
6. Loops: Loops let you repeat code multiple times. The two main types are for
loops and while loops.
o For Loop: Useful for iterating over a range of numbers or a list of items.
for i in range(5):
print(i) # This will print numbers from 0 to
4
o While Loop: Repeats as long as a condition is true.
count = 0
while count < 3:
print("Counting:", count)
count += 1 # Increment count
7. Functions: Functions allow you to write code once and reuse it whenever you
need. It helps to organize your code better.
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
33
Basic Python Concepts:
Variables: Used to store data values. Python does not require declaring a
variable’s type.
x = 5
name = "John"
Data Types: Python supports several data types like integers, floats, strings,
lists, tuples, sets, and dictionaries.
number = 10 # Integer
pi = 3.14 # Float
fruits = ['apple', 'banana', 'cherry’] # List
Conditional Statements: Python supports if-else statements to perform
different actions based on conditions.
if x > 0:
print("Positive")
else:
print("Non-positive")
34
Applications of Python:
Web Development: Using frameworks like Django and
Flask.
Data Science and Machine Learning: Libraries like
NumPy, pandas, TensorFlow, and scikit-learn are widely
used for data analysis and AI tasks.
Automation and Scripting: Python is frequently used for
automating repetitive tasks, making it popular in the
DevOps world.
Game Development: Libraries like Pygame make it
possible to develop simple games.
35
Loops: Python supports for and while loops to execute code
repeatedly.
for i in range(5):
print(i)
Functions: Functions in Python are defined using the def
keyword and allow for code reuse.
def greet(name):
return f"Hello, {name}!"
36
Hands-On Activity
Let’s write a simple program together. Here’s an example:
# Program to calculate the area of a
rectangle
width = int(input("Enter the width: "))
# Taking input from the user
height = int(input("Enter the height:
"))
39
40
What are the Components of Software Defining
Networking (SDN)?
The three main components that make the SDN are:
•SDN Applications: SDN Applications relay requests or
networks through SDN Controller using API.
•SDN Controller: SDN Controller collects network
information from hardware and sends this information
to applications.
•SDN Networking Devices: SDN Network devices help
in forwarding and data processing tasks.
Where is Software Defined Networking Used?
•Enterprises use SDN, the most widely used method for
application deployment, to deploy applications faster
while lowering overall deployment and operating costs.
SDN allows IT administrators to manage and provision
network services from a single location.
•Cloud networking software-defined uses white-box
systems. Cloud providers often use generic hardware so41
42
43
44
45
46
47
SDN Architecture
In a traditional network, each switch has its own data
plane as well as the control plane.
49
SDN Architecture
A typical SDN architecture consists of three layers.
•Application Layer: It contains the typical network
applications like intrusion detection, firewall, and
load balancing.
•Control Layer: It consists of the SDN controller which
acts as the brain of the network. It also allows hardware
abstraction to the applications written on top of it.
•Infrastructure Layer: This consists of physical
switches which form the data plane and carries out the
actual movement of data packets.
50
51
52
Software Defined
Networking in IoT
Software−defined Networking on the Internet of Things
(IoT) presents a formidable architecture that enhances
the adaptability and flexibility of networks.
54
Significance of Software Defined
Networking in IoT
Software−Defined Networking (SDN) on the Internet of
Things (IoT) signifies a considerable improvement over
traditional networking, delivering a range of essential
benefits:
1. Enhanced Control with Unparalleled
Speed and Flexibility:
SDN eliminates the need for manual
configuration of various hardware devices from
different vendors.
Instead, developers can exert control over
network traffic by programming a software-
based controller adhering to open standards.
This approach empowers networking managers
with the freedom to select networking
equipment and communicates with multiple 55
2. Customizable Network Infrastructure:
56
3. Robust Security:
58
Risks of Software Defined Networking in
IoT
From bolstering agility and control to streamlining
management and configuration, SDN presents a
compelling case for adoption.
However, it is imperative to acknowledge the
potential risks that accompany this technological
marvel.
One prominent concern lies in the centralized nature
of the controller, which, if compromised, could act as
a single point of failure.
Nevertheless, proactive measures can mitigate this
vulnerability by implementing controller redundancy
throughout the network, complete with automatic
fail−over capabilities.
While this endeavor may incur additional expenses, it
aligns with the principles of maintaining business
continuity, akin to the judicious addition 59of
Distinguishing Software Defined
Networking in IoT from Traditional
Networking
The dissimilarity between Software−Defined
Networking (SDN) and traditional networking lies
primarily in their underlying infrastructure.
While traditional networking relies on hardware
components, SDN operates on a software basis.
This fundamental variance endows SDN with
remarkable flexibility that surpasses the confines of
traditional networking.
Through a software−driven control panel, SDN
empowers administrators to oversee the network,
modify configuration settings, allocate resources, and
augment network capacity from a centralized user
interface, all without necessitating additional hardware
deployment.
60
Moreover, SDN and traditional networking diverge in
terms of security.
61
SUMMERY
• In Conclusion, The Internet of Things (IoT) networks
may work more efficiently with the help of
Software−Defined Networking (SDN).
• SDN's ability to provide abstractions and its different
varieties, such as Open SDN, API SDN, Overlay Model
SDN, and Hybrid Model SDN, cater to the unique
demands of IoT applications.
• However, there are also risks associated with SDN,
particularly regarding the centralized nature of the
controller.
• Distinctions between SDN and traditional networking
include the software−driven infrastructure of SDN, its
flexibility, and improved security attributes.
• Safeguarding the centralized controller is crucial to
maintaining the overall security of SDN networks.
62
Data Handling and Analytics
What is Data Analytics?
Data analytics, also known as data analysis, is a
crucial component of modern business operations.
It involves examining datasets to uncover useful
information that can be used to make informed
decisions.
This process is used across industries to optimize
performance, improve decision-making, and gain a
competitive edge.
63
What is Data Analytics?
65
Process of Data Analytics
Data analysts, data scientists, and data
engineers together create data pipelines which helps
to set up the model and do further analysis. Data
Analytics can be done in the following steps which are
mentioned below:
•Narrative Analytics is used for working with data acquired from diaries,
interviews and so on.