34
University of Peradeniya Department of Computer Engineering CO421: Final Year Project I Affordable Environmental Monitoring And Controlling System For Greenhouses Authors Weeraratne I.L.(E/11/431) Jayathilaka O.M.D.N.I.(E/11/183) Athukorala A.S.P.(E/11/024) Supervisors Dr. Asitha Bandaranayake Dr. Roshan Ragel September 27, 2016

Affordable EMCS for GeenHouses

Embed Size (px)

Citation preview

Page 1: Affordable EMCS for GeenHouses

University of Peradeniya

Department of Computer Engineering

CO421: Final Year Project I

Affordable EnvironmentalMonitoring And Controlling System

For Greenhouses

AuthorsWeeraratne I.L.(E/11/431)Jayathilaka O.M.D.N.I.(E/11/183)Athukorala A.S.P.(E/11/024)

SupervisorsDr. Asitha Bandaranayake

Dr. Roshan Ragel

September 27, 2016

Page 2: Affordable EMCS for GeenHouses

Abstract

Greenhouses are used to increase harvest by controlling key factors which will affect theplanet growth. Real-time monitoring of the greenhouse environment with sensors cansignificantly affect the plant growth by taking necessary control decisions which resultsin an improvement of yields and economic performance. In this project, we propose anenvironmental monitoring and controlling system that can collect the information relatedto greenhouse environment using various sensors and monitor the greenhouse remotelyvia a web interface and a mobile application. Using a low cost wireless sensor network,environment data on greenhouse are sent to the centralized server. It will store all thisdata and show the latest environment details of the greenhouse using the web interface.The web interface will provide real-time graphical display of data using charts and gauges.Also, using this information farmers can take the decisions necessary to increase harvestand improve quality of crops.

Page 3: Affordable EMCS for GeenHouses

Summary of CO421 and CO425

CO421

In CO421 the basic implementation of the project was done intention of sensor dataacquisition and controlling the greenhouse environment using sensor nodes and centralnode. So the implementation of the sensor network was done only using one internetgateway (Central Node). So every node had to directly connect to the Central node inorder to send sensor data and receive control data. The system was made to be plug andplay. Any pre-configured sensor node can connect to the access point in the central nodeand send data to centralized via it.So the basic implementation of the project was completed in the end of the semester.

Introduction page 1-2Backgroud page 5Implimentation page 6-8Conclusion page 27

CO425

In CO421 implementation there was a big issue in the implementation since all the sensornodes had to connect to the central node directly. So the implementation had to bechanged completely in order to achieve the goal of creating a sensor network using anAd-Hoc network. So the implementation details of the sensor network using clusteredmesh architecture is included in this report. Since that is the final goal achievement andall the things which are done in the CO421 in creating a sensor node details are alreadyincluded in this report.

Introduction page 4Implimentation page 9-22Challenges 25-26Conclusion + future works page 27

iii

Page 4: Affordable EMCS for GeenHouses

Contents

1 Introduction 11.1 Greenhouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Wireless sensor network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Sensor Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 The project and its objectives . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Background 52.1 Related work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Implementation 63.1 Wireless Sensor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3.1.1 Wireless sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . 63.1.2 Low-cost sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . 73.1.3 NodeMCU ESP8266 12-E NodeMCU development board . . . . . 8

3.2 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2.1 DHT 11 Humidity and Temperature Sensor . . . . . . . . . . . . . 93.2.2 Soil Moisture Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.3 Central Node of Sensor Network . . . . . . . . . . . . . . . . . . . . . . . 103.3.1 Development of Wireless Network . . . . . . . . . . . . . . . . . . 113.3.2 Sensor Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.4 Wireless Sensor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.4.1 Low-cost Low-power Sensor Node . . . . . . . . . . . . . . . . . . . 123.4.2 Relay Nodes in Sensor Network . . . . . . . . . . . . . . . . . . . . 123.4.3 Central Node of Sensor Network . . . . . . . . . . . . . . . . . . . 123.4.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.4.5 Gather Data from Sensor Nodes . . . . . . . . . . . . . . . . . . . 143.4.6 Sending data to the Centralized Server . . . . . . . . . . . . . . . . 15

3.5 Development of Monitoring System . . . . . . . . . . . . . . . . . . . . . . 163.5.1 Centralized Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.5.2 REST API for monitoring system . . . . . . . . . . . . . . . . . . 173.5.3 REST API to receive data from Sensor Network . . . . . . . . . . 183.5.4 REST API to control environmental factors in greenhouse . . . . . 193.5.5 Interface for the RESTful API . . . . . . . . . . . . . . . . . . . . 193.5.6 Monitoring System - Front End . . . . . . . . . . . . . . . . . . . . 203.5.7 Network details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.5.8 Latest values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

iv

Page 5: Affordable EMCS for GeenHouses

