5.1 zigbee communication - inflibnetshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter -...

35
104 CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES REAL TIME APPLICATIONS 5.1 ZigBee communication ZigBee modules are embedded solutions providing wireless end-point connectivity to devices. These modules use the IEEE 802.15.4 networking protocol for fast point-to- multipoint or peer-to-peer networking. The ZigBee/ZigBee-PRO OEM RF Modules interface to a host device through a logic-level asynchronous serial port. Through its serial port, the module can communicate with any logic and voltage compatible UART; or through a level translator to any serial device (For example: Through a Max-Stream proprietary RS-232 or USB interface board). Devices that have a UART interface can connect directly to the pins of the RF module as shown in Figure 5.1 Figure 5.1 ZigBee communication After establishing a serial connection between the RF module and a PC, select the Terminal‟ is selected and the following command lines are given: Micro controller D1 data CTS D RTS If Zigbee Module No Zigbee Module Yes D1 data CTS D RTS Micro Controller

Upload: others

Post on 30-Aug-2019

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

104

CHAPTER 5

INTEGRATING IOT AND CLOUD SERVICES – REAL TIME

APPLICATIONS

5.1 ZigBee communication

ZigBee modules are embedded solutions providing wireless end-point connectivity to

devices. These modules use the IEEE 802.15.4 networking protocol for fast point-to-

multipoint or peer-to-peer networking. The ZigBee/ZigBee-PRO OEM RF Modules interface

to a host device through a logic-level asynchronous serial port. Through its serial port, the

module can communicate with any logic and voltage compatible UART; or through a level

translator to any serial device (For example: Through a Max-Stream proprietary RS-232 or

USB interface board). Devices that have a UART interface can connect directly to the pins of

the RF module as shown in Figure 5.1

Figure 5.1 ZigBee communication

After establishing a serial connection between the RF module and a PC, select the

„Terminal‟ is selected and the following command lines are given:

Micro

controller

D1 data

in) CTS

D

0 RTS

SIf tags supports Strength write

Zigbee

Module

No

Zigbee

Module

Yes

D1 data

in) CTS

D

0 RTS

Micro

Controller

Page 2: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

105

Send AT Command

a. +++ : Enter into Command Mode

b. ATID = NETWORKID (network Id) : The ATID command is used to set and read the PAN (Personal

Area Network) ID of the RF module.

c. ATMY = MYID (Id of this module) : The ATMY command is used to set and read the 16-bit source

address of the RF module.

d. ATDL = DSTID (Id of destination module) : The ATDL command is used to set and read the lower 32 bits of

the RF module's 64-bit destination address.

e. ATBD = BAUD9600 (9600 baud rate) : The ATBD command is used to set and read the serial interface

data rate used between the RF module and host.

f. ATCN (Exit Command Mode) : The ATCN command is used to explicitly exit the RF module

from AT Command Mode.

Data enters the module UART through the DI pin (pin 3) as an asynchronous serial signal.

The signal should idle high when no data is being transmitted. Each data byte consists of a

start bit (low), 8 data bits (least significant bit first) and a stop bit (high). Figure 5.2 illustrates

the serial bit pattern of data passing through the module.

Figure 5.2 ZigBee serial bit patterncommunication

The module UART performs tasks, such as timing and parity checking, that are needed for

data communications. Serial communications depend on the two UARTs to be configured

with compatible settings (baud rate, parity, start bits, stop bits, data bits).

UART Signal

Signal

Voltage

LSB

Start Bit

(low)

Start Bit

(high)

Time

Page 3: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

106

5.1.1 Experimental Setup

The ability of ZigBee modules to transfer data files between two STM32 boards is

demonstrated in this research. ZigBee modules are initialized by sending the above mentioned

AT Commands. Data is sent from one controller to ZigBee through USART peripheral.

Similarly, the data is received from ZigBee to another controller through USART peripheral.

5.1.2 Communication between ZigBee modules

Initially code is built & compiled in keil and download the hex file to both boards. Then

HyperTerminal is started with configuration 9600 baud rate, 8 bits data, one stop bit, no parity

