A Secured IoT Framework for Wireless Sensor

0 downloads 0 Views 3MB Size Report
secured IoT framework with multiple wireless sensor nodes is proposed that sends ..... In a device-to-cloud communication model, the IoT device connects directly to ... stack that can give any microcontroller access to your Wi-Fi network. ... meaning, you can simply hook this up to your Arduino device and get about as much ...
A Secured IoT Framework for Wireless Sensor Network

UNIVERSITY OF ENGINEERING & MANAGEMENT, JAIPUR

A Secured IoT Framework for Wireless Sensor Network Submitted in the partial fulfillment of the degree of BACHELOR OF TECHNOLOGY In ELECTRONICS & COMMUNICATION ENGINEERING BY SHOPAN DEY UNIVERSITY ROLL NUMBER: 22014002002001

UNDER THE GUIDANCE OF PROF. SANDIP DAS ELECTRONICS & COMMUNICATION ENGINEERING

UNIVERSITY OF ENGINEERING & MANAGEMENT, JAIPUR

Approval Certificate This is to certify that the project report entitled “A Secured IoT Framework for Wireless Sensor Network” submitted by Shopan Dey (University Roll Number: 22014002002001), in partial fulfillment of the requirements of the degree of Bachelor of Technology in Electronics and Communication Engineering from University of Engineering and Management, Jaipur was carried out in a systematic and procedural manner to the best of our knowledge. It is a bonafide work of the candidate and was carried out under our supervision and guidance during the academic session of 2013-2017.

_______________________

Prof. Sandip Das Project Guide, Assistant Professor (ECE) UEM, JAIPUR

___________________

______________________

Prof. Sandip Das

Prof. Aniruddha Mukherjee

HOD (ECE)

Dean

UEM, JAIPUR

UEM, JAIPUR

i

ACKNOWLEDGEMENT The endless thanks goes to Lord Almighty for all the blessings he has showered onto me, which has enabled me to write this last note in my research work. During the period of my research, as in the rest of my life, I have been blessed by Almighty with some extraordinary people who have spun a web of support around us. Words can never be enough in expressing how grateful I am to those incredible people in my life who made this thesis possible. I would like an attempt to thank them for making my time during my research in the Institute a period I will treasure. I am deeply indebted to my research supervisor, Professor Sandip Das for presenting me such an interesting thesis topic. Each meeting with him added invaluable aspects to the implementation and broadened my perspective. He has guided me with his invaluable suggestions, lightened up the way in my darkest times and encouraged me a lot in the academic life. Shopan Dey

ii

ABSTRACT

The term "Internet of Things" (IoT) defines a trending technology where an ecosystem of connected physical objects are accessible through the internet. The IoT is an emerging topic of technical significance and socio-economic relevance which encapsulates everyday utility objects that are combined with Internet connectivity along with data analytic capabilities that promises to transform our lives in a better way. While IoT does not necessarily refer to any particular communication technology, the wireless communication technologies, especially WSNs that are comprised of sensor nodes that can detect physical phenomena and they find use in different areas such as medical, agricultural, meteorological, etc. In this project, a secured IoT framework with multiple wireless sensor nodes is proposed that sends data to the web cloud server and allows users to access those data via a mobile application. The data transfer between each layer is end to end encrypted. This framework has been used for home automated system apart from meteorological and agricultural purposes. These applications have successfully verified and results are observed.

iii

Table of Contents Approval Certificate……………………………………………………………………………i ACKNOWLEDGEMENT……………………………………………………………………...ii ABSTRACT…………………………………………………………………………………….iii Table of Contents……………………………………………………………………………….1 List of Figures…………………………………………………………………………………...4 1. Introduction……………………………………………………………………………..6 1.1

Internet of Things (IoT)…………………………………………………………6

1.2

Internet of Things Communications Models…………………………………7

1.3

Wireless Sensor Network (WSN)………………………………………………9

1.4

Objective & Methodology……………………………………………………..10

1.5

The Framework: Characteristics……………………………………………...11

2. Device Components…………………………………………………………………...12 2.1

Arduino Nano………………………………………………………………….12

2.2

ESP 8266 Wi-Fi Module………………………………………………………..13

2.3

4 Channel Relay Module………………………………………………………14

2.4

Temperature Sensor……………………………………………………………15

2.5

Light Intensity Sensor………………………………………………………….16

2.6

Ultrasonic Distance Sensor……………………………………………………17

2.7

Relative Humidity Sensor……………………………………………………..18

2.8

Soil Moisture Sensor…………………………………………………………...19

2.9

Other Components……………………………………………………………..20

1

3. Framework Description………………………………………………………………21 3.1

3.2

3.3

3.4

Network Architecture…………………………………………………………21 3.1.1

The OSI Layer………………………………………………………………21

3.1.2

HTTP Protocol……………………………………………………………...23

3.1.3

GCM (Google Cloud Messaging)………………………………………...24

Server Side………………………………………………………………………26 3.2.1

Introduction to AWS………………………………………………………26

3.2.2

Server Programming………………………………………………………26

3.2.3

Database…………………………………………………………………….27

Client Side………………………………………………………………………28 3.3.1

Objective of Implementing Android UI…………………………………28

3.3.2

AES Encryption…………………………………………………………….29

Device Node…………………………………………………………………….30 3.4.1

Node Description…………………………………………………………..30

3.4.2

Binary XOR Encryption……………………………………………………31

4. System Implementation………………………………………………………………32 4.1

Introduction to Arduino IDE………………………………………………….32

4.2

Connecting Arduino to ESP8266 Wi-Fi Module…………………………….32

4.3

AT Command Firmware………………………………………………………33

4.4