Contents

3.5.9 Charts of Each Sensor Types . . . . . . . . . . . . . . . . . . . . . 213.5.10 Controlling Feature in Monitoring System . . . . . . . . . . . . . . 22

3.6 Overall architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4 Challenges 244.1 Finding Appropriate Hardware . . . . . . . . . . . . . . . . . . . . . . . . 244.2 Implementing Wireless Access Point inside Raspberry Pi board . . . . . . 244.3 MQTT Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.4 Lack of hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5 Conclusion 265.1 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Bibliography 27

v

Page 6: Affordable EMCS for GeenHouses

List of Figures

1.1 The typical architecture of the sensor node . . . . . . . . . . . . . . . . . 2

3.1 The sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2 A ESP8266 ESP 7 Wifi module . . . . . . . . . . . . . . . . . . . . . . . . 73.3 NodeMCU DEVKIT 1.0 with Sensor and Power Bank . . . . . . . . . . . 83.4 DHT11 Humidity and Temperature Sensor . . . . . . . . . . . . . . . . . 93.5 Soil Moisture sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.6 Raspberry Pi 3 Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.7 The typical architecture of the sensor node . . . . . . . . . . . . . . . . . 113.8 Sensor Network Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.9 Central Node Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 133.10 Central Node Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 143.11 Running Mosquitto server with connected client(Sensor Node) 192.186.42.16 153.12 Incoming Message from Node 2 . . . . . . . . . . . . . . . . . . . . . . . . 153.13 System Architecture diagram . . . . . . . . . . . . . . . . . . . . . . . . . 163.14 Representation of the Restful API using Swagger . . . . . . . . . . . . . . 193.15 gauges using kendo UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.16 line chart using kendo UI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.17 Controlling System Architecture diagram . . . . . . . . . . . . . . . . . . 223.18 5V 1-Channel Relay interface board . . . . . . . . . . . . . . . . . . . . . 233.19 Relay interface connection with accumulator . . . . . . . . . . . . . . . . . 23

vi

Page 7: Affordable EMCS for GeenHouses

List of Tables

3.1 Pin configuration to program ESP8266-ESP07 module using a USB-FDTImodule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

vii

Page 8: Affordable EMCS for GeenHouses

1 Introduction

1.1 Greenhouse

Greenhouse is a farming structure where the plants which need a controlled climateconditions are cultivated. Due to the limited and decreasing available space for agriculture,Greenhouse has been the best alternative solution to get a better crop production. Thetarget of a greenhouse to provide a better controllable environment to have better harvest,protect crop and crop seeding.

Greenhouses are used for growing flowers, vegetables, fruits and transplants. They areoften used in agricultural industry in commercial production. Greenhouses are mostlyimportant in countries where the environment is not good for cultivation. For an example,greenhouses are increasingly used in high-latitude countries.

Greenhouses can control the environment of the plants. Most of the greenhouses have aroof made of transparent material like glass to have a maximum solar radiation inside ofthe greenhouse. Also the greenhouse atmosphere is closed and therefore the heat temper-ature can be differentiated from the external atmosphere. In most of the greenhouses keyenvironmental factors which are needed to be controlled are temperature, irrigation, levelof light and shade, fertilizer application, and humidity. Greenhouses are used to increasethe harvest in an area where those previously explained key factors are not available asit needs.

A greenhouse environment is a complex and dynamic environment which is needed to becontrolled carefully otherwise it will affect the crop cultivation. To have a better cropproduction the climate conditions are needed to be adjusted by continuously monitoringthose environmental factors which are explained before. For an example a plant maydie because of too much water or because of not enough water. Poor light intensity andhigh humidity often result in poor fruit set and quality. More accurate control can saveresources, effort taken and have a better crop production.

1

Page 9: Affordable EMCS for GeenHouses

1 Introduction

1.2 Wireless sensor network

A wireless sensor network is a group of nodes which are capable of recording sensory dataat diverse locations and transmitting this data to a central node. Those nodes which arecalled sensor nodes are small, lightweight and portable. Those detection stations havevarious sensors attached to them and they have capability of processing sensory datagathered using those sensors and also communicating with each other sensor nodes orthe central node.

Commonly monitored parameters are temperature, humidity, pressure, oxygen percentageand Carbon dioxide percentage. The sensor network communicates with a central nodewhich is connected to all sensor nodes. The Central node is monitoring the activities ofeach sensors and act as a access to the sensor network. The central node is connected toa the distant server which is used to monitor data and control the system.[1]

1.3 Sensor Node

Figure 1.1: The typical architecture of the sensor node

A sensor node has capability of gathering, processing and transmitting a sensory datagathered using a transceiver. Therefore it is equipped with a microcomputer to processthe data, transceiver to communicate, power source to act as an independent device and

2