for slave and master and reset the board. Receive mode is selected in one terminal and wait for

the data to receive. Send mode is selected in other terminal and transmit the start of file, data

in buffer and the end of file through ZigBee module. In receive terminal, if the start of file is

received, it will create the new file and open it for writing the data received and close the file.

Upon completion the data is written in the file specified (Refer Figure 5.3 and 5.4).

Figure 5.3 ZigBee serial bit patterncommunication Hardware setup

Page 4: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

107

5.1.3 Output on the HyperTerminal

SUCCESS

NETWORK ID SET

SOURCE MODULE ID SET

DESTINATION MODULE ID SET

BAUD RATE SET

-- XBEE MODEM INITIALISED

-- SD card detected OK

3800 MB total drive space.

3799 MB available.

****MENU****

1. Send File

2. Receive File

Enter ur choice.......

****SEND MODE****

Open file readme.txt....

680 bytes have been read from the file

File has been transmitted successfully

****MENU****

1. Send File

2. Receive File

Enter ur choice.......

****RECEIVE MODE****

File Receive Success.. 680 bytes received

****START OF FILE****

Writing to file...

File has been received successfully

Figure 5.4 ZigBee Output on the hyper terminal

5.2 IoT implementation

Node 1 is assigned (pyro sensor) to sense the environment and it sends the output to the

processor via I2C or SPI communication. Then the processor sends action required signal to

the Driver circuit and Driver circuit gives command to the Device. All the devices including

the control unit is connected to one another through Wi-Fi and communicates on the Internet

Protocol version 6 (IPv6).

Page 5: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

108

Two nodes 1 and 2 are used with the features shown in the following Table 5.1. The

Raspberry Pi has a Broadcam BCM2835 System on Chip (SoC) which includes an

ARM1176JZF-S 700 MHz processor, VideoCore IV GPU and was originally shipped with

256 megabytes of RAM, later upgraded to 512 MB. It does not include a built-in hard disk or

solid-state drive, but uses an SD card for booting and persistent storage.

Table 5.1 Features of nodes (Raspberry Pi)

Nodes (Raspberry Pi)

Features

Node 1 and Node 2

IP address

Battery powered

LAN enabled

Wi-Fi enabled ARM II processor

HDMI interface USB ports

5.2.1 Communication among Nodes

Here Node 1 has a mail id (domain) node1@ gmail.com and Node 2 has a mail id node2@

yahoo.in. Both the nodes are connected with the internet via one switch. Node 1 writes the

control action (to be performed at Node 2) to the mail. After receiving the mail, Node 2 reads

the mail and the required action is performed. The above operation is explained in Figure 5.5.

Here the switch is ON and OFF based on the requirements of the environment. When the

switch is ON, Node 1 writes in the mail as Device needs to be ON. After receiving the mail,

Node 2 reads the mail and the device is switched ON. Here SNMP Protocol is used to send the

information for node 1 and POP 3 Protocol is used to receive the information for node 2 from

node 1. Similarly when the switch is OFF, Node2 writes in the mail as device needs to be

OFF. After reading this mail from the mail box the Device is switched OFF.This is explained

in Table 5.2.

Page 6: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

109

Figure 5.5 Communication among two nodes

Table 5.2 Switching process of node 1 and node 2

Node 1(SNMP)

Mail id of node 1

Node 2(POP 3)

Mail id of node 2

Switch [email protected] [email protected] Device

ON

OFF

Device needs

to be ON

Device needsto be

OFF

Device

is switched ON

Device

isswitched OFF

ON

OFF

Internet

Node 2 Node 1

Node 1 has a mail id Node 2 has a mail

[email protected] [email protected]

Page 7: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

110

5.2.2 Connectivity

Communication between node and device is carried out by processor and Driver circuit is

shown in Figure 5.6. Initially connectivity of the network is checked whether it is to be LAN

or Wi-Fi enabled. After finding the type of network, network protocol is assisgned for Node 1

and Node 2 as clearly indicated in Figure 5.7.

Figure 5.6 Communication between node and Device