Data Acquisition………………………………………………………………..34

4.5

Data Upload to Server…………………………………………………………36

4.6

Logging into Server……………………………………………………………38 4.6.1

Instance Page…………………………………………………………….....38

4.6.2

Login Page………………………………………………………………….39

4.6.3

Registration Page…………………………………………………………..40

4.6.4

Node Management Window……………………………………………...41

4.6.5

Admin Page………………………………………………………………...42 2

4.7

Workflow of GCM……………………………………………………………..43

4.8

Secure Data Transmission to Client………………………………………….44

4.9

The Android Application……………………………………………………..46

5. Results…………………………………………………………………………………..50 6. Conclusion……………………………………………………………………………...53 Appendix……………………………………………………………………………….54 Bibliography…………………………………………………………………………...69

3

List of Figures Fig. 1: IoT Technology Stack…………………………………………………….....................6 Fig. 2: WSN Topology………………………………………………………………………...9 Fig. 3: Block diagram of proposed framework……………………………………………11 Fig. 4: Arduino Nano Board………………………………………………………………...12 Fig. 5: ESP 8266 Wi-Fi Module……………………………………………………………...13 Fig. 6: 4 -Channel Relay Module……………………………………………………………14 Fig. 7: Temperature Sensor………………………………………………………………….15 Fig. 8: Light Intensity Sensor……………………………………………………..................16 Fig. 9: Ultrasonic Distance Sensor………………………………………………………….17 Fig. 10: Relative Humidity Sensor…………………………………………………………...18 Fig. 11: Soil Moisture Sensor…………………………………………………........................19 Fig. 12: Running Instance……………………………………………………………………..38 Fig. 13: Login Page…………………………………………………………………………….39 Fig. 14: Registration Page……………………………………………………………………..40 Fig. 15: Node Management Window………………………………………………………..41 Fig. 16: Administrator Page…………………………………………………………………..42 Fig. 17: GCM Workflow………………………………………………………………………43 Fig. 18: Flow Chart for Secured Data Transmission between Server and Client……….45 Fig. 19: Login for the Android Application…………………………………………………46 Fig. 20: User Page displaying the Sensor Nodes……………………………………………47 Fig. 21: Application Page for Node 1………………………………………………………..48 Fig. 22: Application Page for Node 2………………………………………………………..49 4

Fig. 23: Server-Side Output Window for Node 1………………..........................................51 Fig. 24: Server-Side Output Window for Node 2………………..........................................51 Fig. 25: Application-Side Output Window for Node 1……………………………………52 Fig. 26: Application-Side Output Window for Node 2…………………………………….52 Fig. 27: Home Automation Node……………………………………………………………54 Fig. 28: Meteorological Node………………………………………………………………...55 Fig. 29: Data Packets’ Transmission from Device Node to Cloud Server………………..68

5

1. Introduction

1.1 Internet Of Things (IoT) The Internet of Things is an emerging topic of technical, social, and economic significance. Consumer products, durable goods, cars and trucks, industrial and utility components, sensors, and other everyday objects are being combined with Internet connectivity and powerful data analytic capabilities that promise to transform the way we work, live, and play. The Internet of Things (IoT) is a framework in which all things have a representation and a presence in the Internet. More specifically, the Internet of Things aims at offering new applications and services bridging the physical and virtual worlds, in which Machine-to-Machine (M2M) communications represents the baseline communication that enables the interactions between Things and applications in the cloud.

Fig. 1: IoT Technology Stack

6

Significance of IoT The IoT promotes a heightened level of awareness about our world, and a platform from which to monitor the reactions to the changing conditions that said awareness exposes us to. And, like the advent of the Internet itself, the IoT enables myriad applications ranging from the micro to the macro, and from the trivial to the critical.

1.2 Internet of Things Communications Models: Device-to-Device Communications: The device-to-device communication model represents two or more devices that directly connect and communicate between one another, rather than through an intermediary application server. These devices communicate over many types of networks, including IP networks or the Internet. Often, however these devices use protocols like Bluetooth, Z-Wave, or ZigBee to establish direct device-to-device communications. Device-to-Cloud Communictions: In a device-to-cloud communication model, the IoT device connects directly to an Internet cloud service like an application service provider to exchange data and control message traffic frequently taking advantage of existing communications mechanisms like traditional wired Ethernet or Wi-Fi connections to establish a connection between the device and the IP network.

7

Device-to-Gateway Model: In the device-to-gateway model, or more typically, the device-to-application-layer gateway (ALG) model, the IoT device connects through an ALG service as a conduit to reach a cloud service. In simpler terms, this means that there is application software operating on a local gateway device, which acts as an intermediary between the device and the cloud service and provides security and other functionality such as data or protocol translation.

Back-End Data-Sharing Model: The back-end data-sharing model refers to a communication architecture that enables users to export and analyze smart object data from a cloud service in combination with data from other sources. This architecture supports “the [user’s] desire for granting access to the uploaded sensor data to third parties”. This approach is an extension of the single device-to-cloud communication model, which can lead to data silos where “IoT devices upload data only to a single application service provider’’. A back-end sharing architecture allows the data collected from single IoT device data streams to be aggregated and analyzed .

8

1.3 Wireless Sensor Network (WSN) A wireless sensor network (WSN) is a network formed by large number of sensor nodes where each node is equipped with a sensor to detect physical phenomena such as light, heat, pressure, etc. WSNs are regarded as a revolutionary information gathering method to build the information and communication system which will greatly improve the reliability and efficiency of infrastructure systems. Compared with the wired solution, WSNs feature easier deployment and better flexibility of devices. With the rapid technological development of sensors, WSNs will become the key technology for IoT.