Page 10: Affordable EMCS for GeenHouses

1 Introduction

one or more sensors. The sensor generates electrical signals based on sensed physicaleffects and phenomena. The microcomputer processes sensor output. The transceiverdata to the central node frequently. The power for each sensor node is derived from abattery. Wireless sensor nodes are very small devices with limited battery source. Thesesensor nodes are popular in commercial use because they are scalable and easy to handle.The key factor of the sensor node is the power consumption. Sensor nodes are placedinside the greenhouses. Therefore, the external power supply is not applicable. The bestsolution is power from the battery. To give power from a battery, those equipment shouldconsume low power. Therefore, the design should be a low power sensor node. There areseveral low power sensor nodes in the market. But the cost for the sensor node is notsuitable for a farmer in the agricultural industry in Sri Lanka where is still a developingcountry.

3

Page 11: Affordable EMCS for GeenHouses

1 Introduction

1.4 The project and its objectives

In this project, we propose a affordable environmental monitoring and controlling systemwhere the environment can be monitored and controlled externally without using mucheffort. Even though there are built solutions in the market they are very expensive andnot affordable to agriculture sectors in countries like Sri Lanka. Therefore need to have aaffordable and low cost greenhouse monitoring and controlling systems.Developing countries like Sri Lanka, most of the farmers in agriculture sector cannotafford high cost sensor networks. Some of the sensors will connect to a central companyserver and to get that data a service charge hash to be paid to the company. Also asdescribed before the key factor of a sensor node is power consumption. Therefore one ofthe objective of this project to build a affordable low cost low power sensor node whichcan be released as a product easily.As the development of the agriculture sector new generation of farmers like to usenew technology in their fields consecutively monitoring and controlling the greenhousesremotely and not be in the fields all the time. Therefore a wireless sensor network isproposed in this project which will be affordable and low cost. By this wireless sensornetwork users can monitor key factors which are explained before remotely. With thewireless sensor network a centralized server is proposed as an objective to gather andstore those data for analyzing and showing in a monitoring system.Being able to control the key factors like temperature, levels of light and shade, irrigation,fertilizer application, and atmospheric humidity will be an power factor to the developmentof agriculture industry. If the greenhouse is monitored remotely it will be good to controlit in remotely . Therefore as the second phase of the project a controlling system alongwith the monitoring system is also proposed. This controlling system will automaticallycontrol the key factors to improve the crop production. This will attract the peoplewho are getting away from the agricultural sector with traditional methods with thetechnological revolution. Therefore this monitoring and controlling system will try toautomate the old methods.The rest of the report is organized as follows. In chapter 2 we discuss about the relatedwork. In chapter 3 we discuss the development of wireless sensor network and in chapter 4we discuss about the development of the Monitoring system. Finally in chapter 5 resultsand discussions are stated.

4

Page 12: Affordable EMCS for GeenHouses

2 Background

2.1 Related work

Many researches have been done in Greenhouse Technology since it is the next chapter ofcost and space effective farming. Since greenhouses give more harvest than other methodworld is moving towards greenhouse. The latest trend is to automate greenhouses usingsensor networks. Some same kind of projects have been done by

• School of Electronic Engineering, Huaihai Institute of Technology, Lianyungang,Chinahttp://ojs.academypublisher.com/index.php/jnw/article/viewFile/jnw0705838844/

4638

• Center for Telecommunication Research & Innovation (CeTRI), Faculty of Electronic& Computer Engineering, Universiti Teknikal Malaysia Melaka (UTeM), Hang TuahJaya, 76100, Melaka, Malaysiahttp://www.ijesi.org/papers/Vol%202(7)/Version-5/B027506012.pdf

• Department of Electronics and Communication Engineering SVS College of Engi-neering, Coimbatore, India http://www.ijana.in/papers/V5I5-5.pdf

But all those are focusing on creating hardware with very low level. Power consumptionis one of their main concern. But no one has tried with the existing technologies likeNodeMCU, MQTT protocol and creating better sensor network using them at lowercost.

5

Page 13: Affordable EMCS for GeenHouses

3 Implementation

3.1 Wireless Sensor Network

3.1.1 Wireless sensor node

Sensor nodes are the roots of the sensor network. Since the system to be the affordablecost of the system should be reduced. Because sensor nodes are the major equipment usedto build the system, reducing the cost of a sensor node will substantially reduce the costof the system. The sensor nodes available in market cost around 150 $for each. Thereforeto make an affordable system, creating a low-cost sensor node is being a primary targetof the project. The image of a sensor node showing in figure 3.1

Figure 3.1: The sensor node

6

Page 14: Affordable EMCS for GeenHouses

3 Implementation

3.1.2 Low-cost sensor node