Figure 5.7 Protocol selection

SNMP protocol is for Node 1 for writing mail and POP 3 protocol for Node 2 for reading

mail.

Node

Environment sensing

Processor

Output

Driver circuit Device

Select the protocol

Node 1 Node 2

SNMP POP 3

OP 3

P 3

3

3

Page 8: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

111

5.2.3 Experimental Setup

The Procedure for network initialization of Wi-Fi and LAN in Raspberry Pi are tabulated in

Table 5.3 and Table 5.4.

Table 5.3 Wi-Fi initialization of raspberry Pi

Wi-Fi network initialization in raspberry Pi

Auto lo

iface lo inet loopback

auto wlan0

allow-hotplugh wlan0

iface wlan0 inetdhcp

wpa-ssid “mgruniv” #wifinetwort name

wpa-ssid “samurai123” #wifi password

Table 5.4 LAN initialization of raspberry Pi

LAN Network initialization in raspberry Pi

Iface lo inet loopback

Iface eth0 inetdhcp

allow-hotplug wlan0

iface wlan0 inet manual

wpa-roam /etc/wpa_suppplicant/wpa_supplicant.conf

iface default inetdhcp

The hardware implementation of sensor side interface in IoT and device side interfaced in

IoT as shown in the Figure 5.8 and 5.9. Ground and voltage (3.3V) connections are given as

per the corresponding figures.

Page 9: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

112

Figure 5.8 Sensor side interface in IoT

Figure 5.9 Device side interfaced in IOT

Switch R1

220

R2=10k

1

2

3

Where

1-pin 1 (3.3V from raspberry pi)

2-pin 2 (ground from raspberry pi)

3-pin 3 (to GPIO 24 of raspberry pi)

Where

1-pin 1 (from raspberry pi)

2-pin 2 (raspberry pi ground)

3-pin 3 (GPIO 25 from raspberry pi)

No

3

R1

2

1

Q1

D1

RL2

D2

R2

Page 10: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

113

5.3 Hotspot an overview

Hotspot 2.0 Task group in the Wi-Fi Alliance was formed by Cisco and industry leaders.

The main goal was to form a common set of standards that will improve subscriber‟s hotspot

experience and support business objectives of service provider. The research is now focused to

improve the Wi-Fi user while roaming. Figure 5.10 & 5.11 shows the Hotspot 2.0 and its

Protocol stack respectively. The protocol IEEE 802.11u enables a mobile device to connect

with a Wi-Fi AP to determine the supporting capabilities of the network. The two protocols

i.e.GAS (generic advertisement service) and ANQP (access network query protocol) are used

by 802.11u and these protocols run on top of the protocol 802.11 and enable the Hotspot

2.0.When a user‟s HS2.0 mobile comes within range of a Hotspot 2.0 AP, it will open up a

dialog with that specific AP to find its functions. ANQP packets are used to do this work and

are carried at layer 2 by the GAS service.The mobile device learn the capabilities of an AP

when exchange of ANQP packets automatically.

Figure 5.10 Hotspot

Internet

Wireless

Nodes

Access point Hotspot

Page 11: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

114

Figure 5.11 Hotspot 2.0 Protocol stack

5.3.1 Performance Metrics

In the traffic data, parameters to be discussed are distribution of packet inter-arrival times,

Packet sizes and burst of traffic. A simulation bench is setup to capture the Wi-Fi access

traffic data for some of the applications, and analyze the data in terms of packet size,

throughput vs. time for uplink and downlink.

Burst Duration is the difference of arrival times between the first and last packets in a

specified burst.

Burst Size is the sum of all data packets in a burst. The packet has application data, and

headers of transport, network and MAC levels.

Packets per Burst are the total number of packets in a specified burst.

Burst Inter-arrival Time is the time duration between the arrival time of the last packet of a

burst and arrival time of first packet of the next burst is referred as the burst inter-arrival time.

Figure 5.12 shows schematic diagram of performance metrics.

Authentication

EAP

802.11

Generic advertisement

service (GAS)

802.1X

ANQP