Fig. 2: WSN Topology

9

1.4 Objective & Methodology

In this project, a secured IoT framework with multiple wireless sensor nodes is proposed that sends data to the web cloud server and allows users to access those data via a mobile application. The data transfer between each layer is end to end encrypted. The Framework can be used universally and is fully customizable. This framework has been used as a home automated system apart from meteorological and agricultural purposes. These applications have successfully verified and results are observed. This framework has provision for further modifications for higher efficiency and can also be implemented in several other fields such as for medical, topological and other scientific fields.

10

1.5 The Framework: Characteristics



The description includes three parts to it: The device side, the server side and the client (user) side.



Three sensor nodes are created: Meteorological sensor node, Home automation node and Agricultural node



A server is created at Amazon Web Services where the sensor data values are stored.



An android application has been developed to access those values.

Fig. 3: Block diagram of proposed framework.

11

2. Device Components The hardware components used in the three sensor nodes are as follows:

2.1 Arduino Nano

The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega328 (Arduino Nano 3.x). It has more or less the same functionality of the Arduino Duemilanove, but in a different package. The boards use single or double-row pins or female headers that facilitate connections for programming and incorporation into other circuits. Arduino microcontrollers are pre-programmed with a boot loader that simplifies uploading of programs to the on-chip flash memory.

Fig. 4: Arduino Nano Board

12

2.2 Esp8266 Wi-Fi Module

The Esp8266 Wi-Fi Module is a self-contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your Wi-Fi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino device and get about as much Wi-Fi ability as a Wi-Fi Shield offers.

Fig. 5: ESP 8266 Wi-Fi Module

13

2.3 4 channel relay module

The 4-Channel Relay Driver Module makes it simple and convenient to drive loads such as 12V relays from simple 5V digital outputs of an Arduino compatible board or other microcontroller. It can be used to control channels independently, so simply leave any unused channels disconnected. This relay module combines the processing power of the Arduino to devices that use higher current and voltage. It does so by providing four relays that are rated for 7A at either 28VDC or 10A at 125VAC.

Fig. 6: 4 -Channel Relay Module

14

2.4 Temperature Sensor

LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can be measured more accurately than with a thermistor. It also possess low self-heating and does not cause more than 0.1 oC temperature rise in still air. The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01V/ oC.

Fig. 7: Temperature Sensor

15

2.5 Light Intensity Sensor

CDS Cells are photo resistive light sensors. When no light is present their impedance is extremely high, and conversely very low when no light is present. In contrast to phototransistors, these cells generally don't seem to have as large a range of values between the two extremes of light and dark. A Light Sensor generates an output signal indicating the intensity of light by measuring the radiant energy that exists in a very narrow range of frequencies basically called “light”, and which ranges in frequency from “Infra-red” to “Visible” up to “Ultraviolet” light spectrum.

Fig. 8: Light Intensity Sensor

16

2.6 Ultrasonic distance sensor

Ultrasonic sensor provides an easy method of distance measurement. This sensor is perfect for any number of applications that require you to perform measurements between moving or stationary objects. The Ultrasonic Sensor sends out a high-frequency sound pulse and then times how long it takes for the echo of the sound to reflect back. The sensor has 2 openings on its front. One opening transmits ultrasonic waves, (like a tiny speaker), the other receives them, (like a tiny microphone). The speed of sound is approximately 341 meters (1100 feet) per second in air. The ultrasonic sensor uses this information along with the time difference between sending and receiving the sound pulse to determine the distance to an object.

Fig. 9: Ultrasonic Distance Sensor

17

2.7 Relative humidity sensor

This I2C digital humidity sensor is an accurate and intelligent alternative to the much simpler humidity and temperature sensors. It has a typical accuracy of ±2% with an operating range that's optimized from 5% to 95% RH. Operation outside this range is still possible - just the accuracy might drop a bit. Humidity sensors relying on this principle consists of a hygroscopic dielectric material sandwiched between a pair of electrodes forming a small capacitor. By definition, relative humidity is a function of both the ambient temperature and water vapour pressure. Therefore there is a relationship between relative humidity, the amount of moisture present in the sensor, and sensor capacitance. This relationship governs the operation of a capacitive humidity instrument.

Fig. 10: Relative Humidity Sensor

18

2.8 Soil Moisture sensor

This moisture sensor can read the amount of moisture present in the soil surrounding it. It's a low tech sensor, but ideal for monitoring an urban garden or a cultivation land. This sensor uses the two probes to pass current through the soil, and then it reads that resistance to get the moisture level. More water makes the soil conduct electricity more easily (less resistance), while dry soil conducts electricity poorly (more resistance).

Fig. 11: Soil Moisture Sensor

19

2.9 Other components

The list of other components required to design a node includes:



Resistors.



LEDs.



Voltage Regulator



Capacitors.



USB cable.



Connecting wires.



DC power supply.

20

3. Framework Description

3.1 Network Architecture

3.1.1 THE OSI LAYER The Open System Interconnection (OSI) model defines a networking framework to implement protocols in seven layers which is absolutely conceptual in nature. Layers 1-4 are considered the lower layers, and mostly concern themselves with moving data around. Layers 57, the upper layers, contain application-level data. Each layer takes care of a very specific job, and then passes the data onto the next layer. 1) Physical Layer: OSI Model, Layer 1 conveys the bit stream - electrical impulse, light or radio signal — through the network at the electrical and mechanical level. 2) Data link Layer: In this layer data packets are encoded and decoded into bits. It furnishes transmission protocol knowledge and management and handles errors in the physical layer, flow control and frame synchronization. The data link layer is divided into two sub layers: The Media Access Control (MAC) layer and the Logical Link Control (LLC) layer. The MAC sub layer controls how a computer on the network gains access to the data.