For the implementation of low-cost sensor nodes, The ESP 8266 ESP 7 module was used.The ESP8266 WiFi Module is a self-contained SoC with integrated TCP/IP protocolstack that can give any microcontroller access to WiFi network. The ESP8266 is capableof either hosting an application or offloading all Wi-Fi networking functions from anotherapplication processor.Also the ESP8266 module is low cost and commonly used nowadays.The image of the Wifi module showing in Figure 3.2

Figure 3.2: A ESP8266 ESP 7 Wifi module

Programming the WiFi module can be done using an USB-FDTI programming modulewith following pin configurations.

ESP8266-ESP07 FDTI programmer

Tx Rx

Rx Tx

GND GND

GPIO15 GND

GPIO0 GND

VCC 3.3V

CH PD (EN) 3.3V

Table 3.1: Pin configuration to program ESP8266-ESP07 module using a USB-FDTImodule

7

Page 15: Affordable EMCS for GeenHouses

3 Implementation

3.1.3 NodeMCU ESP8266 12-E NodeMCU development board

ESP8266 ESP-12E NodeMCU development board was used for further implementation.NodeMCU is an open source IoT platform.NodeMCU is based on the eLua project andit uses the Lua scripting language.The firmware runs on the ESP8266 Wi-Fi SoC, andhardware based on ESP-12 module.The figure 2.3 showing a NodeMCU development boardthat embedded ESP-12E module.The ESP module operate within 3.3V and developmentkit need 5V. It can be powered by USB connection or as we used in this project by apower bank.

Figure 3.3: NodeMCU DEVKIT 1.0 with Sensor and Power Bank

The NodeMCU development board can be programmed using Lua scripting language.Alsothere are some ESP8266 packages for Arduino IDE.By adding those packages and librariesNodeMCU can be programmed dereclty using Arduino IDE and C++.The devKit pro-grammed to read a temperature sensor,humidity sensor and moisture sensors and sendingdata as a client to a Raspberry Pi web server. The sensor node use MQTT (Message

8

Page 16: Affordable EMCS for GeenHouses

3 Implementation

Queuing Telemetry Transport) protocol to communicate with the central server.MQTTis a lightweight messaging protocol which uses a publish/subscribe communication pat-tern.MQTT protocol is used for machine-to-machine communication and commonly usedin the Internet of Things (IoT).

3.2 Sensors

3.2.1 DHT 11 Humidity and Temperature Sensor

The DHT11 is a low-cost, basic digital temperature and humidity sensor.It gives digitalsignal output using a capacitive humidity sensor and a thermistor by measuring thesurrounding air.The sensor gives new data from it once every 2 second. Thus sensorreadings can be up to 2 seconds old. Following figure showing a DHT11 sensor.

Figure 3.4: DHT11 Humidity and Temperature Sensor

3.2.2 Soil Moisture Sensor

The soil mosture sensor is low cost and easy to use.It have two large exposed padstogerther acting as a variable resistor.The conductivity between the pads will be highand the resistance will be low when water in the soil is high. Those parameters are usedto measure soil moisture level and give it as an analog signal output.Following figure 3.5showing a soil moisture sensor.

9

Page 17: Affordable EMCS for GeenHouses

3 Implementation

Figure 3.5: Soil Moisture sensor

3.3 Central Node of Sensor Network

Central Node of Sensor Network is the node which communicates with the centralizedserver. First, when the request comes from the centralized server, it gathers the requireddata from the sensor nodes in the network and sends it to a centralized server via ethernet.Raspberry Pi 2 board is used as the central node.

Figure 3.6: Raspberry Pi 3 Board

10

Page 18: Affordable EMCS for GeenHouses

3 Implementation

3.3.1 Development of Wireless Network

A wireless sensor network is a group of nodes which are capable of recording sensorydata at diverse locations and transmitting this data to a central node. Those nodeswhich are called sensor nodes are small, lightweight and portable. Commonly monitoredparameters are temperature, humidity, pressure, oxygen percentage and Carbon dioxidepercentage.The Central node is monitoring the activities of each sensors and act as aaccess to the sensor network. The central node is connected to a the distant server whichis used to monitor data and control the system. [1]

3.3.2 Sensor Node

Figure 3.7: The typical architecture of the sensor node

A sensor node[2] has capability of gathering, processing and transmitting a sensory datagathered using a transceiver. Therefore it is equipped with a microcomputer to processthe data, transceiver to communicate, power source to act as an independent device andone or more sensors. The sensor generates electrical signals based on sensed physical eectsand phenomena. The microcomputer processes sensor output. The transceiver data to thecentral node frequently. Wireless sensor nodes are very small devices with limited batterysource.The key factor of the sensor node is the power consumption. Sensor nodes areplaced inside the greenhouses. Therefore, the external power supply is not applicable. Thebest solution is power from the battery. To give power from a battery, those equipmentshould consume low power. Therefore, the design should be a low power sensor node.

