0% found this document useful (0 votes)
4 views13 pages

CP4291 IOT UNIT 5

This document outlines the use of Raspberry Pi in IoT projects, detailing its capabilities, advantages, and application in home automation and industrial monitoring. It describes the hardware setup, software requirements, and the process of creating a sensor project, including interfacing with various sensors and managing data. The document emphasizes the importance of Raspberry Pi as a low-cost, efficient solution for IoT applications, providing a comprehensive guide for development.

Uploaded by

Sivasankar
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)
4 views13 pages

CP4291 IOT UNIT 5

This document outlines the use of Raspberry Pi in IoT projects, detailing its capabilities, advantages, and application in home automation and industrial monitoring. It describes the hardware setup, software requirements, and the process of creating a sensor project, including interfacing with various sensors and managing data. The document emphasizes the importance of Raspberry Pi as a low-cost, efficient solution for IoT applications, providing a comprehensive guide for development.

Uploaded by

Sivasankar
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/ 13

lOMoARcPSD|19383840

UNIT 5

Data Structures (Anna University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


UNIT V IOT PROJECTS ON RASPBERRY PI

Building IOT with RASPBERRY PI- Creating the sensor project - Preparing
Raspberry Pi – Clayster libraries – Hardware Interacting with the hardware -
Interfacing the hardware- Internal representation of sensor values - Persisting
data - External representation of sensor values - Exporting sensor data

5.1 Building IOT with RASPBERRY PI

As the world is getting technologically forward, IoT is coming to our personal lives
blurring the digital and physical space. But when we talk about IoT in home automation
and industrial process monitoring system, it makes the use of PC-based servers. Hence
it becomes necessary to keep sever on all the time which ultimately increase the cost of
system. The solution for this problem is to use embedded web server instead of PC
based server which can have single chip implementation of Ethernet networking
standards. And this can be achieved by using Raspberry Pi. By embedding Ethernet
onto the device, it has the competency to interconnect via Ethernet without using PC;
the server enables web access to automate and monitor the system and provides
mountable networking solution that is enhanced for instrumentation and industrial
automation.

Raspberry Pi

It is a low cost, low-power, credit-card sized computer that plugs into a computer
monitor or TV and uses standard keyboard and mouse to compute from browsing the
internet and playing high-definition video to making spreadsheets, word processing and
playing games.

A Raspberry Pi is of small size i.e., of a credit-card-sized single-board computer, The


first generation of Raspberry (Pi 1) was released in the year 2012, which has two
types of models namely model A and model B.

1
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


Raspberry Pi

In the subsequent year, A+ and B+ models were released. Again in 2015, Raspberry Pi2
model B was released and an immediate year Raspberry Pi3 model B was released in
the market.

Raspberry Pi can be plugged into a TV, computer monitor, and it uses a standard
keyboard and mouse. It is user-friendly as it can be handled by all the age groups. It
does everything you would expect a desktop computer to do like word-processing,
browsing the internet spreadsheets, playing games to playing high definition videos. It
is used in many applications like in a wide array of digital maker projects, music
machines, parent detectors to the weather station and tweeting birdhouses with infrared
cameras.

Working

It is more like complete Linux computer but slower than modern desktop or laptop and
enables people of all ages to learn how to program in languages like scratch and python.
Due to its affordable price and compact size, it has been adopted by professionals,
college students and many more. The best thing about Raspberry Pi is that even with
the minimum knowledge of coding; anyone can program it in a way they like.

There are two ways to connect Raspberry Pi to other devices, wired and wireless
sources. The wired source can be connected through HDMI, VGA, USB cables etc. and
the wireless source could be connected using Bluetooth devices, closed controlled
networks like NFC devices or wide-range Wi-Fi or internet services. It is connected to
the other devices through integrated circuits or the GPIO and can be used to get desired
output after coding. Once the goal of the device is finalized, software apps like
MATLAP, Java, Eclipse etc. are used to program the apps accordingly.

Advantages

• Less Power Consumption

• No moving parts

• Small form factors

• No noise

• Status lights

• Expansion capabilities

• Built-in HDMI capable graphics

IoT Design Methodology

2
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


All web application is developed natively in Java Programming Language. It includes
java technologies similar to JSP, servlets, hibernate, and web services, etc., the latest
version of net beans IDE is basically used for web application development. Additional
technologies like bootstrap, javascript, jQuery, etc are used to handle UI and client-side
validations. Cisco provided APIs are used to develop application related to Cisco IP
phones.

IOT uisng Raspberry Pi

Five steps are used in web applications

• Installing Apache Webserver

• Create a My SQL database system

• Developed web application For the GUI (Graphical User Interface)

• Write lots of PHP, JAVA script, CSS and Python Programs for the Web
Application

• Host Web application on our Web server

The following are essential to get started

• Video cable to suit the TV or monitor used

• SD card containing Linux Operating system

• Power supply (see Section 1.6 below)

• USB keyboard

• TV or monitor (with DVI, HDMI, Composite or SCART input)

Recommended optional extras include

3
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


• Internet connection, Model B only: LAN (Ethernet) cable

• USB mouse

• Powered USB hub

• Internet connection, Model A or B: USB WiFi adaptor

What is a System on Chip?

A system on chip is a complex IC that integrates the functional elements into a single
chip or chipset. It is a programmable processor on a chip memory, accelerating function
hardware, software, hardware, and analog components.

System on Chip

Benefits of SoC

• Lower power consumption

• Reduces size

• Reduces overall system cost

• Increases performance

Internet Gateway Device

Internet Gateway Device has the ability to route data approaching from the WSN
network to the internet and Send data coming from the internet to the WSN network. It
is like a Wi-Fi router for the Internet of Things. In the internet gateway device, we use
raspberry pi model B, it features a quad-core ARM Cortex- A7 CPU is running at

4
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


900MHz (for a 6x presentation improve on the first generation Raspberry Pi Model B+)
and 1GB of LPDDR2 SDRAM (for a 2x memory increase). And yes, there is total
compatibility with Raspberry Pi1 we are secured. Broadcom’s new SoC, the BCM2836,
is the key factor.Five steps we are using Internet Gateway Device

• Port Linux operating system on Raspberry Pi

• Modify Linux to work with Our Prototype

• Developed Python Library for Communication of RPI with Xbee ZB

• Wrote Program from sensors and Device controlling

• Create WI-FI functionality on RPI for Internet Connection

WSN Nodes

A wireless sensor network (WSN) consists of three main components: nodes, gateways,
and software. The spatially dispersed measurement nodes interface with the sensors to
monitor assets or their surroundings. The acquired information is wirelessly transmitted
to the gateway, which provides a connection to the wired globe where you can collect,
procedure, analyze, and present your measurement information using the software.
Routers are an individual type of dimension node that you can use to expand the distance
and dependability in a WSN. Sensors can be dispersed on the roads, vehicles, hospitals,
buildings, people and allow dissimilar applications such as medical services, battlefield
operations, disaster response, disaster relief, and environmental monitoring.

IoT Applications

• Weather security and temperature cam

• The working doctor who props with raspberry pi

• Sensually an air quality monitoring hat

• Beer and wine fridge of awesomeness

• Raspberry pi Internet doorbell

• Internet of things toilet

• Train your rat behavioural science at home

• Pebbly smart doorbell

• The raspberry pi microwave

This is all about IoT using Raspberry Pi. Currently, IoT is made up of a loose collection
of different, purpose-built networks. Today’s cars, intended, for example, have multiple

5
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


networks to control engine function, safety features, communication systems, and so
on. Commercial and residential buildings also have various control systems for heating,
venting, and air condition (HVAC), telephone service, security, and lighting.

As IoT evolves, these networks and a lot of others will be connected with additional
security, analytics, and management capabilities. This will allow IoT to become even
more powerful in what it can help people achieve.

5.2 Creating the sensor Project

The development of a Raspberry Pi sensor project is broken down into six steps.
Here’s a simple overview:

1. Firstly, you will set up the basic structure of a console application.

2. Then, you will configure the hardware and learn to sample sensor values and
maintain a useful historical record.

3. After adding HTTP server capabilities and other useful web resources to the
project, you will publish the sensor values collected on the internet.

4. You will then handle the persistence of sampled data in the sensor, so it can
resume after outages or software updates.

5. The next step will teach you how to add a security layer requiring user
authentication to access sensitive information on top of the application.

6. In the last step, you will learn how to overcome one of the major obstacles in the
request/response pattern used by HTTP, that is, how to send events from the
server to the client.

5.3 Preparing Raspberry Pi for sensor project


In this tutorial, you will see the use of Raspberry Pi Model B with the following:
▪ An SD card with the Raspbian operating system installed
▪ A configured network access, including Wi-Fi, if used
▪ User accounts, passwords, access rights, time zones, and so on, all configured
correctly
The sensor project will be developed on a remote PC using C#, as it’s a modern
programming language that allows complete flexibility with IoT. It also allows you to
interchange code between Windows, Linux, Macintosh, Android, and iOS platforms.
Once a project is compiled, executable files are deployed to the corresponding

6
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5


Raspberry Pi and then executed. Since the code runs on .NET, any language out of a
large number of CLI-compatible languages can be used.
To prepare Raspberry for the execution of the .NET code, you need to install
Mono, which contains the Common Language Runtime for .NET that will help
you run the .NET code on Raspberry. This can be done by executing the following
commands in a terminal window in Raspberry Pi:
[bash] $ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install mono-complete
[/bash]
Your device is now ready to run the .NET code.

5.4 Hardware: Sensor used in Raspberry Pi IoT project

The sensor prototype will measure three things: light, temperature, and motion.
To summarize, here is a brief description of the components:
▪ The light sensor is a simple ZX-LDR analog sensor that will connect to a
four-channel analog-to-digital converter (Digilent Pmod AD2). This is
then connected to an I2C bus that will connect to the standard GPIO pins
for I2C. Note that The I2C bus permits communication with multiple
circuits using synchronous communication, employing a Serial Clock Line
(SCL) and Serial Data Line (SDA) pin. This is a common way to
communicate with integrated circuits.
▪ The temperature sensor (Texas Instruments TMP102) connects directly to
the same I2C bus.
▪ The SCL and SDA pins on the I2C bus use recommended pull-up resistors
to ensure they are in a high state when nobody actively pulls them down.
▪ The infrared motion detector (Parallax PIR sensor) is a digital input that
can be connected to GPIO 22.
▪ Four LEDs will also be added to the board. One of these is green and is
connected to GPIO 23. This will show when the application is running. The
second one is yellow and is connected to GPIO 24. This will show when
measurements are done. The third one is yellow and is connected to GPIO
18. This will show when an HTTP activity is performed. The last one is
red and is connected to GPIO 25. This will show when a communication
error occurs.
▪ The pins that control the LEDs are first connected to 160 Ω resistors before
they are connected to the LEDs, and then to ground. All the hardware of

7
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5

the prototype board is powered by the 3.3 V source provided by Raspberry


Pi. A 160 Ω resistor connected in series between the pin and ground ensures
that the LED emits a bright light.
The following figure shows a circuit diagram of the prototype board:

5.5 Interacting with the hardware


Interaction with the hardware is done using corresponding classes defined in
the Clayster.Library.RaspberryPi library. For instance, digital output is handled
using the DigitalOutput class and digital input with the DigitalInput class.
Devices connected to an I2C bus are handled using the I2C class. There are also
other generic classes, such as ParallelDigitalInput and ParallelDigitalOutput,
which handle a series of digital input and output at once.
The SoftwarePwm class handles a software-controlled pulse-width modulation
output. The Uart class handles communication using the UART port available on
Raspberry Pi. There’s also a subnamespace called Devices where device-specific
classes are available.
In the end, all classes communicate with the static GPIO class, which is used to
interact with the GPIO layer in Raspberry Pi.
Each class has a constructor that initializes the corresponding hardware resource,
methods and properties to interact with the resource, and a Dispose method that
releases the resource.
5.6 Interfacing the hardware
The hardware interfaces to be used for the LEDs are as follows:
[csharp] private static DigitalOutput executionLed = new DigitalOutput (23,
true);
private static DigitalOutput measurementLed = new DigitalOutput (24, false);
private static DigitalOutput errorLed = new DigitalOutput (25, false);
private static DigitalOutput networkLed = new DigitalOutput (18, false);
[/csharp]
Use a DigitalInput class for the motion detector:
[csharp] private static DigitalInput motion = new DigitalInput (22);[/csharp]
With the temperature sensor on the I2C bus, which limits the serial clock
frequency to a maximum of 400 kHz, interface it as follows:
[csharp] private static I2C i2cBus = new I2C (3, 2, 400000);
private static TexasInstrumentsTMP102 tmp102 =
new TexasInstrumentsTMP102 (0, i2cBus);[/csharp]

8
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5

We interact with the light sensor using an analog-to-digital converter as follows:


[csharp] private static AD799x adc =
new AD799x (0, true, false, false, false, i2cBus);[/csharp]
5.7 Internal representation of sensor values
The sensor data values will be represented by the following set of variables:
[csharp] private static bool motionDetected = false;
private static double temperatureC;
private static double lightPercent;
private static object synchObject = new object ();
[/csharp]
Historical values will also be kept so that trends can be analyzed:
[csharp] private static List<Record> perSecond = new List<Record> ();
private static List<Record> perMinute = new List<Record> ();
private static List<Record> perHour = new List<Record> ();
private static List<Record> perDay = new List<Record> ();
private static List<Record> perMonth = new List<Record> ();
[/csharp]
5.8 Persisting data
Persisting data is simple. This is done using an object database. This object
database analyzes the class definition of objects to persist and dynamically
creates the database schema to accommodate the objects you want to store. The
object database is defined in the Clayster.Library.Data library. You first need a
reference to the object database, which is as follows:
[csharp]internal static ObjectDatabase db;[/csharp]
Then, you need to provide information on how to connect to the underlying
database. This can be done in the .config file of the application or the code itself.
Specify a SQLite database and provide the necessary parameters in the code
during the startup:
[csharp] DB.BackupConnectionString = “Data Source=sensor.db;Version=3;”;
DB.BackupProviderName = “Clayster.Library.Data.Providers.”
+ “SQLiteServer.SQLiteServerProvider”;
[/csharp]
Finally, you will get a proxy object for the object database. This object can be
used to store, update, delete, and search for objects in your database:
[csharp] db = DB.GetDatabaseProxy (“TheSensor”);
[/csharp]

9
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5

After doing this, the sensor won’t lose data if Raspberry Pi is restarted.
5.9 External representation of sensor values
To facilitate the interchange of sensor data between devices, you’ll need an
interoperable sensor data format based on XML, provided in
the Clayster.Library.IoT library. Here, the sensor data consists of a collection of
nodes that report data ordered according to the timestamp.
For each timestamp, a collection of fields is reported. There are different types of
fields available: numerical, string, date and time, timespan, Boolean, and
enumeration-valued fields. Each field has a field name, field value of the
corresponding type, an optional readout type, a field status, Quality of Service
value, and localization information.
The Clayster.Library.IoT.SensorData namespace helps you export sensor data
information by providing an abstract interface called ISensorDataExport. The
same logic can later be used to export to different sensor data formats. The library
also provides a class named ReadoutRequest that provides information about
what type of data is desired. You can use this to tailor the data export to the desires
of the requestor.
5.10 Exporting sensor data
The export starts by calling the Start() method on the sensor data export module
and ends with a call to the End() method. Between these two, a sequence
of StartNode() and EndNode() calls are made, one for each node to export.
To simplify the export, you can call another function to output data from an array
of Record objects that contain the data. Use the same method to export the
momentary values by creating a temporary Record object that would contain
them:
[csharp] private static void ExportSensorData (ISensorDataExport Output,
ReadoutRequest Request)
{
Output.Start ();
lock (synchObject)
{
Output.StartNode (“Sensor”);
Export (Output, new Record[] {
new Record (DateTime.Now, temperatureC, lightPercent, motionDetected)
},ReadoutType.MomentaryValues, Request);
Export (Output, perSecond, ReadoutType.HistoricalValuesSecond, Request);
Export (Output, perMinute, ReadoutType.HistoricalValuesMinute, Request);
Export (Output, perHour, ReadoutType.HistoricalValuesHour, Request);
Export (Output, perDay, ReadoutType.HistoricalValuesDay, Request);

10
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5

Export (Output, perMonth, ReadoutType.HistoricalValuesMonth, Request);


Output.EndNode ();
}
Output.End ();
}
[/csharp]
Note that you need to check whether the corresponding readout type is desired by
the client before you export data of this type.
The Export method exports an enumeration of Record objects. It first checks
whether the corresponding readout type is desired by the client before exporting
data of this type. The method also checks whether the data is within the requested
time interval and that the fields are of interest to the client.
If a data field passes all these tests, it is exported by calling any of the instances
of the overloaded method ExportField(), available on the sensor data export
object. Fields are exported between
the StartTimestamp() and EndTimestamp() method calls, defining the timestamp
that corresponds to the fields being exported:
[csharp] private static void Export(ISensorDataExport Output, IEnumerable
History,
ReadoutType Type,ReadoutRequest Request)
{
if((Request.Types & Type) != 0)
{
foreach(Record Rec in History)
{
if(!Request.ReportTimestamp (Rec.Timestamp))
continue;
Output.StartTimestamp(Rec.Timestamp);
if (Request.ReportField(“Temperature”))
Output.ExportField(“Temperature”,Rec.TemperatureC, 1,”C”, Type);
if(Request.ReportField(“Light”))
Output.ExportField(“Light”,Rec.LightPercent, 1, “%”, Type);
if(Request.ReportField (“Motion”))
Output.ExportField(“Motion”,Rec.Motion, Type);
Output.EndTimestamp();
}
}
}
[/csharp]

11
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840

CP4291 IOT UNIT 5

You can test the method by exporting some sensor data to XML using
the SensorDataXmlExport class. It implements the ISensorDataExport interface.
The result would look something like this if you export only momentary and
historic day values:
[xml] <?xml version=”1.0″?>
<fields xmlns=”urn:xmpp:iot:sensordata”>
<node nodeId=”Sensor”>
<timestamp value=”2014-07-25T12:29:32Z”>
<numeric value=”19.2″ unit=”C” automaticReadout=”true” momentary=”true”
name=”Temperature”/>
<numeric value=”48.5″ unit=”%” automaticReadout=”true” momentary=”true”
name=”Light”/>
<boolean value=”true” automaticReadout=”true” momentary=”true”
name=”Motion”/>
</timestamp>
<timestamp value=”2014-07-25T04:00:00Z”>
<numeric value=”20.6″ unit=”C” automaticReadout=”true”
name=”Temperature” historicalDay=”true”/>
<numeric value=”13.0″ unit=”%” automaticReadout=”true” name=”Light”
historicalDay=”true”/>
<boolean value=”true” automaticReadout=”true” name=”Motion”
historicalDay=”true”/>
</timestamp>

</node>
</fields>
[/xml]

12
Downloaded by S PRABAKARAN ([email protected])

You might also like