21

3) Network Layer: It provides switching and routing technologies, creating logical paths, known as virtual circuits, for transmitting data from node to node. Routing and forwarding are functions of this layer, as well as addressing. 4) Transport Layer: This layer provides transparent transfer of data between end systems, or hosts, and is responsible for end-to-end error recovery and flow control. It ensures complete data transfer. 5) Session Layer: This layer establishes, manages and terminates connections between applications. The session layer sets up, coordinates, and terminates conversations, exchanges, and dialogues between the applications at each end. 6) Presentation Layer: This layer provides independence from differences in data representation (e.g., encryption) by translating from application to network format, and vice versa. The presentation layer works to transform data into the form that the application layer can accept. This layer formats and encrypts data to be sent across a network, providing freedom from compatibility problems. It is sometimes called the syntax layer. 7) Application Layer: This layer supports application and end-user processes. Communication partners are identified, quality of service is identified, user authentication and privacy are considered, and any constraints on data syntax are identified.

22

Transmission Control Protocol/Internet Protocol (TCP/IP) is the standard communication protocol suite used for client/server communication over a network. TCP is the transport protocol that manages the exchange of data between hosts. IP is a network layer protocol for packet-switched networks.

3.1.2 HTTP Protocol: The Hypertext Transfer Protocol (HTTP) defines the application protocol for distributed, collaborative, and hypermedia information systems. An HTTP session is a sequence of network request-response transactions. An HTTP client initiates a request by establishing a Transmission Control Protocol (TCP) connection to a particular port on a server An HTTP server listening on that port waits for a client's request message. Upon receiving the request, the server sends back a status line, and a message of its own. The body of this message is typically the requested resource, although an error message or other information may also be returned. The client and server communicate by sending plain-text (ASCII) messages. The client sends requests to the server and the server sends responses. HTTP defines methods to indicate the desired action to be performed on the identified resource. What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server. Often, the resource corresponds to a file or the output of an executable residing on the server.

23



The GET method requests a representation of the specified resource. Requests using GET only retrieves data and has no other effect.



The POST method requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data Posted might be, for example, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database. Simply stated, a POST request is used to send data to the server, for example, customer information, file upload, etc. using HTML forms.



The PUT method requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already existing resource, it is modified; if the URI does not point to an existing resource, then the server can create the resource with that URI.



The TRACE method echoes the received request so that a client can see what (if any) changes or additions have been made by intermediate servers. It basically performs a message loop-back test along the path to the target resource.

3.1.3 GCM (Google Cloud Messaging) The Google Cloud Messaging (GCM) plays the most important role in terms of interaction of the Application with the server. Google Cloud messaging (commonly referred to as GCM) is a mobile notification service developed by Google that enables third-party application developers to send notification data or information from developer-run servers to 24

applications that target the Google Android Operating System, as well as applications or extensions developed for the Google Chrome internet browser. Google Cloud Messaging functions using server APIs and SDKs, both maintained by Google. The GCM has the ability to send push notifications, deep-linking commands, and application data. Upon allowing the application permission to receive and display notifications, the client application sends a registration API request to the Google Cloud Messaging interface to begin the registration process. The GCM Service receives and acknowledges the request and responds by giving the device a GCM Registration ID, a unique identifier that the developer later uses to send a notification to the individual device. The identifier is stored onto the device, and is typically sent to the developer's application server to be stored. The GCM Registration ID is a randomly-generated identifier that does not contain any personal or device information that could allow a developer to discover the personal identity of the user. When the developer wishes to send a notification event to a device, the process begins with an API POST request being sent to the GCM Authentication Service. The POST request includes the GCM Registration ID, priority, optional values and links, and the information that is to be displayed on the device upon its arrival. Upon successful verification of the GCM Registration ID and other credentials, an authentication token is returned. Both identifiers are then sent to the GCM Service to be enquired and delivered to the device.

25

3.2 Server Side

3.2.1 Introduction to AWS A server has been created using Amazon Web Services. Amazon Web Services (AWS) is presently the most popular cloud computing platform. AWS sports dozens of cloud services from compute to storage to networking and so on. AWS also offers a robust IoT solution that can scale to ingest hundreds of millions of sensor data points per seconds. First of all, Amazon Elastic Compute Cloud (Amazon EC2) is initiated by launching a Linux instance. An instance is a virtual server in the AWS cloud. With Amazon EC2, the operating system have been configured for the applications that would run on the instance. When the instance is launched, it needs to be secured by specifying a key pair and security group.

3.2.2 Server Programming The server is programmed and designed using PHP and HTML programming. Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications. With Cascading Style Sheets (CSS) and JavaScript it forms a triad of cornerstone technologies for the World Wide Web. PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

26

There are two ways to use HTML on a PHP page. The first way is to put the HTML outside of the PHP tags. One can even put it in the middle if he closes and reopens the. The second way to use HTML with PHP is by using PRINT or ECHO. By using this method one can include the HTML inside of the PHP tags. This is a nice quick method if you only have a line or so to do. Using one or both of these methods you can easily embed HTML code in the PHP pages, to give them a nicer more formatted look, and make them more user-friendly.

3.2.3 Database The database of the server is created using MySQL. MySQL is an opensource relational database management system (RDBMS). The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single forprofit firm, the Swedish company MySQL AB, now owned by Oracle Corporation. There are three tables in the database namely users, node info and node data. The user table stores the user information of every registered i.e. login details such as user id and password. The node info table stores information on each node such as the node number, the device id and serial key for that node, the input parameters such as temperature, humidity etc. and the output parameters such as area1, area2, etc. The node data table stores the incoming sensor data values with their log time corresponding to the respective input parameters.