HS 2.0 Credential

Network

Discovery and

selection

Page 12: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

115

Figure 5.12 Schematic diagram of Performance metrics

5.3.2 System Requirements

Standard PC with Windows XP, Pentium III, 256 MB RAM, 2 Network cards (USB or

Ethernet network card), 2 network cables, Wi-Fi access point or router and Working internet

connection are minimum requirement. IP address between hotspot node and internet is

assigned and then Hotspot node and Wi-Fi are connected with IP address.

5.3.3 Experimental Setup

In this research, the system performance of the proposed WLAN hotspot network

infrastructure is measured using OPNET Modeler simulation software. The OPNET™

Riverbed Academic edition software used for creating a simulated network and analyzing its

networking metrics. OPNET is a graphical network simulator. It is generally used for

simulation of both wired and wireless communication networks. In this work, the

infrastructure include:Five mobile nodes, Http Server, 100 BaseT and Access point and its

important attributes are tabulated as in Table 5.5

Burst duration Data packet

Packet inter-arrival time Burst inter-arrival time

Page 13: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

116

Table 5.5 WirelessLan Attributes

Nodes Model Trajectory Address

Mobile node 0 Wlan_wkstn_adv Trajectory_2

Client

address:

Auto assigned

Mobile node 1 Wlan_wkstn_adv Trajectory_1

Mobile node 2 Wlan_wkstn_adv Trajectory_3

Mobile node 3 Wlan_wkstn_adv Trajectory_4

Mobile node 4 Wlan_wkstn_adv Trajectory_5

Access point Wlan_ethernet_slip4_adv_1_upgrade ---- Server

address: Auto

assigned

Http server Ethernet_server ----

In Figure 5.13, the proposed WLAN system model utilizes the infrastructure components.

A Http server has the role authenticating and monitoring the overall network for efficient

service delivery. Application Definitions were used for the creations of applications for traffic

generation on the network. Profile Configuration used for the activity applications and always

used by users through a period of time. After setting up the model, a simulation was carried

out to generate graphical plots.

Figure 5.13 WLAN nodes setup with Server and Access point

Page 14: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

117

5.4 Realtime system implementation

5.4.1 Case (i) Smart parking system

Controller code:

The controller code is the code for controller native service that runs on Raspberry Pi. The

runController function is called every „T‟ seconds and the reading of the ultrasonic sensor is

obtained. If the distance returned by the sensor is less than a threshold, the slot is considered to

be occupied. The current state of the slot is then updated by sending a PUT request to the state

REST service.

Controller Code Algorithm

Main Loop

Module readUltrasonicSensor to read the Ultrasonic Sensor with a Type Boolean

If it returns “1”, set current state “occupied” to cloud server

Else , set current state “empty” to cloud server

Repeat Step 1

readUltrasonicSensor

Set the threshold range

Measures the signal on and off time from ECHO-PIN connected to GPIO on R-Pi

Convert from time to distance

If distance is less than threshold , return “1” to main loop

Else, return “0” to main loop

Page 15: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

118

Cloud Side Programming

Django Framework is used to implement the cloud side services.

The following are the cloud side files:

serializers.py: Serializers allow complex data (such as model instances) to be

converted to native Python data types that can then be easily rendered into JSON,

XML or other content types.

views.py: ViewSets combine the logic for a set of related views in a single class. The

ViewSets for the models (Mode ViewSet and State ViewSet) are included in the views

file.

models.py: A model is the single, definitive source of data about your data. It contains

the essential yields and behaviors of the data stored. Generally, each model maps to a

single database table.

5.4.2 Circuit Diagram

The connection diagram used for smart parking is shown in Figure 5.14.

Figure 5.14 Smart parking system

Page 16: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

119

The ultrasonic sensor senses the distance and is placed in the slots. The connection

between the electronic circuit and the R-Pi is shown in Figure 5.15.

Figure 5.15 Connection diagram of Smart parking system

5.4.3 Raspberry Pi Setup

In this experimental setup, Keyboard and Mouse are connected to USB through Wi-Fi and