3.4 Wireless Sensor Network

Wireless sensor network is used to monitor the greenhouse activities and control theenvironment in a way that the harvest of the plants in the greenhouse is maximized. Forthat an clustered wireless mesh network is created and sent data to a centralized serverwhich monitor the data given by the sensor network and give feedback to control thegreenhouse.The reason to create a clustered mesh network is to reduce the cost of the implementation

11

Page 19: Affordable EMCS for GeenHouses

3 Implementation

of the sensor network rather than using high cost nodes as sensor node and connectingthem to a relay node in the sensor network and send data through the sensor network.

1 cluster = Relay Node + Sensor nodes connectedto the given relay node

By clustering the low cost

sensor node for the nearest relay node, it allows to create very affordable sensor networkby using very few expensive relay nodes.

Figure 3.8: Sensor Network Overview

3.4.1 Low-cost Low-power Sensor Node

Sensor nodes are the leaf of the sensor network.sensors are connected to sensor nodes.Sensor nodes gather the data and send to central nodes.Thus sensor nodes are should becapable of getting inputs from sensors, process gathered data and wirelessly communicatewith central nodes.Considering those requirements and the cost,low-cost NodeMCUopen-source development kit was chosen to implement the sensor nodes. To make sensornodes are more power efficient, sleep mode used in the microprocessor(NodeMCU) andlightweight messaging protocol called MQTT was chosen over HTTP.

3.4.2 Relay Nodes in Sensor Network

Relay nodes are responsible for creating the mesh network and routing data to the centralnode. Relay nodes are created in a way which can automatically find the nearest relaynode and send data through the sensor network. For the routing, B.A.T.M.A.N (BetterApproach To Mobile Ad-hoc Network) protocol was used to create mesh network.It also has a running wifi access point where the nearest sensor nodes can connect andpublish data to the network using MQTT.Relay node is the node which create intermediate clusters of the network. It abstractdata from the sensor nodes and send it to the other relay nodes which are engaged in themesh network (B.A.T.M.A.N Network) and finally it flows though the central node tothe centralized server.

3.4.3 Central Node of Sensor Network

Central node is the node which communicate with the Relay nodes and gather data to besent to the centralized server. This includes an MQTT message broker which can brakethe message and send data to the centralized server using HTTP protocol. This nodeis known as the sync of the system. Which means all the data gathered in the sensornetwork finally be routed to the central node. This is the only node which is connected

12

Page 20: Affordable EMCS for GeenHouses

3 Implementation

to the centralized server for the communication purposes that makes the system moresecured.

3.4.4 Implementation

Sensor nodes developed using NodeMCU [3] platform. It can be programmed using Luaprogramming language [4]. Arduino IDE and esp8266 [5] package were used instead ofusing Lua directly. The node was programmed as follows,

• Connects to given MQTT server

• Read sensor values from given GPIOs

• Publishes those data as a JSON object to the given topic every two seconds

• Subscribers to the topic given topic to receive control commands

• Reconnecting functionality to the server if the connection is lost

Figure 3.9: Central Node Implementation

In centralized server, for the implementation Raspberry pi 2 board with wifi dongle wasused and to send data central node has to connect to another network (Default using theEthernet port).As the MQTT message broker, Mosquitto[6] was used and it runs in the backgroundof the central node’s Linux system. Then using python mqtt-paho [7] library the datawas gathered and converted in to JSON files and sent it to the centralized server for theprocessing and data gathering.Beside Mosquitto server centralized server runs the B.A.T.M.A.N protocol [8] and workas the bat0 port which is the default gateway for the mesh network. So it works as thesync of the mesh network.Also using the Shell scripts and Crontab [9] facility in the Raspbian OS [10] the process

13

Page 21: Affordable EMCS for GeenHouses

3 Implementation

was automated so even in reboot, the process runs automatically.For the Relay node B.A.T.M.A.N protocol was used to create the mesh network.

Figure 3.10: Central Node Implementation

B.A.T.M.A.N can identify the nearest member of the mesh network and configureautomatically.Besides B.A.T.M.A.N there is a access point running in every relay node which the sensornodes can search and join the network of the relay node. It is the way that the clustersof the network are automatically formed.

3.4.5 Gather Data from Sensor Nodes

MQTT is used as the communication protocol for the sensor network. MQTT is a mes-saging protocol for IOT(Internet of Things) devices which is extremely lightweight. Ituses Publisher/Subscriber method for communication. Nodes can publish data to theconnected network using a Topic and the central node can subscribe to the given Topicand receive data from any node which publishes data using the given Topic.

Central Node is using following Technologies to receive data from Nodes

• Mosquitto[6] (Linux Server to handle MQTT messages)

• Paho-mqtt 1.1[7] (Python Library for MQTT)