27

3.3 Client Side

3.3.1 Objective of Implementing Android UI Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies. Android offers a unified approach to application development for mobile devices which means developers need only develop for Android, and their applications should be able to run on different devices powered by Android. The source code for Android is available under free and open source software licenses. The “Internet of Things” (IoT) is simply a collection of everyday objects that have internet connectivity and sensors that can gather, transmit and receive information. Consequently, the need for incorporating an Android Application Interface in a typical IoT Framework arises due to the obvious need of enabling total automation. Android applications don’t do much without external input, they need to talk to “things”. With more and more devices becoming internet connected, the apps you write will communicate with them. One might think we can get away with this because the devices talk to the server and they just obey the server. However, security and performance being high value requirements for mobile, potentially having our Android apps talk to IoT devices on local networks or pairing with them one on one are highly crucial features and must be scrutinized with utmost attention. This where the security concerns comes into picture.

28

Encryption involves the process of transforming data so that it is unreadable by anyone who does not have a decryption key. The Secure Shell (SSH) and Socket Layer (SSL) protocols are usually used in encryption processes. The SSL drives the secure part of “https://” sites used in e-commerce sites. All data in SSL transactions is encrypted between the client (browser) and the server (web server) before the data is transferred between the two.

3.3.2 AES Encryption In this case, the data transfer between the server and client is end to end encrypted using AES encryption with key length of 256 bits. AES is a data encryption technique founded by the U.S NIST in 2001. AES is an iterative cipher. It is based on ‘substitution–permutation network’. AES treats the 128 bits of a plaintext block as 16 bytes. The number of rounds of iteration in AES is variable and depends on the length of the key. The algorithm for a single step encryption is: Step 1: The 16 bytes of the matrix are XORed with 128 bits of round key. Step 2: Left shift each 4 row of the matrix. Step 3: Transform four bytes from each column using a special mathematical function. Step 4: If this is the last round, output is cipher text, otherwise go to step 1. For decryption, the steps are performed in reverse way to get the plaintext.

29

3.4 Device Node

3.4.1 Node Description In this project three nodes have been designed each consisting of varying sensors which are primarily intended to benefit the meteorological sector, domestic sector (home automation) and agricultural sector. The detailed analysis of the three nodes are given below: 

NODE 1: This node is designed to serve the meteorological sector as it contains temperature and air humidity sensors which records the corresponding values and sends them to the server for future retrieval as and when required.



NODE 2: This node is targeted to serve the domestic sector in order to provide home automation. The sensors present in this node are the light intensity and ultrasonic distance sensor. The light intensity sensor checks for the light intensity values and notifies the user. Similarly, the ultrasonic distance sensor checks for the water level values and controls the water pump accordingly.

30



NODE 3: This node consisting of soil moisture and relative humidity sensor is dedicated to serve the agricultural sector where the recorded values denotes the prevailing air humidity and soil moisture conditions which helps to manipulate the agricultural factors consequently.

3.4.2 Binary XOR Encryption The data interchanged between the nodes and server is end-to-end-encrypted using binary XOR technique. The algorithm of the same is provided below: XOR operation flips the bits i.e. returns 0 if neither or both bits are 1. Step 1: The plaintext is represented in its ASCII, Hexadecimal and Binary forms. Step 2: A key s chosen for example, any alphabet. Step 3: The key is used to XOR the first character of the plaintext to ciphertext. Binary XOR encryption is symmetric i.e. the same key is used to decrypt the cipher text to plaintext.

31

4. System Implementation 4.1 Introduction to Arduino IDE Every action that the node performs has to be programmed in Arduino IDE. The Arduino Software (IDE) is an open-source software makes it easy to write code and upload it to the board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing and other open-source software.

4.2 Connecting Arduino to Esp8266 Wi-Fi Module ESP-8266 is an easy and low-cost alternative to the expensive Arduino Wi-Fi shields. All ESP-8266 modules are programmable. One can use the default factory firmware or can write their own firmware and upload it to the module. The default firmware provides a serial communication that you can use to send AT commands to your module, just like in the old telephone/modem days. These commands provide everything you need to connect to a Wi-Fi router and send/receive data. In the Arduino IDE, there is no need to choose a board, as nothing is uploaded to the ESP8266. Just choose the right port in the Tools menu and go to Tools → Serial Monitor. Then simply set the baud rate to 115200 and the line endings to Both NL & CR. The terminals for this ESP models are: •

VCC shall be connected to the 3.3V power supply.

32



GPIO0 and GPIO2 are general purpose digital ports. GPIO0 also controls the module mode (programming or normal operation). In this case (normal operation), it shall be connected to 3.3V (high).



CH_PD: Chip enable. Keep it on high (3.3V) for normal operation.



RST: Reset. Is kept on high (3.3V) for normal operation. Put it on 0V to reset the chip.



Tx: Goes to Arduino Rx.



Rx: Goes to Arduino Tx. (But needs a voltage adjusting).



GND is ground.

4.3 AT command firmware In order to test the ESP, two serial ports are required: •

One dedicated serial port, connected between Arduino and ESP, where Arduino will send AT commands to ESP.



A second serial port, connected between Arduino and the computer, where the AT commands are written.

The user can test your ESP connection with a simple code. The code simply relays data from both Arduino serial. It gets the AT commands that are typed on the computer and sends them directly to ESP. It also gets ESP return data and sends to the computer. Once it is set, type in the box AT and it should return OK. This device communicates via AT comments. 33



To check firmware type AT+GMR.