Power to Raspberry Pi through USB. Initially connections are checked to make sure Wi-Fi is

available by pinging to the Server IP address and make the connections as shown in the

connection diagram of Figure 5.15. IP address of the server is detected using ifconfig and set

this IP address in the configuration file views.py. Then „python manage.py runserver with the

ipaddress for ex: 192.168.1.2:8000‟ to run the server.

5.5 Case (ii) Weather reporting system

Controller code

Twitter.py file is the code for controller native service that runs on Raspberry Pi. The

Controller service obtains temperature and humidity from DHT22 sensor, pressure and

Page 17: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

120

temperature from BMP085 sensor and light intensity from LDR sensor connected through

analog-to-digital (A/D) converter MCP3008.The controller service obtains the temperature,

humidity, pressure and light readings from the sensors, every 10 seconds. The sensor readings

and the images is then sent as a tweet on Twitter.

Controller Code Algorithm

Read the DHT22 sensor, it returns temperature and humidity

Read the BMP085 sensor, it returns pressure and also temperature

Compute average of temperature values

Read LDR, it returns analog data and Convert analog data to digital

Store temperature. Humidity, pressure and light(digital) in status

Mention the image path of uploading image

Update status and image path in to twitter

Cloud Side Programming

Cloud side setup is done using Twitter App. To send tweets the controller services uses a

Python library for Twitter called tweepy. With tweepy the Twitter REST API is used to send

tweets. Before using the twitter API, a twiiter developer account is setup and then a new

application (with read-write permissions). Upon creating the application, API key, API secret

and access tokens will be obtained. These credentials and token are used in the controller

service. The connections is as shown in Figure 5.16 & 5.17

Page 18: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

121

Figure 5.16 Circuit diagram of Weather Reporting System

Figure 5.17 Connection diagram of Weather Reporting System

5.5.1 Interface twitter with r-pi

In this research work, twitter interfaced with raspberry-pi to get the data from weather

reporting bot and displayed in twitter. The purpose of the weather reporting bot is to collect

data on environmental conditions such as temperature, pressure, humidity and light in an area

using multiple end nodes. The weather information by sending tweets on Twitter. The end

Page 19: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

122

node is comprised of a Raspberry Pi minicomputer, temperature, humidity, and pressure and

light sensors. The system consists of multiple nodes placed in different locations for

monitoring temperature, humidity and pressure in an area. The end nodes are equipped with

various sensors (such as temperature, pressure, humidity and light). The end nodes send the

data to the cloud and the data is stored in a cloud database. The analysis of data is done in the

cloud to aggregate the data and make predictions. A Twitter app is used for visualizing the

data. The centralized controller can send control commands to the end nodes, for example, to

configure the monitoring interval on the end nodes. The devices and components used in this

research work are Raspberry Pi minicomputer, temperature and humidity sensor (DHT22),

pressure and temperature sensor (BMP085) and LDR sensor. An analog-to-digital (A/D)

converter (MCP3008) is used for converting the analog input from LDR to digital.

Controller code

Twitter.py file is the code for controller native service that runs on Raspberry Pi. The

controller service obtains temperature and humidity from DHT22 sensor, pressure and

temperature from BMP085 sensor and light intensity from LDR sensor connected through

analog-to-digital (A/D) converter MCP3008.The controller service obtains the temperature,

humidity, pressure and light readings from the sensors, every 10 seconds. The sensor readings

and the images is then sent as a tweet on Twitter. The workflow of controller is shown in

Figure 5.18.

Page 20: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

123

Figure 5.18 Workflow of controller

5.5.2 Cloud Side Programming

Cloud side setup is done using Twitter App. The controller service uses a Python library

for Twitter to send tweets called as tweepy. Twitter REST API to send tweets usingtweepy.

Before using the twitter API, twitter developer account is needed to set up and then a new

application (with read-write permissions) created. Upon creating the application the API key,

API secret and access tokens for user are generated. These credentials and token are used in

the controller service. The circuit diagram of proposed system is shown in figure 5.19. The

connection diagram is shown in Figure 5.20.

Call Module

