SlideShare a Scribd company logo
1 of 34
Download to read offline
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
Abstract
Greenhouses are used to increase harvest by controlling key factors which will affect the
planet growth. Real-time monitoring of the greenhouse environment with sensors can
significantly affect the plant growth by taking necessary control decisions which results
in an improvement of yields and economic performance. In this project, we propose an
environmental monitoring and controlling system that can collect the information related
to greenhouse environment using various sensors and monitor the greenhouse remotely
via 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 this
data 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 harvest
and improve quality of crops.
Summary of CO421 and CO425
CO421
In CO421 the basic implementation of the project was done intention of sensor data
acquisition and controlling the greenhouse environment using sensor nodes and central
node. So the implementation of the sensor network was done only using one internet
gateway (Central Node). So every node had to directly connect to the Central node in
order to send sensor data and receive control data. The system was made to be plug and
play. Any pre-configured sensor node can connect to the access point in the central node
and send data to centralized via it.
So the basic implementation of the project was completed in the end of the semester.
Introduction page 1-2
Backgroud page 5
Implimentation page 6-8
Conclusion page 27
CO425
In CO421 implementation there was a big issue in the implementation since all the sensor
nodes had to connect to the central node directly. So the implementation had to be
changed completely in order to achieve the goal of creating a sensor network using an
Ad-Hoc network. So the implementation details of the sensor network using clustered
mesh architecture is included in this report. Since that is the final goal achievement and
all the things which are done in the CO421 in creating a sensor node details are already
included in this report.
Introduction page 4
Implimentation page 9-22
Challenges 25-26
Conclusion + future works page 27
iii
Contents
1 Introduction 1
1.1 Greenhouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Wireless sensor network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Sensor Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 The project and its objectives . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Background 5
2.1 Related work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Implementation 6
3.1 Wireless Sensor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.1 Wireless sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2 Low-cost sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1.3 NodeMCU ESP8266 12-E NodeMCU development board . . . . . 8
3.2 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.1 DHT 11 Humidity and Temperature Sensor . . . . . . . . . . . . . 9
3.2.2 Soil Moisture Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Central Node of Sensor Network . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.1 Development of Wireless Network . . . . . . . . . . . . . . . . . . 11
3.3.2 Sensor Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 Wireless Sensor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4.1 Low-cost Low-power Sensor Node . . . . . . . . . . . . . . . . . . . 12
3.4.2 Relay Nodes in Sensor Network . . . . . . . . . . . . . . . . . . . . 12
3.4.3 Central Node of Sensor Network . . . . . . . . . . . . . . . . . . . 12
3.4.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4.5 Gather Data from Sensor Nodes . . . . . . . . . . . . . . . . . . . 14
3.4.6 Sending data to the Centralized Server . . . . . . . . . . . . . . . . 15
3.5 Development of Monitoring System . . . . . . . . . . . . . . . . . . . . . . 16
3.5.1 Centralized Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5.2 REST API for monitoring system . . . . . . . . . . . . . . . . . . 17
3.5.3 REST API to receive data from Sensor Network . . . . . . . . . . 18
3.5.4 REST API to control environmental factors in greenhouse . . . . . 19
3.5.5 Interface for the RESTful API . . . . . . . . . . . . . . . . . . . . 19
3.5.6 Monitoring System - Front End . . . . . . . . . . . . . . . . . . . . 20
3.5.7 Network details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.8 Latest values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
iv
Contents
3.5.9 Charts of Each Sensor Types . . . . . . . . . . . . . . . . . . . . . 21
3.5.10 Controlling Feature in Monitoring System . . . . . . . . . . . . . . 22
3.6 Overall architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4 Challenges 24
4.1 Finding Appropriate Hardware . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2 Implementing Wireless Access Point inside Raspberry Pi board . . . . . . 24
4.3 MQTT Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4 Lack of hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5 Conclusion 26
5.1 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Bibliography 27
v
List of Figures
1.1 The typical architecture of the sensor node . . . . . . . . . . . . . . . . . 2
3.1 The sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 A ESP8266 ESP 7 Wifi module . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 NodeMCU DEVKIT 1.0 with Sensor and Power Bank . . . . . . . . . . . 8
3.4 DHT11 Humidity and Temperature Sensor . . . . . . . . . . . . . . . . . 9
3.5 Soil Moisture sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.6 Raspberry Pi 3 Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.7 The typical architecture of the sensor node . . . . . . . . . . . . . . . . . 11
3.8 Sensor Network Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.9 Central Node Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.10 Central Node Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.11 Running Mosquitto server with connected client(Sensor Node) 192.186.42.16 15
3.12 Incoming Message from Node 2 . . . . . . . . . . . . . . . . . . . . . . . . 15
3.13 System Architecture diagram . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.14 Representation of the Restful API using Swagger . . . . . . . . . . . . . . 19
3.15 gauges using kendo UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.16 line chart using kendo UI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.17 Controlling System Architecture diagram . . . . . . . . . . . . . . . . . . 22
3.18 5V 1-Channel Relay interface board . . . . . . . . . . . . . . . . . . . . . 23
3.19 Relay interface connection with accumulator . . . . . . . . . . . . . . . . . 23
vi
List of Tables
3.1 Pin configuration to program ESP8266-ESP07 module using a USB-FDTI
module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
vii
1 Introduction
1.1 Greenhouse
Greenhouse is a farming structure where the plants which need a controlled climate
conditions 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. The
target 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 are
often used in agricultural industry in commercial production. Greenhouses are mostly
important 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 a
roof made of transparent material like glass to have a maximum solar radiation inside of
the 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 key
environmental factors which are needed to be controlled are temperature, irrigation, level
of light and shade, fertilizer application, and humidity. Greenhouses are used to increase
the harvest in an area where those previously explained key factors are not available as
it needs.
A greenhouse environment is a complex and dynamic environment which is needed to be
controlled carefully otherwise it will affect the crop cultivation. To have a better crop
production the climate conditions are needed to be adjusted by continuously monitoring
those environmental factors which are explained before. For an example a plant may
die because of too much water or because of not enough water. Poor light intensity and
high humidity often result in poor fruit set and quality. More accurate control can save
resources, effort taken and have a better crop production.
1
1 Introduction
1.2 Wireless sensor network
A wireless sensor network is a group of nodes which are capable of recording sensory data
at diverse locations and transmitting this data to a central node. Those nodes which are
called sensor nodes are small, lightweight and portable. Those detection stations have
various sensors attached to them and they have capability of processing sensory data
gathered using those sensors and also communicating with each other sensor nodes or
the central node.
Commonly monitored parameters are temperature, humidity, pressure, oxygen percentage
and Carbon dioxide percentage. The sensor network communicates with a central node
which is connected to all sensor nodes. The Central node is monitoring the activities of
each sensors and act as a access to the sensor network. The central node is connected to
a 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 data
gathered using a transceiver. Therefore it is equipped with a microcomputer to process
the data, transceiver to communicate, power source to act as an independent device and
2
1 Introduction
one or more sensors. The sensor generates electrical signals based on sensed physical
effects and phenomena. The microcomputer processes sensor output. The transceiver
data to the central node frequently. The power for each sensor node is derived from a
battery. Wireless sensor nodes are very small devices with limited battery source. These
sensor 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 placed
inside the greenhouses. Therefore, the external power supply is not applicable. The best
solution is power from the battery. To give power from a battery, those equipment should
consume low power. Therefore, the design should be a low power sensor node. There are
several low power sensor nodes in the market. But the cost for the sensor node is not
suitable for a farmer in the agricultural industry in Sri Lanka where is still a developing
country.
3
1 Introduction
1.4 The project and its objectives
In this project, we propose a affordable environmental monitoring and controlling system
where the environment can be monitored and controlled externally without using much
effort. Even though there are built solutions in the market they are very expensive and
not affordable to agriculture sectors in countries like Sri Lanka. Therefore need to have a
affordable and low cost greenhouse monitoring and controlling systems.
Developing countries like Sri Lanka, most of the farmers in agriculture sector cannot
afford high cost sensor networks. Some of the sensors will connect to a central company
server and to get that data a service charge hash to be paid to the company. Also as
described before the key factor of a sensor node is power consumption. Therefore one of
the objective of this project to build a affordable low cost low power sensor node which
can be released as a product easily.
As the development of the agriculture sector new generation of farmers like to use
new technology in their fields consecutively monitoring and controlling the greenhouses
remotely and not be in the fields all the time. Therefore a wireless sensor network is
proposed in this project which will be affordable and low cost. By this wireless sensor
network users can monitor key factors which are explained before remotely. With the
wireless sensor network a centralized server is proposed as an objective to gather and
store 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 development
of agriculture industry. If the greenhouse is monitored remotely it will be good to control
it in remotely . Therefore as the second phase of the project a controlling system along
with the monitoring system is also proposed. This controlling system will automatically
control the key factors to improve the crop production. This will attract the people
who are getting away from the agricultural sector with traditional methods with the
technological revolution. Therefore this monitoring and controlling system will try to
automate the old methods.
The rest of the report is organized as follows. In chapter 2 we discuss about the related
work. In chapter 3 we discuss the development of wireless sensor network and in chapter 4
we discuss about the development of the Monitoring system. Finally in chapter 5 results
and discussions are stated.
4
2 Background
2.1 Related work
Many researches have been done in Greenhouse Technology since it is the next chapter of
cost and space effective farming. Since greenhouses give more harvest than other method
world is moving towards greenhouse. The latest trend is to automate greenhouses using
sensor networks. Some same kind of projects have been done by
• School of Electronic Engineering, Huaihai Institute of Technology, Lianyungang,
China
http://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 Tuah
Jaya, 76100, Melaka, Malaysia
http://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 consumption
is one of their main concern. But no one has tried with the existing technologies like
NodeMCU, MQTT protocol and creating better sensor network using them at lower
cost.
5
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 affordable
cost of the system should be reduced. Because sensor nodes are the major equipment used
to build the system, reducing the cost of a sensor node will substantially reduce the cost
of the system. The sensor nodes available in market cost around 150 $for each. Therefore
to make an affordable system, creating a low-cost sensor node is being a primary target
of the project. The image of a sensor node showing in figure 3.1
Figure 3.1: The sensor node
6
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 protocol
stack that can give any microcontroller access to WiFi network. The ESP8266 is capable
of either hosting an application or offloading all Wi-Fi networking functions from another
application 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 module
with 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-FDTI
module
7
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 and
it uses the Lua scripting language.The firmware runs on the ESP8266 Wi-Fi SoC, and
hardware based on ESP-12 module.The figure 2.3 showing a NodeMCU development board
that embedded ESP-12E module.The ESP module operate within 3.3V and development
kit need 5V. It can be powered by USB connection or as we used in this project by a
power bank.
Figure 3.3: NodeMCU DEVKIT 1.0 with Sensor and Power Bank
The NodeMCU development board can be programmed using Lua scripting language.Also
there are some ESP8266 packages for Arduino IDE.By adding those packages and libraries
NodeMCU can be programmed dereclty using Arduino IDE and C++.The devKit pro-
grammed to read a temperature sensor,humidity sensor and moisture sensors and sending
data as a client to a Raspberry Pi web server. The sensor node use MQTT (Message
8
3 Implementation
Queuing Telemetry Transport) protocol to communicate with the central server.MQTT
is a lightweight messaging protocol which uses a publish/subscribe communication pat-
tern.MQTT protocol is used for machine-to-machine communication and commonly used
in 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 digital
signal output using a capacitive humidity sensor and a thermistor by measuring the
surrounding air.The sensor gives new data from it once every 2 second. Thus sensor
readings 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 pads
togerther acting as a variable resistor.The conductivity between the pads will be high
and the resistance will be low when water in the soil is high. Those parameters are used
to measure soil moisture level and give it as an analog signal output.Following figure 3.5
showing a soil moisture sensor.
9
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 centralized
server. First, when the request comes from the centralized server, it gathers the required
data 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
3 Implementation
3.3.1 Development of Wireless Network
A wireless sensor network is a group of nodes which are capable of recording sensory
data at diverse locations and transmitting this data to a central node. Those nodes
which are called sensor nodes are small, lightweight and portable. Commonly monitored
parameters are temperature, humidity, pressure, oxygen percentage and Carbon dioxide
percentage.The Central node is monitoring the activities of each sensors and act as a
access to the sensor network. The central node is connected to a the distant server which
is 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 data
gathered using a transceiver. Therefore it is equipped with a microcomputer to process
the data, transceiver to communicate, power source to act as an independent device and
one or more sensors. The sensor generates electrical signals based on sensed physical eects
and phenomena. The microcomputer processes sensor output. The transceiver data to the
central node frequently. Wireless sensor nodes are very small devices with limited battery
source.The key factor of the sensor node is the power consumption. Sensor nodes are
placed inside the greenhouses. Therefore, the external power supply is not applicable. The
best solution is power from the battery. To give power from a battery, those equipment
should 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 the
environment in a way that the harvest of the plants in the greenhouse is maximized. For
that an clustered wireless mesh network is created and sent data to a centralized server
which monitor the data given by the sensor network and give feedback to control the
greenhouse.
The reason to create a clustered mesh network is to reduce the cost of the implementation
11
3 Implementation
of the sensor network rather than using high cost nodes as sensor node and connecting
them to a relay node in the sensor network and send data through the sensor network.
1 cluster = Relay Node + Sensor nodes connected
to the given relay node
By clustering the low cost
sensor node for the nearest relay node, it allows to create very affordable sensor network
by 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 be
capable of getting inputs from sensors, process gathered data and wirelessly communicate
with central nodes.Considering those requirements and the cost,low-cost NodeMCU
open-source development kit was chosen to implement the sensor nodes. To make sensor
nodes are more power efficient, sleep mode used in the microprocessor(NodeMCU) and
lightweight 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 central
node. Relay nodes are created in a way which can automatically find the nearest relay
node and send data through the sensor network. For the routing, B.A.T.M.A.N (Better
Approach 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 and
publish data to the network using MQTT.
Relay node is the node which create intermediate clusters of the network. It abstract
data from the sensor nodes and send it to the other relay nodes which are engaged in the
mesh network (B.A.T.M.A.N Network) and finally it flows though the central node to
the 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 be
sent to the centralized server. This includes an MQTT message broker which can brake
the message and send data to the centralized server using HTTP protocol. This node
is known as the sync of the system. Which means all the data gathered in the sensor
network finally be routed to the central node. This is the only node which is connected
12
3 Implementation
to the centralized server for the communication purposes that makes the system more
secured.
3.4.4 Implementation
Sensor nodes developed using NodeMCU [3] platform. It can be programmed using Lua
programming language [4]. Arduino IDE and esp8266 [5] package were used instead of
using 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 was
used and to send data central node has to connect to another network (Default using the
Ethernet port).
As the MQTT message broker, Mosquitto[6] was used and it runs in the background
of the central node’s Linux system. Then using python mqtt-paho [7] library the data
was gathered and converted in to JSON files and sent it to the centralized server for the
processing and data gathering.
Beside Mosquitto server centralized server runs the B.A.T.M.A.N protocol [8] and work
as the bat0 port which is the default gateway for the mesh network. So it works as the
sync of the mesh network.
Also using the Shell scripts and Crontab [9] facility in the Raspbian OS [10] the process
13
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 configure
automatically.
Besides B.A.T.M.A.N there is a access point running in every relay node which the sensor
nodes can search and join the network of the relay node. It is the way that the clusters
of 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. It
uses Publisher/Subscriber method for communication. Nodes can publish data to the
connected network using a Topic and the central node can subscribe to the given Topic
and 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 it
can identify the devices connected to the server using MQTT protocol.
Paho-mqtt is a Python Library for MQTT. Data publishing and Subscription can be
done using that library. After running the Mosquitto in the Central Node, Python Script
can 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
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 means
that 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 many
sensors 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. Then
another 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 data
Requests Library was used.
15
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 agricultural
industry can monitor their greenhouses remotely. This is a great advantage for farmers
who have several greenhouses in several areas. Therefore, an idea of the centralized server
comes to reality. This centralized server is acting as the access to the wireless sensor
network. 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 Framework
is an application framework build on the Java platform. The framework’s core features
can be used by any Java application. But for building web applications on top of the
Java EE platform there are extensions which are needed to be included. This server has
16
3 Implementation
a fully REST API, which will be used by the front end of the monitoring system and the
sensor 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 NoSQL
database) to save all the sensor data in the system.
• Gson [13] A Java serialization/deserialization library that can convert Java Objects
into 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 API
calls will be helpful for any developers where they can use it to develop a custom User
Interface or integrate those calls to any system that they already have. REST API for
monitoring 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
3 Implementation
To get the sensor types and number of sensors, aggregation is used. This system works
using spring Data MongoDB library to query and aggregate data. Aggregation operations
process recorded data and give the calculated results. The aggregation results can be
groups of similar characteristics. Using this aggregation operations, the system can
identify if there are new sensor types are available. Not only that system will show the
number of all the nodes available in the system. There are REST API calls to retrieve the
number 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 pair
objects.Those charts mostly need last 24 hour sensor data. There is also that facility and
user can customize the chart data request to get chart data in a custom date range and
custom interval like ’minutes’,’hours’,’days’ and etc.
For the chart data the system uses key value pair object. The total system give responses
in JSON format. Therefore any system can use those JSON responses and use those data
to 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. Because
this system saves only the sensor data and network details in the system. Therefore a
non-relational database was used in this system. There is a REST API calls to receive
data from Sensor Network. These calls will receive data in a specific format which is
designed to reduce number of calls to the centralized server.
The sensor network is designed to use the minimum power consumption. Therefore, the
sensor nodes are in sleep mode most of the time. Frequently It will automatically send
sensor data to the central node. At that time central node will send those sensor data to
the centralized server. These API calls are developed to receive those data from central
node. There is common json object is used to receive sensor data. Also there are REST
API calls to retrieve network details from the sensor network.
18
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 environmental
factor 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 in
central 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.Therefore
Swagger[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 interactive
documentation, 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 the
system and user can test those calls and experience the required parameters and response
model.
19
3 Implementation
3.5.6 Monitoring System - Front End
The front end of the monitoring and controlling system is a Web Interface to show the
sensor data of the sensor network and control environmental factors. Web interface is a
better solution to real time monitoring and controlling system because it is accessible
from anywhere and no setup overhead. This is developed using AngularJS[15], Javascript
Framework. Those data are obtained by sensor network real time. Using AngularJs and
Kendo UI to show sensor data as chart data. Those sensor data will be shown as chart
data by using real-time data and old data saved in the centralized server. The charts and
gauges 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 the
network and etc.
3.5.8 Latest values
The web interface has gauges to show the latest values from the sensor network. It will
return the most recent value from each sensor type.This gauges will show to the user
that 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. The
Latest value part in the system is for user to get the idea about the latest environmental
factors in the greenhouse. To get how the greenhouse environment in past can be seen in
following section called chart data.
This web Interface is updated frequently. It uses AngularJS function called $interval and
update the charts and gauges freuently.
20
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 inputs
for the chart can be customized like changing date range, change time interval. The scale
can be changed like hours,days,weeks and etc. Also looking at chart data user can send a
signal to centralized server to increase/decrease relevant environmental factor.
Those charts uses Kendo UI chart which will identify the values as dates. Therefore
when 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 changed
like hours,days,weeks and etc.
This web Interface is updated frequently. It uses AngularJs function called $interval and
update the charts and gauges frequently.
Those charts uses Kendo UI chart library which will identify the values as dates. Therefore
when 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
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 with
the respective environmental factor type.
After monitoring the parameters in a greenhouse controlling aspects will be needed.For a
example when temperature in greenhouse goes down than predetermined value, heaters
should on while temperature comes to desired level.
The Controlling system can be either manual or automated.Automated systems can be
designed to be triggered when required criteria met. Also system can be controlled by a
user 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 content
of the message and send relevant signal to accumulators. Accumulators work in A/C
current normally 210V-230V voltages.But, sensor nodes are working withing 3.3V-5V
range.Thus for controlling accumulators 5V 1-Channel Relay interface board were used.
22
3 Implementation
Figure 3.18: 5V 1-Channel Relay interface board
5V 1-Channel Relay interface board is standard interface that can be controlled directly
by microcontroller ,such as Arduino , 8051, AVR, PIC, DSP, ARM. Each one needs
15-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 5V
and GND. The IN pin is connected to out put pin in the sensor node.
23
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 some
milestones of the project.
For the sensor node implementation best low cost low power wifi module had to be found
out. For that first ESP8266 07 module was tried out. It was good enough but with other
hardware which should had to be used to create the sensor node with that module was
not time efficient and there was no good resource to find out how to implement it in a
better way. Finally NodeMCU module was found which was with all the equipments that
was needed and it was very easy to programme and use out of the box. Also it was cheap
enough 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 with
the Intel Galileo 2 board. It was very hard to use it as a device with communication
protocols like HTTP. After some effort with it Raspberry Pi is known as the best option
for 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 Pi
board
According to the architecture of the system it was needed to create Wireless Access Point
inside the Central Node. But there was no better documentation to do it. So about the
linux operating system had be learned thoroughly to get the job done.
24
4 Challenges
4.3 MQTT Protocol
Since the HTTP is not very energy efficient inside the Sensor Nodes research had to be
done about the existing better protocols for communication. Then MQTT and CoAP
was 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. But
it was very hard to find them in electronic equipment shops since those hardware are not
usually used. So huge effort had to be made to find the hardware for the project.
25
5 Conclusion
A wireless sensor network for environment monitoring and controlling of greenhouse was
build successfully.The system tested in real time where data was successfully captured and
displayed via a web interface.The mesh topology was used in sensor network.The captured
data presented to the user through line charts and gauges implemented using kendo UI
framework.Also environment parameters can be controlled via web interface controllers.
Wireless Sensor Network in greenhouse monitoring and controlling is extremely useful
and a low cost system presented in this paper is more affordable for both small and large
scale 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 predict
the future.Using those results greenhouse controlling system can be automated in much
efficient way.
26
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 Greenhouse
Environmental 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

More Related Content

What's hot

Heliostat Operators Manual
Heliostat Operators ManualHeliostat Operators Manual
Heliostat Operators ManualAntonio Teta
 
Air router user_guide
Air router user_guideAir router user_guide
Air router user_guiderujakarasbw
 
Motorola ap 7131 series access point product reference guide (part no. 72 e-1...
Motorola ap 7131 series access point product reference guide (part no. 72 e-1...Motorola ap 7131 series access point product reference guide (part no. 72 e-1...
Motorola ap 7131 series access point product reference guide (part no. 72 e-1...Advantec Distribution
 
Motorola solutions ap7131 access point installation guide wi ng 5.5 version...
Motorola solutions ap7131 access point installation guide   wi ng 5.5 version...Motorola solutions ap7131 access point installation guide   wi ng 5.5 version...
Motorola solutions ap7131 access point installation guide wi ng 5.5 version...Advantec Distribution
 
Bx310x Product Specification
Bx310x Product SpecificationBx310x Product Specification
Bx310x Product SpecificationFrederic Petit
 
Using gsm sim authentication in vp ns
Using gsm sim authentication in vp nsUsing gsm sim authentication in vp ns
Using gsm sim authentication in vp nsJamal Meselmani
 
patient monitoring using surface electromyography
patient monitoring using surface electromyographypatient monitoring using surface electromyography
patient monitoring using surface electromyographyMeghayu Adhvaryu
 
The Effect of CPU Clock Rate on Power Consumption
The Effect of CPU Clock Rate on Power ConsumptionThe Effect of CPU Clock Rate on Power Consumption
The Effect of CPU Clock Rate on Power ConsumptionMarc Bacvanski
 
Realtimesamplingofutilization
RealtimesamplingofutilizationRealtimesamplingofutilization
RealtimesamplingofutilizationVicente Nava
 
Au anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesisAu anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesisevegod
 
Integrating wind and solar energy in india for a smart grid platform
Integrating wind and solar energy in india for a smart grid platformIntegrating wind and solar energy in india for a smart grid platform
Integrating wind and solar energy in india for a smart grid platformFarhan Beg
 
37274377 6260-manual
37274377 6260-manual37274377 6260-manual
37274377 6260-manualDavid Reyes
 
Eap controller v2.4.8 ug
Eap controller v2.4.8 ugEap controller v2.4.8 ug
Eap controller v2.4.8 ugZaenal Mutakin
 
Mittapalli control remoto de un sistema mecatronico con comunicaciones inal...
Mittapalli   control remoto de un sistema mecatronico con comunicaciones inal...Mittapalli   control remoto de un sistema mecatronico con comunicaciones inal...
Mittapalli control remoto de un sistema mecatronico con comunicaciones inal...imranshaikh168323
 
BE Project Final Report on IVRS
BE Project Final Report on IVRSBE Project Final Report on IVRS
BE Project Final Report on IVRSAbhishek Nadkarni
 

What's hot (20)

Magicus clock
Magicus clockMagicus clock
Magicus clock
 
Heliostat Operators Manual
Heliostat Operators ManualHeliostat Operators Manual
Heliostat Operators Manual
 
Air router user_guide
Air router user_guideAir router user_guide
Air router user_guide
 
Motorola ap 7131 series access point product reference guide (part no. 72 e-1...
Motorola ap 7131 series access point product reference guide (part no. 72 e-1...Motorola ap 7131 series access point product reference guide (part no. 72 e-1...
Motorola ap 7131 series access point product reference guide (part no. 72 e-1...
 
Motorola solutions ap7131 access point installation guide wi ng 5.5 version...
Motorola solutions ap7131 access point installation guide   wi ng 5.5 version...Motorola solutions ap7131 access point installation guide   wi ng 5.5 version...
Motorola solutions ap7131 access point installation guide wi ng 5.5 version...
 
Bx310x Product Specification
Bx310x Product SpecificationBx310x Product Specification
Bx310x Product Specification
 
Using gsm sim authentication in vp ns
Using gsm sim authentication in vp nsUsing gsm sim authentication in vp ns
Using gsm sim authentication in vp ns
 
Refman3.0
Refman3.0Refman3.0
Refman3.0
 
patient monitoring using surface electromyography
patient monitoring using surface electromyographypatient monitoring using surface electromyography
patient monitoring using surface electromyography
 
The Effect of CPU Clock Rate on Power Consumption
The Effect of CPU Clock Rate on Power ConsumptionThe Effect of CPU Clock Rate on Power Consumption
The Effect of CPU Clock Rate on Power Consumption
 
Tesi v.d.cuccaro
Tesi v.d.cuccaroTesi v.d.cuccaro
Tesi v.d.cuccaro
 
Realtimesamplingofutilization
RealtimesamplingofutilizationRealtimesamplingofutilization
Realtimesamplingofutilization
 
report
reportreport
report
 
Au anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesisAu anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesis
 
Integrating wind and solar energy in india for a smart grid platform
Integrating wind and solar energy in india for a smart grid platformIntegrating wind and solar energy in india for a smart grid platform
Integrating wind and solar energy in india for a smart grid platform
 
Presentation1
Presentation1Presentation1
Presentation1
 
37274377 6260-manual
37274377 6260-manual37274377 6260-manual
37274377 6260-manual
 
Eap controller v2.4.8 ug
Eap controller v2.4.8 ugEap controller v2.4.8 ug
Eap controller v2.4.8 ug
 
Mittapalli control remoto de un sistema mecatronico con comunicaciones inal...
Mittapalli   control remoto de un sistema mecatronico con comunicaciones inal...Mittapalli   control remoto de un sistema mecatronico con comunicaciones inal...
Mittapalli control remoto de un sistema mecatronico con comunicaciones inal...
 
BE Project Final Report on IVRS
BE Project Final Report on IVRSBE Project Final Report on IVRS
BE Project Final Report on IVRS
 

Similar to Affordable EMCS for GeenHouses

Project Report Distance measurement system
Project Report Distance measurement systemProject Report Distance measurement system
Project Report Distance measurement systemkurkute1994
 
FYP_enerScope_Final_v4
FYP_enerScope_Final_v4FYP_enerScope_Final_v4
FYP_enerScope_Final_v4Hafiiz Osman
 
Project report on Eye tracking interpretation system
Project report on Eye tracking interpretation systemProject report on Eye tracking interpretation system
Project report on Eye tracking interpretation systemkurkute1994
 
Bidirectional Visitor Counter for efficient electricity usage.
Bidirectional Visitor Counter for efficient electricity usage.Bidirectional Visitor Counter for efficient electricity usage.
Bidirectional Visitor Counter for efficient electricity usage.NandaVardhanThupalli
 
Distributed Traffic management framework
Distributed Traffic management frameworkDistributed Traffic management framework
Distributed Traffic management frameworkSaurabh Nambiar
 
On-Line Presentation of Data from PMU Stations
On-Line Presentation of Data from PMU StationsOn-Line Presentation of Data from PMU Stations
On-Line Presentation of Data from PMU StationsPower System Operation
 
KurtPortelliMastersDissertation
KurtPortelliMastersDissertationKurtPortelliMastersDissertation
KurtPortelliMastersDissertationKurt Portelli
 
Wireless m-bus-quick-start-guide
Wireless m-bus-quick-start-guideWireless m-bus-quick-start-guide
Wireless m-bus-quick-start-guide봉조 김
 
Communication and Control in Electric Power Systems_ Applications of Parallel...
Communication and Control in Electric Power Systems_ Applications of Parallel...Communication and Control in Electric Power Systems_ Applications of Parallel...
Communication and Control in Electric Power Systems_ Applications of Parallel...alimeziane3
 
Maxime Javaux - Automated spike analysis
Maxime Javaux - Automated spike analysisMaxime Javaux - Automated spike analysis
Maxime Javaux - Automated spike analysisMaxime Javaux
 
Plc and scada report
Plc and scada reportPlc and scada report
Plc and scada reportIndira Kundu
 
Emf2192 ib _ethercat aif module__v3-1__en
Emf2192 ib _ethercat aif module__v3-1__enEmf2192 ib _ethercat aif module__v3-1__en
Emf2192 ib _ethercat aif module__v3-1__enCharles Santos
 
Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...
Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...
Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...TanuAgrawal27
 

Similar to Affordable EMCS for GeenHouses (20)

Project Report Distance measurement system
Project Report Distance measurement systemProject Report Distance measurement system
Project Report Distance measurement system
 
FYP_enerScope_Final_v4
FYP_enerScope_Final_v4FYP_enerScope_Final_v4
FYP_enerScope_Final_v4
 
T401
T401T401
T401
 
Final Report
Final ReportFinal Report
Final Report
 
Project report on Eye tracking interpretation system
Project report on Eye tracking interpretation systemProject report on Eye tracking interpretation system
Project report on Eye tracking interpretation system
 
Bidirectional Visitor Counter for efficient electricity usage.
Bidirectional Visitor Counter for efficient electricity usage.Bidirectional Visitor Counter for efficient electricity usage.
Bidirectional Visitor Counter for efficient electricity usage.
 
Distributed Traffic management framework
Distributed Traffic management frameworkDistributed Traffic management framework
Distributed Traffic management framework
 
thesis_SaurabhPanda
thesis_SaurabhPandathesis_SaurabhPanda
thesis_SaurabhPanda
 
On-Line Presentation of Data from PMU Stations
On-Line Presentation of Data from PMU StationsOn-Line Presentation of Data from PMU Stations
On-Line Presentation of Data from PMU Stations
 
USB OTG
USB OTGUSB OTG
USB OTG
 
KurtPortelliMastersDissertation
KurtPortelliMastersDissertationKurtPortelliMastersDissertation
KurtPortelliMastersDissertation
 
PLC & SCADA
PLC & SCADA PLC & SCADA
PLC & SCADA
 
Wireless m-bus-quick-start-guide
Wireless m-bus-quick-start-guideWireless m-bus-quick-start-guide
Wireless m-bus-quick-start-guide
 
Communication and Control in Electric Power Systems_ Applications of Parallel...
Communication and Control in Electric Power Systems_ Applications of Parallel...Communication and Control in Electric Power Systems_ Applications of Parallel...
Communication and Control in Electric Power Systems_ Applications of Parallel...
 
document
documentdocument
document
 
Maxime Javaux - Automated spike analysis
Maxime Javaux - Automated spike analysisMaxime Javaux - Automated spike analysis
Maxime Javaux - Automated spike analysis
 
Plc and scada report
Plc and scada reportPlc and scada report
Plc and scada report
 
Emf2192 ib _ethercat aif module__v3-1__en
Emf2192 ib _ethercat aif module__v3-1__enEmf2192 ib _ethercat aif module__v3-1__en
Emf2192 ib _ethercat aif module__v3-1__en
 
Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...
Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...
Smart Traffic Management System using Internet of Things (IoT)-btech-cse-04-0...
 
report
reportreport
report
 

Affordable EMCS for GeenHouses

  • 1. 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
  • 2. Abstract Greenhouses are used to increase harvest by controlling key factors which will affect the planet growth. Real-time monitoring of the greenhouse environment with sensors can significantly affect the plant growth by taking necessary control decisions which results in an improvement of yields and economic performance. In this project, we propose an environmental monitoring and controlling system that can collect the information related to greenhouse environment using various sensors and monitor the greenhouse remotely via 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 this data 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 harvest and improve quality of crops.
  • 3. Summary of CO421 and CO425 CO421 In CO421 the basic implementation of the project was done intention of sensor data acquisition and controlling the greenhouse environment using sensor nodes and central node. So the implementation of the sensor network was done only using one internet gateway (Central Node). So every node had to directly connect to the Central node in order to send sensor data and receive control data. The system was made to be plug and play. Any pre-configured sensor node can connect to the access point in the central node and send data to centralized via it. So the basic implementation of the project was completed in the end of the semester. Introduction page 1-2 Backgroud page 5 Implimentation page 6-8 Conclusion page 27 CO425 In CO421 implementation there was a big issue in the implementation since all the sensor nodes had to connect to the central node directly. So the implementation had to be changed completely in order to achieve the goal of creating a sensor network using an Ad-Hoc network. So the implementation details of the sensor network using clustered mesh architecture is included in this report. Since that is the final goal achievement and all the things which are done in the CO421 in creating a sensor node details are already included in this report. Introduction page 4 Implimentation page 9-22 Challenges 25-26 Conclusion + future works page 27 iii
  • 4. Contents 1 Introduction 1 1.1 Greenhouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Wireless sensor network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 Sensor Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.4 The project and its objectives . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 Background 5 2.1 Related work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3 Implementation 6 3.1 Wireless Sensor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.1 Wireless sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.2 Low-cost sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.1.3 NodeMCU ESP8266 12-E NodeMCU development board . . . . . 8 3.2 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.2.1 DHT 11 Humidity and Temperature Sensor . . . . . . . . . . . . . 9 3.2.2 Soil Moisture Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.3 Central Node of Sensor Network . . . . . . . . . . . . . . . . . . . . . . . 10 3.3.1 Development of Wireless Network . . . . . . . . . . . . . . . . . . 11 3.3.2 Sensor Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.4 Wireless Sensor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.4.1 Low-cost Low-power Sensor Node . . . . . . . . . . . . . . . . . . . 12 3.4.2 Relay Nodes in Sensor Network . . . . . . . . . . . . . . . . . . . . 12 3.4.3 Central Node of Sensor Network . . . . . . . . . . . . . . . . . . . 12 3.4.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.4.5 Gather Data from Sensor Nodes . . . . . . . . . . . . . . . . . . . 14 3.4.6 Sending data to the Centralized Server . . . . . . . . . . . . . . . . 15 3.5 Development of Monitoring System . . . . . . . . . . . . . . . . . . . . . . 16 3.5.1 Centralized Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.5.2 REST API for monitoring system . . . . . . . . . . . . . . . . . . 17 3.5.3 REST API to receive data from Sensor Network . . . . . . . . . . 18 3.5.4 REST API to control environmental factors in greenhouse . . . . . 19 3.5.5 Interface for the RESTful API . . . . . . . . . . . . . . . . . . . . 19 3.5.6 Monitoring System - Front End . . . . . . . . . . . . . . . . . . . . 20 3.5.7 Network details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 3.5.8 Latest values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 iv
  • 5. Contents 3.5.9 Charts of Each Sensor Types . . . . . . . . . . . . . . . . . . . . . 21 3.5.10 Controlling Feature in Monitoring System . . . . . . . . . . . . . . 22 3.6 Overall architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4 Challenges 24 4.1 Finding Appropriate Hardware . . . . . . . . . . . . . . . . . . . . . . . . 24 4.2 Implementing Wireless Access Point inside Raspberry Pi board . . . . . . 24 4.3 MQTT Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.4 Lack of hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5 Conclusion 26 5.1 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Bibliography 27 v
  • 6. List of Figures 1.1 The typical architecture of the sensor node . . . . . . . . . . . . . . . . . 2 3.1 The sensor node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.2 A ESP8266 ESP 7 Wifi module . . . . . . . . . . . . . . . . . . . . . . . . 7 3.3 NodeMCU DEVKIT 1.0 with Sensor and Power Bank . . . . . . . . . . . 8 3.4 DHT11 Humidity and Temperature Sensor . . . . . . . . . . . . . . . . . 9 3.5 Soil Moisture sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.6 Raspberry Pi 3 Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.7 The typical architecture of the sensor node . . . . . . . . . . . . . . . . . 11 3.8 Sensor Network Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.9 Central Node Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.10 Central Node Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.11 Running Mosquitto server with connected client(Sensor Node) 192.186.42.16 15 3.12 Incoming Message from Node 2 . . . . . . . . . . . . . . . . . . . . . . . . 15 3.13 System Architecture diagram . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.14 Representation of the Restful API using Swagger . . . . . . . . . . . . . . 19 3.15 gauges using kendo UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.16 line chart using kendo UI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.17 Controlling System Architecture diagram . . . . . . . . . . . . . . . . . . 22 3.18 5V 1-Channel Relay interface board . . . . . . . . . . . . . . . . . . . . . 23 3.19 Relay interface connection with accumulator . . . . . . . . . . . . . . . . . 23 vi
  • 7. List of Tables 3.1 Pin configuration to program ESP8266-ESP07 module using a USB-FDTI module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 vii
  • 8. 1 Introduction 1.1 Greenhouse Greenhouse is a farming structure where the plants which need a controlled climate conditions 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. The target 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 are often used in agricultural industry in commercial production. Greenhouses are mostly important 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 a roof made of transparent material like glass to have a maximum solar radiation inside of the 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 key environmental factors which are needed to be controlled are temperature, irrigation, level of light and shade, fertilizer application, and humidity. Greenhouses are used to increase the harvest in an area where those previously explained key factors are not available as it needs. A greenhouse environment is a complex and dynamic environment which is needed to be controlled carefully otherwise it will affect the crop cultivation. To have a better crop production the climate conditions are needed to be adjusted by continuously monitoring those environmental factors which are explained before. For an example a plant may die because of too much water or because of not enough water. Poor light intensity and high humidity often result in poor fruit set and quality. More accurate control can save resources, effort taken and have a better crop production. 1
  • 9. 1 Introduction 1.2 Wireless sensor network A wireless sensor network is a group of nodes which are capable of recording sensory data at diverse locations and transmitting this data to a central node. Those nodes which are called sensor nodes are small, lightweight and portable. Those detection stations have various sensors attached to them and they have capability of processing sensory data gathered using those sensors and also communicating with each other sensor nodes or the central node. Commonly monitored parameters are temperature, humidity, pressure, oxygen percentage and Carbon dioxide percentage. The sensor network communicates with a central node which is connected to all sensor nodes. The Central node is monitoring the activities of each sensors and act as a access to the sensor network. The central node is connected to a 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 data gathered using a transceiver. Therefore it is equipped with a microcomputer to process the data, transceiver to communicate, power source to act as an independent device and 2
  • 10. 1 Introduction one or more sensors. The sensor generates electrical signals based on sensed physical effects and phenomena. The microcomputer processes sensor output. The transceiver data to the central node frequently. The power for each sensor node is derived from a battery. Wireless sensor nodes are very small devices with limited battery source. These sensor 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 placed inside the greenhouses. Therefore, the external power supply is not applicable. The best solution is power from the battery. To give power from a battery, those equipment should consume low power. Therefore, the design should be a low power sensor node. There are several low power sensor nodes in the market. But the cost for the sensor node is not suitable for a farmer in the agricultural industry in Sri Lanka where is still a developing country. 3
  • 11. 1 Introduction 1.4 The project and its objectives In this project, we propose a affordable environmental monitoring and controlling system where the environment can be monitored and controlled externally without using much effort. Even though there are built solutions in the market they are very expensive and not affordable to agriculture sectors in countries like Sri Lanka. Therefore need to have a affordable and low cost greenhouse monitoring and controlling systems. Developing countries like Sri Lanka, most of the farmers in agriculture sector cannot afford high cost sensor networks. Some of the sensors will connect to a central company server and to get that data a service charge hash to be paid to the company. Also as described before the key factor of a sensor node is power consumption. Therefore one of the objective of this project to build a affordable low cost low power sensor node which can be released as a product easily. As the development of the agriculture sector new generation of farmers like to use new technology in their fields consecutively monitoring and controlling the greenhouses remotely and not be in the fields all the time. Therefore a wireless sensor network is proposed in this project which will be affordable and low cost. By this wireless sensor network users can monitor key factors which are explained before remotely. With the wireless sensor network a centralized server is proposed as an objective to gather and store 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 development of agriculture industry. If the greenhouse is monitored remotely it will be good to control it in remotely . Therefore as the second phase of the project a controlling system along with the monitoring system is also proposed. This controlling system will automatically control the key factors to improve the crop production. This will attract the people who are getting away from the agricultural sector with traditional methods with the technological revolution. Therefore this monitoring and controlling system will try to automate the old methods. The rest of the report is organized as follows. In chapter 2 we discuss about the related work. In chapter 3 we discuss the development of wireless sensor network and in chapter 4 we discuss about the development of the Monitoring system. Finally in chapter 5 results and discussions are stated. 4
  • 12. 2 Background 2.1 Related work Many researches have been done in Greenhouse Technology since it is the next chapter of cost and space effective farming. Since greenhouses give more harvest than other method world is moving towards greenhouse. The latest trend is to automate greenhouses using sensor networks. Some same kind of projects have been done by • School of Electronic Engineering, Huaihai Institute of Technology, Lianyungang, China http://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 Tuah Jaya, 76100, Melaka, Malaysia http://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 consumption is one of their main concern. But no one has tried with the existing technologies like NodeMCU, MQTT protocol and creating better sensor network using them at lower cost. 5
  • 13. 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 affordable cost of the system should be reduced. Because sensor nodes are the major equipment used to build the system, reducing the cost of a sensor node will substantially reduce the cost of the system. The sensor nodes available in market cost around 150 $for each. Therefore to make an affordable system, creating a low-cost sensor node is being a primary target of the project. The image of a sensor node showing in figure 3.1 Figure 3.1: The sensor node 6
  • 14. 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 protocol stack that can give any microcontroller access to WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application 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 module with 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-FDTI module 7
  • 15. 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 and it uses the Lua scripting language.The firmware runs on the ESP8266 Wi-Fi SoC, and hardware based on ESP-12 module.The figure 2.3 showing a NodeMCU development board that embedded ESP-12E module.The ESP module operate within 3.3V and development kit need 5V. It can be powered by USB connection or as we used in this project by a power bank. Figure 3.3: NodeMCU DEVKIT 1.0 with Sensor and Power Bank The NodeMCU development board can be programmed using Lua scripting language.Also there are some ESP8266 packages for Arduino IDE.By adding those packages and libraries NodeMCU can be programmed dereclty using Arduino IDE and C++.The devKit pro- grammed to read a temperature sensor,humidity sensor and moisture sensors and sending data as a client to a Raspberry Pi web server. The sensor node use MQTT (Message 8
  • 16. 3 Implementation Queuing Telemetry Transport) protocol to communicate with the central server.MQTT is a lightweight messaging protocol which uses a publish/subscribe communication pat- tern.MQTT protocol is used for machine-to-machine communication and commonly used in 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 digital signal output using a capacitive humidity sensor and a thermistor by measuring the surrounding air.The sensor gives new data from it once every 2 second. Thus sensor readings 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 pads togerther acting as a variable resistor.The conductivity between the pads will be high and the resistance will be low when water in the soil is high. Those parameters are used to measure soil moisture level and give it as an analog signal output.Following figure 3.5 showing a soil moisture sensor. 9
  • 17. 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 centralized server. First, when the request comes from the centralized server, it gathers the required data 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
  • 18. 3 Implementation 3.3.1 Development of Wireless Network A wireless sensor network is a group of nodes which are capable of recording sensory data at diverse locations and transmitting this data to a central node. Those nodes which are called sensor nodes are small, lightweight and portable. Commonly monitored parameters are temperature, humidity, pressure, oxygen percentage and Carbon dioxide percentage.The Central node is monitoring the activities of each sensors and act as a access to the sensor network. The central node is connected to a the distant server which is 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 data gathered using a transceiver. Therefore it is equipped with a microcomputer to process the data, transceiver to communicate, power source to act as an independent device and one or more sensors. The sensor generates electrical signals based on sensed physical eects and phenomena. The microcomputer processes sensor output. The transceiver data to the central node frequently. Wireless sensor nodes are very small devices with limited battery source.The key factor of the sensor node is the power consumption. Sensor nodes are placed inside the greenhouses. Therefore, the external power supply is not applicable. The best solution is power from the battery. To give power from a battery, those equipment should 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 the environment in a way that the harvest of the plants in the greenhouse is maximized. For that an clustered wireless mesh network is created and sent data to a centralized server which monitor the data given by the sensor network and give feedback to control the greenhouse. The reason to create a clustered mesh network is to reduce the cost of the implementation 11
  • 19. 3 Implementation of the sensor network rather than using high cost nodes as sensor node and connecting them to a relay node in the sensor network and send data through the sensor network. 1 cluster = Relay Node + Sensor nodes connected to the given relay node By clustering the low cost sensor node for the nearest relay node, it allows to create very affordable sensor network by 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 be capable of getting inputs from sensors, process gathered data and wirelessly communicate with central nodes.Considering those requirements and the cost,low-cost NodeMCU open-source development kit was chosen to implement the sensor nodes. To make sensor nodes are more power efficient, sleep mode used in the microprocessor(NodeMCU) and lightweight 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 central node. Relay nodes are created in a way which can automatically find the nearest relay node and send data through the sensor network. For the routing, B.A.T.M.A.N (Better Approach 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 and publish data to the network using MQTT. Relay node is the node which create intermediate clusters of the network. It abstract data from the sensor nodes and send it to the other relay nodes which are engaged in the mesh network (B.A.T.M.A.N Network) and finally it flows though the central node to the 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 be sent to the centralized server. This includes an MQTT message broker which can brake the message and send data to the centralized server using HTTP protocol. This node is known as the sync of the system. Which means all the data gathered in the sensor network finally be routed to the central node. This is the only node which is connected 12
  • 20. 3 Implementation to the centralized server for the communication purposes that makes the system more secured. 3.4.4 Implementation Sensor nodes developed using NodeMCU [3] platform. It can be programmed using Lua programming language [4]. Arduino IDE and esp8266 [5] package were used instead of using 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 was used and to send data central node has to connect to another network (Default using the Ethernet port). As the MQTT message broker, Mosquitto[6] was used and it runs in the background of the central node’s Linux system. Then using python mqtt-paho [7] library the data was gathered and converted in to JSON files and sent it to the centralized server for the processing and data gathering. Beside Mosquitto server centralized server runs the B.A.T.M.A.N protocol [8] and work as the bat0 port which is the default gateway for the mesh network. So it works as the sync of the mesh network. Also using the Shell scripts and Crontab [9] facility in the Raspbian OS [10] the process 13
  • 21. 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 configure automatically. Besides B.A.T.M.A.N there is a access point running in every relay node which the sensor nodes can search and join the network of the relay node. It is the way that the clusters of 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. It uses Publisher/Subscriber method for communication. Nodes can publish data to the connected network using a Topic and the central node can subscribe to the given Topic and 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 it can identify the devices connected to the server using MQTT protocol. Paho-mqtt is a Python Library for MQTT. Data publishing and Subscription can be done using that library. After running the Mosquitto in the Central Node, Python Script can 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
  • 22. 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 means that 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 many sensors 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. Then another 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 data Requests Library was used. 15
  • 23. 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 agricultural industry can monitor their greenhouses remotely. This is a great advantage for farmers who have several greenhouses in several areas. Therefore, an idea of the centralized server comes to reality. This centralized server is acting as the access to the wireless sensor network. 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 Framework is an application framework build on the Java platform. The framework’s core features can be used by any Java application. But for building web applications on top of the Java EE platform there are extensions which are needed to be included. This server has 16
  • 24. 3 Implementation a fully REST API, which will be used by the front end of the monitoring system and the sensor 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 NoSQL database) to save all the sensor data in the system. • Gson [13] A Java serialization/deserialization library that can convert Java Objects into 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 API calls will be helpful for any developers where they can use it to develop a custom User Interface or integrate those calls to any system that they already have. REST API for monitoring 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
  • 25. 3 Implementation To get the sensor types and number of sensors, aggregation is used. This system works using spring Data MongoDB library to query and aggregate data. Aggregation operations process recorded data and give the calculated results. The aggregation results can be groups of similar characteristics. Using this aggregation operations, the system can identify if there are new sensor types are available. Not only that system will show the number of all the nodes available in the system. There are REST API calls to retrieve the number 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 pair objects.Those charts mostly need last 24 hour sensor data. There is also that facility and user can customize the chart data request to get chart data in a custom date range and custom interval like ’minutes’,’hours’,’days’ and etc. For the chart data the system uses key value pair object. The total system give responses in JSON format. Therefore any system can use those JSON responses and use those data to 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. Because this system saves only the sensor data and network details in the system. Therefore a non-relational database was used in this system. There is a REST API calls to receive data from Sensor Network. These calls will receive data in a specific format which is designed to reduce number of calls to the centralized server. The sensor network is designed to use the minimum power consumption. Therefore, the sensor nodes are in sleep mode most of the time. Frequently It will automatically send sensor data to the central node. At that time central node will send those sensor data to the centralized server. These API calls are developed to receive those data from central node. There is common json object is used to receive sensor data. Also there are REST API calls to retrieve network details from the sensor network. 18
  • 26. 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 environmental factor 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 in central 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.Therefore Swagger[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 interactive documentation, 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 the system and user can test those calls and experience the required parameters and response model. 19
  • 27. 3 Implementation 3.5.6 Monitoring System - Front End The front end of the monitoring and controlling system is a Web Interface to show the sensor data of the sensor network and control environmental factors. Web interface is a better solution to real time monitoring and controlling system because it is accessible from anywhere and no setup overhead. This is developed using AngularJS[15], Javascript Framework. Those data are obtained by sensor network real time. Using AngularJs and Kendo UI to show sensor data as chart data. Those sensor data will be shown as chart data by using real-time data and old data saved in the centralized server. The charts and gauges 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 the network and etc. 3.5.8 Latest values The web interface has gauges to show the latest values from the sensor network. It will return the most recent value from each sensor type.This gauges will show to the user that 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. The Latest value part in the system is for user to get the idea about the latest environmental factors in the greenhouse. To get how the greenhouse environment in past can be seen in following section called chart data. This web Interface is updated frequently. It uses AngularJS function called $interval and update the charts and gauges freuently. 20
  • 28. 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 inputs for the chart can be customized like changing date range, change time interval. The scale can be changed like hours,days,weeks and etc. Also looking at chart data user can send a signal to centralized server to increase/decrease relevant environmental factor. Those charts uses Kendo UI chart which will identify the values as dates. Therefore when 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 changed like hours,days,weeks and etc. This web Interface is updated frequently. It uses AngularJs function called $interval and update the charts and gauges frequently. Those charts uses Kendo UI chart library which will identify the values as dates. Therefore when 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
  • 29. 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 with the respective environmental factor type. After monitoring the parameters in a greenhouse controlling aspects will be needed.For a example when temperature in greenhouse goes down than predetermined value, heaters should on while temperature comes to desired level. The Controlling system can be either manual or automated.Automated systems can be designed to be triggered when required criteria met. Also system can be controlled by a user 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 content of the message and send relevant signal to accumulators. Accumulators work in A/C current normally 210V-230V voltages.But, sensor nodes are working withing 3.3V-5V range.Thus for controlling accumulators 5V 1-Channel Relay interface board were used. 22
  • 30. 3 Implementation Figure 3.18: 5V 1-Channel Relay interface board 5V 1-Channel Relay interface board is standard interface that can be controlled directly by microcontroller ,such as Arduino , 8051, AVR, PIC, DSP, ARM. Each one needs 15-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 5V and GND. The IN pin is connected to out put pin in the sensor node. 23
  • 31. 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 some milestones of the project. For the sensor node implementation best low cost low power wifi module had to be found out. For that first ESP8266 07 module was tried out. It was good enough but with other hardware which should had to be used to create the sensor node with that module was not time efficient and there was no good resource to find out how to implement it in a better way. Finally NodeMCU module was found which was with all the equipments that was needed and it was very easy to programme and use out of the box. Also it was cheap enough 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 with the Intel Galileo 2 board. It was very hard to use it as a device with communication protocols like HTTP. After some effort with it Raspberry Pi is known as the best option for 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 Pi board According to the architecture of the system it was needed to create Wireless Access Point inside the Central Node. But there was no better documentation to do it. So about the linux operating system had be learned thoroughly to get the job done. 24
  • 32. 4 Challenges 4.3 MQTT Protocol Since the HTTP is not very energy efficient inside the Sensor Nodes research had to be done about the existing better protocols for communication. Then MQTT and CoAP was 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. But it was very hard to find them in electronic equipment shops since those hardware are not usually used. So huge effort had to be made to find the hardware for the project. 25
  • 33. 5 Conclusion A wireless sensor network for environment monitoring and controlling of greenhouse was build successfully.The system tested in real time where data was successfully captured and displayed via a web interface.The mesh topology was used in sensor network.The captured data presented to the user through line charts and gauges implemented using kendo UI framework.Also environment parameters can be controlled via web interface controllers. Wireless Sensor Network in greenhouse monitoring and controlling is extremely useful and a low cost system presented in this paper is more affordable for both small and large scale 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 predict the future.Using those results greenhouse controlling system can be automated in much efficient way. 26
  • 34. 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 Greenhouse Environmental 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