To set the module to accept connections type AT+CWMODE=3.



To search Wi-Fi networks around type AT+CWLAP. It will display Wi-Fi networks nearby.



To

connect

to

a

network

type

AT+CWJAP="Wi-Fi

SSID","password". •

To find the IP address type AT+CIFSR.

After every command it returns you OK.

4.4 Data Acquisition The sensors collect data from the surroundings and convert the data to digital signal by a process known as data acquisition. Data acquisition is the process of sampling signals that measure real world physical conditions and converting the resulting samples into digital numeric values that can be manipulated by a computer. Data acquisition systems, abbreviated by the acronyms DAS or DAQ, typically convert analog waveforms into digital values for processing. The components of data acquisition systems include: •

Sensors, to convert physical parameters to electrical signals.



Signal conditioning circuitry, to convert sensor signals into a form that can be converted to digital values.

34



Analog-to-digital converters, to convert conditioned sensor signals to digital values.

Data acquisition applications are usually controlled by software programs developed

using

various

general

purpose

programming

languages

such

as Assembly, BASIC, C, C++ etc. Data acquisition begins with the physical phenomenon or physical property to be measured. Examples of this include temperature, light intensity, humidity, fluid flow, and force. Regardless of the type of physical property to be measured, the physical state that is to be measured must first be transformed into a unified form that can be sampled by a data acquisition system. The task of performing such transformations falls on devices called sensors. A data acquisition system is a collection of software and hardware that measures or controls physical characteristics of something in the real world. A sensor, which is a type of transducer, is a device that converts a physical property into a corresponding electrical signal. An acquisition system to measure different properties depends on the sensors that are suited to detect those properties. The signal may need to be filtered or amplified in most cases. For transmission purposes, single ended analog signals, which are more susceptible to noise can be converted to differential signals. Once digitized to uniform packets, the signal can be encoded to reduce and correct transmission errors.

35

4.5 Data upload to server Once the code is burnt into the Arduino, connection is established between the server and the node indicated by glowing of a led. Now, to upload the data, a PHP file is created that contains the sensor data parameters such as temperature, humidity etc. that the sensor will record. This file can be easily uploaded to the server using FileZilla software. FileZilla is a powerful tool and popular FTP client that facilitates uploading of files over the internet. The sensor data from the surroundings is uploaded successively to the server as uniformly digitized packets within fixed intervals. In this case the POST method in Http has been used to transfer the data. As mentioned earlier, each data is end-to-end encrypted with Binary XOR encryption.

Algorithm for data transfer from node to server: Step 1: Start. Step 2: Connect to the internet. Step 3: If connected go to step 4. Else go to step 7 Step 4: Generate control UI (User Interface) for monitor. Step 5: Check for user input

36

Step 6: If yes, then  Get registration ID from GCM server,  Perform Binary Encryption and  Send user command to device for next input Else go to step 3 Step 7: Check for message from IoT device, Perform decryption. Step 8: Show notification. Step 9: Refresh IoT device go to step 4.

37

4.6 Logging into server

4.6.1 Instance Page As mentioned earlier, a server has been created at Amazon Web Services. So, after logging into the console, it redirects to the instance page. The instance page displays the current instance status, the instance ID, instance type, public IP, public DNS and the private DNS of our server. Since the server is active, the status is displayed as ‘running’. The

public

DNS

(IPv4)

of

the

instance

is:

ec2-52-43-125-183.us-west-

2.compute.amazonaws.com. When this address is initiated, it redirects to a login page.

Fig. 12: Running instance

38

4.6.2 Login Page The figure below displays the Login Page of the server. The credentials required to log into the server are user name and password for a registered user. For new users, a “Registration” link has been provided below.

Fig. 13: Login page

39

4.6.3 Registration Page The required fields for new registration are Name, Password and email id of the user. After registration, the user can go back clicking on the ‘back’ button and the fill in the log in details in the login page. Once the credentials are authenticated, it redirects to the Home Page. The registration page is named ‘IOT WSN’ and a diagram of it is provided below.

Fig. 14: Registration Page

40

4.6.4 Node Management Window In the Home Page one can add a new node, delete an existing node or modify a node inside the node management window. In order to create a new node, the user has to specify the Node identification number, Node name, an optional description about the node, a node key through which it can be uniquely identified by the server or the mobile app, device identification number, names of the sensors used and the output devices. Users can also view information on existing sensor nodes such as node name and id, device id, serial key and input output parameters. To view the sensor values of a particular sensor node, the user needs to click on the node id. The login and home pages are created using HTML and PHP programming.

Fig. 15: Node Management Window

41

4.6.5 Admin Page The admin page shows the list of all the registered users on the server along with their email id, password and GCM id. Clicking on the hyperlink ID of the user gives the information on the nodes present for that particular user. The diagram below shows that the gcm id has been provided for that user who has logged into the server.

Fig. 16: Administrator Page

42

4.7 Workflow of GCM The workflow of GCM between the server and client include the following steps: 

Sends SENDER ID to GCM for Registration.



After successful registration, GCM returns REG_ID.



Device sends REG_ID to server.



Stores REG_ID in database.



Retrieve REG_ID from database and sends it to GCM along with the encrypted message.



After getting request from server, GCM sends it to the device.

Fig. 17: GCM Workflow

43

4.8 Secure Data Transmission to Client The algorithm implemented for secure transmission of data to client side are as follows: Step 1: Start Step 2: Initiate Static IP address. Step 3: Connect to the internet. Step 4: If connected, Read all sensor values, go to step 5 Else goto step 2 Step 5: Perform AES encryption. Step 6: Send data to cloud server. Step 7: If sensor value greater than threshold, Send notification to Android device, do the required action Else Go to step 8 Step 8: Check for remote command from the user. Step 9: If message received, Perform AES decryption, go to step 10 Else goto step 4 44