(DHT22) function

Read the temperature

and humidity

Calculate average

temperature values

Read the temperature

and pressure

Read the light intensity

value

Analog to digital

conversion

Call Module

(BMP085) function

Call Module

(LDR) function

Store temperature, Humidity, pressure and light in status

Update status and

photo path in twitter

Page 21: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

124

Figure: 5.19 Circuit Diagram

Figure 5.20 Connection diagram

Page 22: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

125

5.5.3 Creating Twitter app

The https://twitter.com and https://apps.twitter.com are used to create twitter account and

Twitter app. Create new App option is used to create new application. The name of the

application and the website address is filled and „create a Twitter Application‟ is used to create

app as apk file (Refer Figure 5.21 and Figure 5.21).

Figure 5.21 Twitter applications Screen shot -1

Figure 5.22 Twitter Applications Screen shot -2

Page 23: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

126

The developed weather Reporting Bot app is shown in Figure 5.23.

Figure: 5.23 Weather Reporting Bot application Screen shot – 1

The created keys and access tokens are shown in Figure 5.24.

Figure 5.24 Keys and access tokens

Page 24: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

127

Consumer Key and Consumer Secret are obtained from application settings. In Twitter.py

Consumer Key used instead of CONSUMER_KEY and Consumer Secret used instead of

CONSUMER_SECRET. This is shown in Figure 5.25.

Figure 5.25 Weather reporting application Screen shot – 2

The „Create my access token‟ option is used to get Access Token and Access Token

Secret. In Twitter.py, Access Token used instead of ACCESS_KEY and Access Token Secret

used instead of ACCESS_SECRET. This is shown in Figure 5.26.

Figure 5.26 Access Token

Page 25: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

128

5.6 Case (iii) Smart irrigation

Controller code

Controller. py file is the code for controller native service that runs on Raspberry Pi. The

runController function is called every 10 second and the reading of the soil Moisture sensor is

obtained. If the level returned by the sensor is greater than a threshold, the valve is opened to

release water. The current state of the valve is then updated by sending a PUT request to the

state REST service.

Controller Code Algorithm

Set the threshold range

Call Module readMoisture to read the soil Moisture Sensor.

It returns Analog data then, convert Analog data to Digital using MCP3008.

Update that “ digital data “ to xively ( Cloud based application)

Repeat step 2.

Cloud Side Programming

Cloud side setup is done using xively Cloud Services. Xively is a Platform as a

Service built for the IoT. This includes directory services, data services, a trust engine

for security, and web-based management application. Xively‟s messaging is built on a publish-

subscribe protocol called MQTT. The API supports REST, Web Sockets, and MQTT.

5.6.1 Circuit Diagram

Figure 5.27 and 5.28 show the circuit and connection diagram for smart irrigation. Here

instead of LED (5v) Solenoid valve (24v) is connected. If Moisture level is greater than

threshold, LED is ON (Solenoid valve is open to realease the water). Else, LED is OFF.

Page 26: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

129

Figure 5.27 Circuit diagram for smart irrigation

5.6.2 Connetion diagram

Figure 5.28 Connection diagram for smart irrigation

Page 27: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

130

5.6.3 Raspberry pi Setup

In this experimental setup, Keyboard and Mouse are connected to USB through Wi-Fi and

Power to Raspberry Pi through USB. Initially connections are checked to make sure Wi-Fi is

available by pinging to the Server IP address and make the connections as shown in the

connection diagram Figure 5.28.

Setup the xively (cloud based application)

Xively account is created through this link https://personal.xively.com/signup.No need

to create xively account for every time. Once xively account is created, this link

https://personal.xively.com is used to login (Figure 5.29). After login screen, add device (if

new device is to be created) (Figure 5.30).The steps for smart irrigations are shown in the

Figures 5.31 to 5.33. Device name (Example: Soil Moisture Sensor), private device and Add

Device are entered. ID & API Keys and controller.py program (Every device as unique feed

ID & API Keys) are added. After receiving authentication required message, username &

password are entered. Executing the program in terminal window, the result updates on xively

