0% found this document useful (0 votes)
9 views10 pages

UNIT IV

The document provides an overview of developing IoT applications using Python, highlighting its benefits such as ease of learning, multi-paradigm support, and broad library availability. It also discusses various IoT tools like Arduino, Raspbian, and Eclipse IoT, along with the importance of selecting appropriate hardware, connectivity protocols, and security measures in IoT application development. Additionally, it covers the implementation of IoT concepts in Python through libraries and examples, emphasizing the use of platforms like Raspberry Pi and Micro Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

UNIT IV

The document provides an overview of developing IoT applications using Python, highlighting its benefits such as ease of learning, multi-paradigm support, and broad library availability. It also discusses various IoT tools like Arduino, Raspbian, and Eclipse IoT, along with the importance of selecting appropriate hardware, connectivity protocols, and security measures in IoT application development. Additionally, it covers the implementation of IoT concepts in Python through libraries and examples, emphasizing the use of platforms like Raspberry Pi and Micro Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

DEVELOPING IOTS INTRODUCTION TO PYTHON


 Python becomes a great choice when it comes to IoT.
 We can either use it for the backend side of development or the software
development of devices.
 Moreover, Python is available to work on Linux devices, and we can make use of
Micro Python for microcontrollers.
 The main characteristics of Python are:
 Multi-paradigm programming language.
o Python supports more than one programming paradigms including object-
oriented programming and structured programming.
 Interpreted Language.
o Python is an interpreted language and does not require an explicit
compilation step.
o The Python interpreter executes the program source code directly, statement
by statement, as a processor or scripting engine does.
 Interactive Language
o Python provides an interactive mode in which the user can submit
commands at the Python prompt and interact with the interpreter directly.
Benefits of Python
Easy to learn, read and maintain
 Python is a minimalistic language with relatively few keywords, uses English
Keywords and has fewer syntactical constructions as compared to other languages.
 Reading Python programs feels like English with pseudo-code like constructs.
 Python is easy to learn yet an extremely powerful language for a wide range of
applications.
Object and Procedure Oriented
 Python supports both procedure oriented programming allows and object oriented
programming.
 Procedure oriented paradigm allows programs to written around objects that
include both data and functionality.
 Procedure oriented paradigm allows programs to be written around procedures or
functions that allow reuse of code.
Extendable
 Python is an extendable language and allows integration of low level modules
written in languages such as C/C++.
 This is useful when you want to speed up a program
Scaleable
 Due to the minimalistic nature of Python, it provides manageable structure for large
programs.
Portable
 Since python is an interpreted Language, programmers do not have to worry about
compilation, linking and loading of programs.
 Python programs can be directly executed from the source.
Broad Library Support
 Python has a broad library support and works on various platforms such as Windows,
Linux, Mac etc

2. INTRODUCTION TO DIFFERENT IOT TOOLS


 IoT Tools stands for the Internet of Things Tools.
 It is a network or connection of devices, vehicles, and equipment applying
embedded electronics, home appliances, buildings and many more.
 This helps in collecting and exchanging different kinds of data.
 It also helps the user to control the devices remotely over a network.
 These tools help the developers to explore and create innovative IoT applications
and devices.
 The tools used can either be a hardware setup, or a standalone software setup or an
integrated setup.
 Some of the commonly used IOT Tools are
Arduino
 It is an open-source prototyping platform that offers both IoT hardware and
software.
 Hardware specifications can be applied to interactive electronics and software
includes Integrated Development Environment (IDE).
 It is the most preferable IDEs in all IoT development tools.
 This platform is easy and simple to use.
Raspbian
 This IDE is created for Raspberry Pi board.
 It has more than 35000 packages and with the help of precompiled software, it
allows rapid installation.
 It was not created by the parent organization but by the IoT tech enthusiasts. For
working with Raspberry Pi, this is the most suitable IDE available.

Platform IoT
 It is a cross-platform IoT IDE.
 It comes with the integrated debugger.
 It is the best for mobile app development and developers can use a friendly IoT
environment for development.
 A developer can port the IDE on Atom editor or it can install it as a plugin.
 It is compatible with more than 400 embedded boards and has more than 20
development frameworks and platforms.
 It offers a remarkable interface and is easy to use.
Eclipse IoT
 This tool or instrument allows the user to develop, adopt and promote open
source IoT technologies.
 It is best suited to build IoT devices, Cloud platforms, and gateways.
 Eclipse supports various projects related to IoT.
 These projects include open-source implementations of IoT protocols, application
frameworks and services, and tools for using Lua programming language which is
promoted as the best-suited programming language for IoT.

Tessel 2
 It is used to build basic IoT prototypes and applications.
 It helps through its numerous modules and sensors.
 Using Tessel 2 board, a developer can avail the following features