Mosquitto is a Linux based server to handle MQTT messages. When server is hosted itcan identify the devices connected to the server using MQTT protocol.

Paho-mqtt is a Python Library for MQTT. Data publishing and Subscription can bedone using that library. After running the Mosquitto in the Central Node, Python Scriptcan be run to subscribe to the given topic and receive messages from the Sensor Nodes.Sensor nodes send data payload as a JSON string to the central node under given topic.Central node extract data payload from the MQTT message and process it.

14

Page 22: Affordable EMCS for GeenHouses

3 Implementation

Figure 3.11: Running Mosquitto server with connected client(Sensor Node) 192.186.42.16

Figure 3.12: Incoming Message from Node 2

In figure 3.12 the topic is the node and the received JSON is printed below. 200 meansthat sending data to the centralized server is successful.

From that method nodes can be added or replaced dynamically.

The server inside the Central Node uses multi-threading to process messages since manysensors can send data at the same time.

3.4.6 Sending data to the Centralized Server

After receiving message from the sensor node the received JSON is processed. Thenanother JSON is created which matched the centralized server JSON receiving structure.Then the data is sent to the Centralized Server as a HTTP request using POST method.

The whole server was implemented using Python Programming Languages. To send dataRequests Library was used.

15

Page 23: Affordable EMCS for GeenHouses

3 Implementation

3.5 Development of Monitoring System

3.5.1 Centralized Server

The primary goal of the project to create a feature where modern farmers in agriculturalindustry can monitor their greenhouses remotely. This is a great advantage for farmerswho have several greenhouses in several areas. Therefore, an idea of the centralized servercomes to reality. This centralized server is acting as the access to the wireless sensornetwork. Also, it will store sensor data gathered from sensor network.

Figure 3.13: System Architecture diagram

Centralized server is developed based on spring framework [11]. The Spring Frameworkis an application framework build on the Java platform. The framework’s core featurescan be used by any Java application. But for building web applications on top of theJava EE platform there are extensions which are needed to be included. This server has

16

Page 24: Affordable EMCS for GeenHouses

3 Implementation

a fully REST API, which will be used by the front end of the monitoring system and thesensor networks.

The Centralized server and Monitoring System uses following technologies.

• Spring Core Library - Version 3.2

• MongoDB[12] - Version 3.2.4 open-source document database, and leading NoSQLdatabase) to save all the sensor data in the system.

• Gson [13] A Java serialization/deserialization library that can convert Java Objectsinto JSON and back.

• MongoDB java driver - create a connection between MongoDB server.

• Jackson data binding library - converts JSON to and from Java Maps, Lists, Strings,Numbers, Boolean, and null objects.

• Spring data Mongodb - library to work with MongoDB

This centralized server has main three parts. They are

• REST API for monitoring system

• REST API to receive data from Sensor Network

• REST API to control environmental factors in greenhouse

• Interface for the RESTful API

3.5.2 REST API for monitoring system

The centralized server was developed as a fully restful system because the REST APIcalls will be helpful for any developers where they can use it to develop a custom UserInterface or integrate those calls to any system that they already have. REST API formonitoring system consists several API calls including,

• Get the detail of the sensor network

• Get detail of the sensor nodes in the sensor network

• Get data as chart data for date range and sensor type

• Get the latest values for gauges

• Get data of a specific sensor type as chart data

17

Page 25: Affordable EMCS for GeenHouses

3 Implementation

To get the sensor types and number of sensors, aggregation is used. This system worksusing spring Data MongoDB library to query and aggregate data. Aggregation operationsprocess recorded data and give the calculated results. The aggregation results can begroups of similar characteristics. Using this aggregation operations, the system canidentify if there are new sensor types are available. Not only that system will show thenumber of all the nodes available in the system. There are REST API calls to retrieve thenumber of sensor nodes in the system, sensor types in the system and the system details.

To have the simplicity, for the chart data, the system uses key value pair object. There-fore if chart data was requested, then system will send a list of this key-value pairobjects.Those charts mostly need last 24 hour sensor data. There is also that facility anduser can customize the chart data request to get chart data in a custom date range andcustom interval like ’minutes’,’hours’,’days’ and etc.

For the chart data the system uses key value pair object. The total system give responsesin JSON format. Therefore any system can use those JSON responses and use those datato convert to any format.

3.5.3 REST API to receive data from Sensor Network

Centralized server doesn’t need a relational database management system. Becausethis system saves only the sensor data and network details in the system. Therefore anon-relational database was used in this system. There is a REST API calls to receivedata from Sensor Network. These calls will receive data in a specific format which isdesigned to reduce number of calls to the centralized server.