Step 10: Execute user command, go to step 4.

Fig. 18: Flow Chart for Secured Data Transmission between Server and Client

45

4.9 The Android Application For the client side an android application has been developed named ‘IoT’ using Android Studio in order to control the electronic home appliances and to access the sensor node data values. The aforementioned picture depicts the login page of the application. The credentials required to login are username and password.

Fig. 19: Login Page for the Android Application

46

The next picture displays the details produced on screen when a user logs in to the application. It clearly shows that there is provision for three sensor nodes namely ‘Home test’, ‘Rajasthan’ and ‘My Home’.

Fig. 20: User Page displaying the Sensor Nodes

47

The next picture displays all the readings recorded in the server for the node ‘Home Test’ which controls home automation parameters such as Main power, garden lights, water level in water pump and fan. Tapping on any record displays the recorded values explicitly along with the time of observation.

Fig. 21: Application page for Node 1

48

The next picture displays all the readings recorded in the server for the node ‘West Bengal’ which controls temperature and humidity parameters of Area1, Area2, Area3 and Area4. Tapping on any record displays the recorded values explicitly along with the time of observation.

Fig. 22: Application page for Node 2

49

5. Results This section focuses on the observations after successful implementation of the sensor nodes. Fig 7 shows there are three nodes. The parameters for each node are node id, node name, device id and node key. The node ‘Home Test’ is used to log sensor data of Rajasthan and control power line of four areas i.e.area1, area2, area3, and area4. The recorded data appear below. The user has the provision to choose the area for monitoring the sensor data. Fig 8 shows the display window where the user can see the log time along with temperature and humidity values. The node ‘My Home’ serves the purpose of home automation to control the electrical appliances of a home. The user can control the main power supply, the garden lights, water level in the water pump, and the door lock from the values he receives from the logged sensor values. LED sensor has been used to control the garden lights while the ultrasonic distance sensor acts as a water level checker. Fig 9 shows the display window where the user can see the log time along with temperature in centigrade, height of water reserve in centimeters and light intensity in percentage. Similarly, the third node is designed to be used for agricultural purposes as it measures the soil moisture and air humidity of a land and accordingly displays the output.

50

Fig. 23: Server-Side Output Window for Node 1

Fig. 24: Server-Side Output Window for Node 2

51

Fig. 25: Application-Side Output Window for Node 1

Fig. 26: Application-Side Output Window for Node 2

52

6. Conclusion

In this project, a secure IoT framework have been proposed for wireless sensor network comprising of a variety of sensors that were successfully implemented in various fields and has provision for further modifications for higher efficiency. The framework can also be implemented in several other fields such as for medical, topological and other scientific fields. The home automation system is economical and efficient in our daily lives and is likely to get more popularity in the upcoming years. In near future, with some minor improvements in the framework there is a high scope for economic technological advancement in the field of Wireless Sensor Networking.

53

Appendix Node 1: The following is designed to implement home automation. It is in working condition. We can see that the Arduino and Esp8266 Wi-Fi module is active. The sending of data to the server is indicated by the green LED. The four LED at the left hand side of the image is for the four parameters used in the home automation circuit namely main power, water level, garden lights and fan. The glowing LEDs denotes the parameters that are active and the others show the status for rest of the parameters.

Fig. 27: Home Automation Node 54

Node 2: The following is designed to implement services for meteorological sector. It is in working condition. We can see that the Arduino and Esp8266 Wi-Fi module is active. The sending of data to the server is indicated by the green LED. The four LEDs at the left hand side of the image is for the four parameters used in the circuit namely area1, area2, area3 and area4. The glowing LEDs denotes the parameters that are active and the others show the status for rest of the parameters.

Fig 28: Meteorological Node

55

Source Code for Connecting Arduino with Cloud Server

Node.ino #include String ssid

= "wifi";

String password = "12345678"; String device_id = "2222abcd56"; String key

= "hello";

int LM35_in

= A0;

int LDR_in

= A1;

int rly1

= 2;

int rly2

= 3;

int rly3

= 4;

int rly4

= 5;

int rx

= 6;

int tx

= 7;

int green

= 11; 56

int red

= 12;

String cmd

= "";

String relay1

= "";

String relay2

= "";

String relay3

= "";

String relay4

= "";

String relay1_set = ""; String relay2_set = ""; String relay3_set = ""; String relay4_set = ""; SoftwareSerial esp(rx, tx); void setup() { uint32_t baud = 9600; Serial.begin(baud); esp.begin(baud); 57

Serial.println("IoT node for WSN"); Serial.println("Version: 0.3"); Serial.print("baud rate: "); Serial.println(baud); Serial.print("Device ID: "); Serial.println(device_id); esp_reset(); connectWifi(); analogReference(INTERNAL); pinMode (green, OUTPUT); pinMode (red, OUTPUT); pinMode (rly1, OUTPUT); pinMode (rly2, OUTPUT); pinMode (rly3, OUTPUT); pinMode (rly4, OUTPUT); } 58

void red_blink() { digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level) delay(2000);

// wait for a second