o Ethernet connectivity,
o Wi-Fi connectivity,
o two USB ports,
o a micro USB port,
o 32MB of Flash,
o 64MB of RAM.
 Additional modules can also be integrated like cameras, accelerometers, RFID, GPS,
etc.
 Tessel 2 can support Node.JS and can use the libraries of Node.JS.

3. DEVELOPING APPLICATIONS THROUGH IOT TOOLS

Figure 1: Flow of Application Development


Operating System
 IoT operating systems enable users to perform basic computer activities on an
internet-connected device.
 IoT OSs run on IoT devices and connects to a larger network of devices.
 These operating systems offer computer-like capabilities by providing memory and
data storage processing capability.
 These systems may run and process any program that is installed on the device.
 Operating systems for IoT devices communicate with IoT device management
software.
 Some ioT tools like Arduino which are single board microcontrollers, doesn't have an
operating system, but can be programmed with firmware using several IDEs, including
the Arduino IDE.

Programming Language
 Programming for IoT is usually a polyglot (multiple languages) effort since the
Internet-of-Things (IoT) is a system of inter-related computing devices that are
provided with unique identifiers and the ability to transfer data over a network.
 The choice of programming-language depends on the capability and purpose of the
device.
 IoT encompasses a variety of devices including edge devices, gateways, and cloud
servers.
 The most popular languages in IoT are Java, C, C++, Python, JavaScript, Node.js,
Assembler, PHP, C#, Lua, R, Go, Ruby, Swift and Rust.

Debugging
 The important technique to find and remove the number of errors or bugs or defects
in a program is called Debugging.
 It is a multistep process in software development.
 It involves identifying the bug, finding the source of the bug and correcting the
problem to make the program error-free.

Hardware
 The Hardware development includes the following steps:
o Design the schematic circuit Diagram
o Make the required connections to the IoT Tools and other peripherals with the
help of jumper wires and cables with reference to the circuit diagram.
o Connect the power supply to the respective tool.
o Execute the program.
Openness
 Openness is the technical method includes transparent Internet standards
development where someone can participate on a similar basis, and open
nonproprietary protocols that anyone can execute.
 It supports more opportunity for variety of thought.
Figure 2: Openness in IoT Tools

 Some of the benefits are transparency, convenience, and fast development resulting
in significant cost savings.
 The most common openness types encountered in open IoT platforms is open-
source, open standards, open APIs, open data, and open layers.

4. DEVELOPING SENSOR BASED APPLICATION THROUGH EMBEDDED SYSTEMS


An IoT application can help you monitor your business, improve efficiency and make better
decisions based on device data that it collects and analyzes.

Figure 3: Developing Sensor Based Application through embedded system

Define the requirements for the application


 An important step in developing an IoT application is to define the goal and scope of
your application.
 This entails you getting to the bare bones of your objective.
 Decide what you want to achieve once the app is live. The goals may include:
o Tracking movement or location in real-time, allowing users to see where their
devices are throughout the day (e.g., EVs owned by a delivery chain)
o Monitoring temperature or humidity levels, which could help you manage
heating/cooling systems (e.g., hospitals)
o Using sensors to detect harmful gases such as carbon monoxide, methane, and
hydrogen sulphide at industrial plants (e.g., refineries)
 The scope of your application will include the features that you require. This could
include:
o Device Management
o Dashboarding
o Device to Mobile Communication
o Remote Shell
o Over-the-air updates
o Device Shadow
o Metadata management
o Data visualization
 When you define the requirements of your IoT application, you will be able to
develop an app that will speed up your processes and bring down your costs.

Choosing the right hardware


 The type of hardware depends on your project requirements.
 It could be sensors or GPS trackers
 But it is important to pick devices that are reliable and relevant to your project.
 Take a look at the sensors that are available.
 For example, if you are developing smart vehicles, you will need different sensors
like GPS or altitude monitors.
 Depending on whether your device is consumer-based, industrial, or automobile-
focused, you will have to find sensors that are appropriate.
 Industrial and automotive sensors need to be far more reliable than those on
consumer devices, as they undertake more sensitive tasks.
 Once you have settled on the sensors, you also need to look at the larger hardware
architecture and figure out if you need microcontrollers or microprocessors on the
device to process the data.
 These details may seem overwhelming, but it is important to get them right as
changing your hardware down the road is going to be time-consuming and
expensive.

Find the right connectivity protocols


 There are several network protocols that you can use like Wi-Fi, 2G, 5G, Bluetooth,
LoRa, NB-IoT, or Zigbee.
 Depending on your devices and the availability of resources, you need to pick the
right channels for connectivity.
 If your devices are usually used in a home or office environment, for example, you
can use WiFi for data transmission.
 Whereas if your devices are going to be in motion or in remote locations, you may
want to pick GSM.
 So it is important to pick the right protocol for the use cases you have in mind. This