The sensor network is designed to use the minimum power consumption. Therefore, thesensor nodes are in sleep mode most of the time. Frequently It will automatically sendsensor data to the central node. At that time central node will send those sensor data tothe centralized server. These API calls are developed to receive those data from centralnode. There is common json object is used to receive sensor data. Also there are RESTAPI calls to retrieve network details from the sensor network.

18

Page 26: Affordable EMCS for GeenHouses

3 Implementation

3.5.4 REST API to control environmental factors in greenhouse

System has REST API calls which will send central node about which environmentalfactor to control. Centralized server will action to be done (”increase”, ”decrease” and”stop”). It will find the address of the central node and send request to the server incentral node to increase/decrease or stop changing the environmental factor.

3.5.5 Interface for the RESTful API

Most of the Restful systems are developed to separate client from server and reduce com-plexity. Therefore there is no description to look at the capabilities of the server.ThereforeSwagger[14] is use to represent the REST API. Swagger is a simple yet powerful rep-resentation of your RESTful API. With a Swagger-enabled API, There are interactivedocumentation, client SDK generation and discoverability.

Figure 3.14: Representation of the Restful API using Swagger

As shown in 3.14 any user who uses swagger, can see the all the calls provided by thesystem and user can test those calls and experience the required parameters and responsemodel.

19

Page 27: Affordable EMCS for GeenHouses

3 Implementation

3.5.6 Monitoring System - Front End

The front end of the monitoring and controlling system is a Web Interface to show thesensor data of the sensor network and control environmental factors. Web interface is abetter solution to real time monitoring and controlling system because it is accessiblefrom anywhere and no setup overhead. This is developed using AngularJS[15], JavascriptFramework. Those data are obtained by sensor network real time. Using AngularJs andKendo UI to show sensor data as chart data. Those sensor data will be shown as chartdata by using real-time data and old data saved in the centralized server. The charts andgauges are implemented using Kendo UI[16] library.

This web interface (Front End) has main three parts. They are,

• Network details

• Latest values

• Charts of Each Sensor Types

3.5.7 Network details

The user can see the details of the sensor network. Where is the sensor network is located,Which are the sensor types in the network, how many sensor nodes are available in thenetwork and etc.

3.5.8 Latest values

The web interface has gauges to show the latest values from the sensor network. It willreturn the most recent value from each sensor type.This gauges will show to the userthat if the environmental factor is not in comfortable area. Not only the real time value,the node number and the last checked time also can be seen in the web interface. TheLatest value part in the system is for user to get the idea about the latest environmentalfactors in the greenhouse. To get how the greenhouse environment in past can be seen infollowing section called chart data.

This web Interface is updated frequently. It uses AngularJS function called $interval andupdate the charts and gauges freuently.

20

Page 28: Affordable EMCS for GeenHouses

3 Implementation

Figure 3.15: gauges using kendo UI

3.5.9 Charts of Each Sensor Types

User can see the data gathered and stored from sensor network as line charts. The inputsfor the chart can be customized like changing date range, change time interval. The scalecan be changed like hours,days,weeks and etc. Also looking at chart data user can send asignal to centralized server to increase/decrease relevant environmental factor.Those charts uses Kendo UI chart which will identify the values as dates. Thereforewhen adding values to the charts those values need to be converted to JavaScript date.Therefore the chart will use those data and draw the chart. The scale can be changedlike hours,days,weeks and etc.This web Interface is updated frequently. It uses AngularJs function called $interval andupdate the charts and gauges frequently.

Those charts uses Kendo UI chart library which will identify the values as dates. Thereforewhen adding values to the charts those values need to be converted to JavaScript date.Therefore the chart will use those data and draw the chart.

Figure 3.16: line chart using kendo UI.

21

Page 29: Affordable EMCS for GeenHouses

3 Implementation

3.5.10 Controlling Feature in Monitoring System

Controlling feature is developed in system with basic three actions. They are ”increase”,”decrease” and ”stop”. Web interface will send signal about either previous actions withthe respective environmental factor type.After monitoring the parameters in a greenhouse controlling aspects will be needed.For aexample when temperature in greenhouse goes down than predetermined value, heatersshould on while temperature comes to desired level.The Controlling system can be either manual or automated.Automated systems can bedesigned to be triggered when required criteria met. Also system can be controlled by auser when he needed manually. In this project, a manual system was designed.

3.6 Overall architecture

Figure 3.17: Controlling System Architecture diagram

Controlling system works based on HTTP requests.Sensor nodes have given static IPs.Web or mobile application send a requests to sensor nodes.Sensor node check the contentof the message and send relevant signal to accumulators. Accumulators work in A/Ccurrent normally 210V-230V voltages.But, sensor nodes are working withing 3.3V-5Vrange.Thus for controlling accumulators 5V 1-Channel Relay interface board were used.

22

Page 30: Affordable EMCS for GeenHouses

3 Implementation

Figure 3.18: 5V 1-Channel Relay interface board