digitalWrite(red, LOW); // turn the LED off by making the voltage LOW } void update_relay() { if (relay1_set != relay1){ relay1_set = relay1; if (relay1_set == "on"){ digitalWrite(rly1, HIGH); Serial.println("Relay 1 on"); } else { digitalWrite(rly1, LOW); Serial.println("Relay 1 off"); } 59

} if (relay2_set != relay2){ relay2_set = relay2; if (relay2_set == "on"){ digitalWrite(rly2, HIGH); Serial.println("Relay 2 on"); } else { digitalWrite(rly2, LOW); Serial.println("Relay 2 off"); } } if (relay3_set != relay3){ relay3_set = relay3; if (relay3_set == "on"){ digitalWrite(rly3, HIGH); 60

Serial.println("Relay 3 on"); } else { digitalWrite(rly3, LOW); Serial.println("Relay 3 off"); } } if (relay4_set != relay4){ relay4_set = relay4; if (relay4_set == "on"){ digitalWrite(rly4, HIGH); Serial.println("Relay 4 on"); } else { digitalWrite(rly4, LOW); Serial.println("Relay 4 off"); 61

} } } //reset the esp8266 module void esp_reset() { esp.println("AT+RST"); delay(1000); if(esp.find("OK") ) Serial.println("Module Reset"); } void connectWifi() { String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\""; esp.println(cmd); delay(4000); if(esp.find("OK")) { Serial.println("Connected with wifi"); 62

digitalWrite(green, HIGH); } else { digitalWrite(red, LOW); Serial.println("Cannot connect to wifi"); connectWifi(); } } //connect the esp8266 module with server void esp_upload() { float input1 = read_temp(); String input2 = "50"; float input3 = read_light(); String http = " HTTP/1.0";

63

String url = "/nodedataupload.php/?deviceid="+device_id+"&key="+key+"&input1="+input1+"&input2="+i nput2+"&input3="+input3; String data = "GET " + url + http + "\r\n\r\n"; //String data = "GET / HTTP/1.0\r\n\r\n"; esp.println("AT+CIPSTART=\"TCP\",\"52.43.125.183\",80"); delay(1000); if(esp.find("CONNECT") ){ //CONNECT Serial.println("Connected with server"); esp.print("AT+CIPSEND="); esp.println(data.length()); delay(1000); Serial.println("-------------------------------"); } red_blink(); // close the connection

64

//esp.println("AT+CIPCLOSE"); } else{ Serial.println("Packet sent failed"); } } } else { Serial.println("Connection failed with server"); } } float read_temp(){ int reading = analogRead(LM35_in); float tempC = reading / 9.31; return tempC; float read_light() 65

{ int light_var = analogRead(LDR_in)/10; float light = light_var / 1.02; return light; } void loop() { //esp_reset(); esp_upload(); //esp_disconnect(); //esp_send("GET / HTTP/1.0\r\n\r\n"); //GET / HTTP/1.0 //GET /nodedataupload.php/?deviceid=1234abcd56&key=thsa1&input1=30&input2=80&input3=0,0,0 HTTP/1.0 /* while (esp.available() > 0) 66

{ char a = esp.read(); Serial.print(a); } while(Serial.available() > 0) { char a = Serial.read(); //Serial.write(a); esp.write(a); } */ delay(5000); }

67

Output: The program is executed in Arduino IDE. We can observe the output in the Serial Monitor of Arduino IDE.

Fig. 29: Data Packets’ Transmission from Device Node to Cloud Server

68

Bibliography Following are the references which we have used for the purpose of the project completion: [1] K. Laubhan, K. Talaat, S. Riehl, M. S. Aman, A. Abdelgawad and K. Yelamarthi, "A low-power IoT framework: From sensors to the cloud," 2016 IEEE International Conference on Electro Information Technology (EIT), Grand Forks, ND, 2016, pp. 0648-0652. [2] S. Noh, K. Kim and Y. Ji, “Design of a room monitoring system for wireless sensor networks,”

International

Journal

on

Distributed

Sensor

networks,

vol.2013(2013),no. 189840, pp 1-7, July 2013. [3] J. Zhang, G. Song, H. Wang and T. Meng, "Design of a Wireless Sensor Network Based Monitoring System for Home Automation," 2011 International Conference on Future Computer Sciences and Application, Hong Kong, 2011, pp. 57-60. [4] H. Xianzhe, "Room temperature and humidity monitoring and energy-saving system," 2011 6th International Conference on Computer Science & Education (ICCSE), Singapore, 2011, pp. 537-540. [5] K. S. Sahoo, B. Sahoo and A. Panda, "A secured SDN framework for IoT," 2015 International Conference on Man and Machine Interfacing (MAMI), Bhubaneswar, 2015, pp. 1-4.

69

[6] H. Tang, J. Shi and K. Lei, "A smart low-consumption IoT framework for location tracking and its real application," 2016 6th International Conference on Electronics Information and Emergency Communication (ICEIEC), Beijing, 2016, pp. 306309. [7] S. K. Datta and C. Bonnet, "Connect and Control Things: Integrating Lightweight IoT Framework into a Mobile Application," 2015 9th International Conference on Next Generation Mobile Applications, Services and Technologies, Cambridge, 2015, pp. 66-71. [8] S. G. Hong, N. S. Kim and T. Heo, "A smartphone connected software updating framework for IoT devices," 2015 International Symposium on Consumer Electronics (ISCE), Madrid, 2015, pp. 1-2. [9] E. Carrillo, V. Benitez, C. Mendoza and J. Pacheco, "IoT framework for smart buildings with cloud computing," 2015 IEEE First International Smart Cities Conference (ISC2), Guadalajara, 2015, pp. 1-6. [10]

L. M. Feeney and M. Nilsson, "Investigating the energy consumption of a

wireless network interface in an ad hoc networking environment," Proceedings IEEE INFOCOM 2001. Conference on Computer Communications. Twentieth Annual Joint Conference of the IEEE Computer and Communications Society (Cat. No.01CH37213), Anchorage, AK, 2001, pp. 1548-1557 vol.3.

70

Suggest Documents