will also affect your cost structures. Adding GSM connectivity will mean you will have
to incur cellular data charges whereas with WiFi & Bluetooth these concerns don’t
exist.

Ensure the firmware is well equipped


 Firmware, or device-side software, are the technical terms for the program that runs
your hardware.
 It is essential to ensure that your firmware is well equipped, or else you could
experience data loss, and end up spending a lot more on data storage and
transmission than necessary.
 Ensure 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. This is
absolutely necessary if your devices are going to be mobile or remotely located.
o Batching & compression to save data costs. Data costs can pile up over time and
drastically bring down your ROI(Return of Investment)

 Data encryption using TLS (Transport Layer Security) allows you to ensure data
security for sensitive data.
 Reliable downloads of over-the-air update images will ensure frequent updates that
improve efficiency and device performance over time.

Pick the right cloud platform


 The right IoT platform will hand you the necessary tools to create an application that
serves your purpose
 In order to choose an IoT platform that works for you, you need to look for the
following:
o Uptime
o Data security
o Debugging
o Feature stability
o Security
o Migration capabilities
o Connectivity, and
o Scalability

Critical addition: Secure your app


 IoT security is massively 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 defined.
 Also, each device in your project can be a security issue, if not secured appropriately.
 Your IoT application is the melting pot of all the data that your devices collect.
 It can be used to redirect your devices or even snoop on your customers. Therefore,
proper security is of utmost importance.
 When developing your app, make sure that you put security protocols in place,
ensure encryption for all the data being stored and transferred, and employ
appropriate access control.

5. IMPLEMENTING IOT CONCEPTS WITH PYTHON


 IoT Concepts in Python are implemented using libraries.
 For implementing an IOT Concepts, below mentioned procedure is followed
o Import required modules from the libraries
o Set input/output mode// (This is optional)
o Create an object of the pin
o Use the desired function.

Import required modules from the libraries


 The required modules are imported in the following format:
from gpiozero import LED
 Here gpiozero is the name of the library.
 LED is the function to be imported from the library

Set input/output mode


 The input/output mode is set in the following format
GPIO.setmode (GPIO.BOARD)
GPIO.setup (18, GPIO.OUT)
 Here the setmode defines whether the program is using BOARD or BCM (Broadcom
chip-specific)
 Here the setup defines whether GPIO pin is configured as input or Output

Create an object of the pin


 The required pin number is written in the following format
LedPin=18
 Here LedPin is the name given to the pin number 18

Use the desired function


 The function is written in the following format
GPIO.output (LedPin, True)
 This instruction is used to keep the LedPin high.
 Some of the commonly used libraries are as mentioned below:

Library Description
RPi.GPIO  Used to control the GPIO on a Raspberry Pi.
 Not Suitable for real time data
gpiozero  It allows the programmers control the GPIO pins by importing them directly at the start
of a code.
time  It allows functionality like getting the current time, pausing the Program from executing,
etc.
machine  It contains specific functions related to the hardware on a particular board.
 Most functions in this module allow to achieve direct and unrestricted access to and
control of hardware blocks on a system (like CPU, timers, buses, etc.).
mraa  Used for I2C,UART & SPI
Mysqldb  Used to send data to the internet
 Generating some predictions using ML
Numpy  Used to read sensor data in bulk from my database and work on them using inbuilt
functions
Tkinter  Used for GUI development
 Used in situations such as functionality testing or repeated execution of the same code
OpenCv  Used for image Processing
 Some of the best solutions for implementing IoT in the Python programming language
are as follows:
o Python on Raspberry Pi
o Python on PyBoard
o ESP8266, ESP32 with Micro python

Python on Raspberry Pi
 Python is pre-installed in the operating system, and the only objective left for us is to
write the coding script.
 In Raspberry Pi, we can control the I/O ports on the expansion bar of the Raspberry
Pi.

Python on PyBoard
 PyBoard runs Micro Python, a lightweight implementation of the standard Python
interpreter.
 The Micro Python PyBoard is a compact electronic circuit board that runs Micro Python
on the bare metal, giving you a low-level Python operating system that can be used to
control all kinds of electronic projects.
 The built-in pyb module contains functions and classes to control the peripherals
available on the board, such as UART, I2C, SPI, ADC, and DAC.
 Below is an example of Micro Python Programming on PyBoard

import pyb
led = pyb.LED (4)
while True:
led.on()
pyb.delay(1000)
led.off()
pyb.delay(1000)

ESP8266, ESP32 with Micro python


 It is self-contained SOC with integrated TCP/IP protocol stack that can give any
microcontroller access to your WiFi network.
 Like PyBoard, this module also uses Micro Python.
 Micro Python is an implementation of the Python 3 programming language which is
optimized to run on many microcontrollers.

You might also like