5V 1-Channel Relay interface board is standard interface that can be controlled directlyby microcontroller ,such as Arduino , 8051, AVR, PIC, DSP, ARM. Each one needs15-20mA driver current equipped with high-current relay, AC250V 10A ; DC30V 10A As

Figure 3.19: Relay interface connection with accumulator

the figure 3.18 showing 5V and GND pin of the relay connected to the sensor node 5Vand GND. The IN pin is connected to out put pin in the sensor node.

23

Page 31: Affordable EMCS for GeenHouses

4 Challenges

4.1 Finding Appropriate Hardware

One of the challenges of the project was to find the best hardware for the implementation.Changing of hardware from time to time made the project successful but it delayed somemilestones of the project.

For the sensor node implementation best low cost low power wifi module had to be foundout. For that first ESP8266 07 module was tried out. It was good enough but with otherhardware which should had to be used to create the sensor node with that module wasnot time efficient and there was no good resource to find out how to implement it in abetter way. Finally NodeMCU module was found which was with all the equipments thatwas needed and it was very easy to programme and use out of the box. Also it was cheapenough for the project when compared to other other hardware available in the market.

Implementation of Central Node was another challenge. First central node was tried withthe Intel Galileo 2 board. It was very hard to use it as a device with communicationprotocols like HTTP. After some effort with it Raspberry Pi is known as the best optionfor the project. It had all the components needed for the central node implementation.Installing all the software and using in web was very easy with Raspberry Pi 2 B model.

4.2 Implementing Wireless Access Point inside Raspberry Piboard

According to the architecture of the system it was needed to create Wireless Access Pointinside the Central Node. But there was no better documentation to do it. So about thelinux operating system had be learned thoroughly to get the job done.

24

Page 32: Affordable EMCS for GeenHouses

4 Challenges

4.3 MQTT Protocol

Since the HTTP is not very energy efficient inside the Sensor Nodes research had to bedone about the existing better protocols for communication. Then MQTT and CoAPwas found. MQTT is widely used so MQTT had to be studied before the implementation.It is very energy efficient and consume power very well.

4.4 Lack of hardware

There were many hardware equipment which had to be used in the implementation. Butit was very hard to find them in electronic equipment shops since those hardware are notusually used. So huge effort had to be made to find the hardware for the project.

25

Page 33: Affordable EMCS for GeenHouses

5 Conclusion

A wireless sensor network for environment monitoring and controlling of greenhouse wasbuild successfully.The system tested in real time where data was successfully captured anddisplayed via a web interface.The mesh topology was used in sensor network.The captureddata presented to the user through line charts and gauges implemented using kendo UIframework.Also environment parameters can be controlled via web interface controllers.Wireless Sensor Network in greenhouse monitoring and controlling is extremely usefuland a low cost system presented in this paper is more affordable for both small and largescale greenhouses.

5.1 Future work

For the future works following are suggested.Data mining techniques can be used on stored data to identify patterns and predictthe future.Using those results greenhouse controlling system can be automated in muchefficient way.

26

Page 34: Affordable EMCS for GeenHouses

Bibliography

[1] S. feng Yang and D. S. Simbeye, “Computerized Greenhouse Environ-mental Monitoring and Control System Based on LabWindows/CV,”https://www.researchgate.net/publication/262380106 Computerized GreenhouseEnvironmental Monitoring and Control System Based on LabWindowsCVI, 2013.

[2] “Sensor Node,” https://en.wikipedia.org/wiki/Sensor node.

[3] “ESP8266 ESP-12E NodeMCU,” https://en.wikipedia.org/wiki/NodeMCU.

[4] “Lua,” https://www.lua.org/, 2016.

[5] “WiFi Module-ESP8266,” https://www.sparkfun.com/products/13678.

[6] “Mosquitto,” http://mosquitto.org, 2016.

[7] “pahomqtt 1.1,” https://pypi.python.org/pypi/paho-mqtt/1.1, 2016.

[8] “B.A.T.M.A.N,” https://en.wikipedia.org/wiki/B.A.T.M.A.N., 2016.

[9] “CronHowto,” https://help.ubuntu.com/community/CronHowto, 2016.

[10] “Raspbian,” https://www.raspbian.org/, 2016.

[11] “Spring Framework,” https://spring.io/, 2016.

[12] “MongoDB,” https://www.mongodb.com/, 2016.

[13] “gson,” https://github.com/google/gson, 2016.

[14] “Swagger,” http://swagger.io/, 2016.

[15] “AngularJS,” https://angularjs.org/, 2016.

[16] “Kendo UI,” http://www.telerik.com/kendo-ui, 2016.

[17] “How to create WiFi Hotspot in Raspberry Pi,” http://elinux.org/RPI-Wireless-Hotspot, 2015.

27