has shown.

Running the code on Raspberry Pi

Circuit board is connected as per the connection diagram. The following steps are followed

to run the code on Raspberry Pi.

cd/home/IOT_projects/Smart_Irrigation

Run command “python controller.py

Page 28: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

131

Figure 5.29 Screen shot for smart irrigation – 1

Figure 5.30 Screen shot for smart irrigation - 2

Page 29: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

132

Figure 5.31 Screen shot for smart irrigation - 3

Figure 5.32 Screen shot for smart irrigation - 4

Page 30: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

133

Figure 5.33 Screen shot for smart irrigation - 5

5.7 Case (iv) Air pollution monitoring

5.7.1 Controller code

Controller.py file is the code for controller native service that runs on raspberry pi. The

runcontroller function is called every 10 second and the reading of the co sensor is

obtained. The current state of the value is then updated by sending a put request to the state

rest service.

Controller code algorithm

Call module readco_sensor .

It returns analog data then, convert analog data to digital data using mcp3008.

Updates that “digital data” to the xively (cloud based application).

Repeat step1.

Page 31: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

134

5.7.2 Cloud side programming

Cloud side setup is done using xively cloud services. Xively is a platform as a

service built for the iot. This includes directory services, data services, a trust engine

for security, and web-based management application. Xively‟s messaging is built on

a publish-subscribe protocol called mqtt. The api supports rest, web sockets, and mqtt.

Build the connection as shown in Figure 5.34 & 5.35.

Figure 5.34 Circuit diagram for Air pollution monitoring

Figure 5.35 Connection diagram for Air pollution monitoring

Page 32: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

135

5.7.3 Raspberry pi setup

In this experimental setup, Keyboard and Mouse are connected to USB through Wi-Fi and

Power to Raspberry Pi through USB. Initially connections are checked to make sure Wi-Fi is

available by pinging to the Server IP address and make the connections as shown in the

connection diagram of Figure 5.35.

Setup the xively (cloud based application)

Xively account is created through this link https://personal.xively.com/signup. No need

to create xively account for every time. Once xively account is created, this link

https://personal.xively.com is used to login (Figure 5.36). After login screen, add device (if

new device is to be created) (Figure 5.37).The steps for smart irrigations are shown in the

Figures 5.38 to5.40. Device name (Example Air Pollution Monitoring), private device and

Add Device are entered. ID & API Keys and controller.py program (Every device as unique

feed ID & API Keys) are added. After receiving authentication required message, username &

password are entered. Executing the program in terminal window, the result updates on xively

has shown.

Figure 5.36 Screen shot of Air pollution monitoring - 1

Page 33: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

136

Figure 5.37 Screen shot of Air pollution monitoring - 2

Figure 5.38 Screen shot of Air pollution monitoring - 3

Page 34: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

137

Figure 5.39 Screen shot of Air pollution monitoring - 4

Figure 5.40 Screen shot of Air pollution monitoring - 5

Page 35: 5.1 ZigBee communication - INFLIBNETshodhganga.inflibnet.ac.in/bitstream/10603/107638/9/09_chapter - 5.pdf · CHAPTER 5 INTEGRATING IOT AND CLOUD SERVICES – REAL TIME APPLICATIONS

138

5.8 Chapter Conclusion

Integrating IoT and Cloud services in real time applications are studied and implemented

in diverse fields. Communications between ZigBee modules are analyzed and output on hyper

terminal are showing this transfer of files. Communication among IoT Nodes using mail

concept is discussed in this chapter. Node 1 writes the control action (to be performed at Node

2) to the mail. After receiving the mail, Node 2 reads the mail and the required action is

performed. In this research, the system performance of the proposed WirelessLAN hotspot

network infrastructure is measured using OPNET Modeler simulation software. IoT based

applications like Smart parking, Weather reporting bot, Smart irrigation and Air pollution

control are implemented as realtime applications in this chapter. The devices and components

used in this research work are Raspberry Pi minicomputer, temperature and humidity sensor

(DHT22), pressure and temperature sensor (BMP085) and LDR sensor.