CP4291 IOT UNIT 5
CP4291 IOT UNIT 5
UNIT 5
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
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.
1
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
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
• No moving parts
• No noise
• Status lights
• Expansion capabilities
2
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
• Write lots of PHP, JAVA script, CSS and Python Programs for the Web
Application
• USB keyboard
3
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
• USB mouse
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
• Reduces size
• Increases performance
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
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
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
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.
The development of a Raspberry Pi sensor project is broken down into six steps.
Here’s a simple overview:
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.
6
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
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
8
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
9
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
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
11
Downloaded by S PRABAKARAN ([email protected])
lOMoARcPSD|19383840
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])