Sensor Network Proposal for Greenhouse Automation placed at the South of Algeria

The south of Algeria has a very hard climate. In summer, it is very hot and dry with a very violent sand wind and in winter very cold and dry, from where several plants cannot be cultivated in an open field. With rapid population growth, the production of fruits and vegetables cannot be sufficient. To solve these two major problems, we propose in this paper a new mechanism for the control of the climate inside a greenhouse. The objective of this work is to propose a new design for the greenhouse that can be managed and controlled automatically. The management and the control of this greenhouse are done because of our new proposed algorithms, and the use of new technologies such as sensors, actuators, microcontrollers, and the Internet of things to facilitate the tasks of farmers in the south of Algeria, and to improve the productiveness of the agriculture. We present the results of applying our proposal in a greenhouse during a short period of time and the changes on the environmental parameters inside the greenhouse.


Introduction
Since the 1990s, the Internet has become an essential component of our daily lives. It has evolved from simple hypertext pages to the Internet of content (e-mail, information, etc.) and the Internet of services where services such as e-commerce are born. Then, to the internet of people or to what we know as social media where people communicate with each other. And now, we are on the edge of the Internet of Things (IoT) [1] where things communicate and interact (from machine to machine).
After the oil crisis that touched Algeria, approximately three years ago, Algeria's economy is directed to several sectors, particularly the agriculture sector. For better yield and to ensure a product with good quality in southern Algeria, the plants are cultivated in greenhouses [2,3]. According to the French standard NF U57-001, the greenhouse is an enclosure for growing or protecting plants by exploiting solar radiation. The dimensions of this enclosure allow a man to work easily [4]. The objective of greenhouses is to produce crops outside the natural growing season and to protect plants in arid areas. Nonetheless, the major problem to face is how to control the internal microclimate of greenhouses in southern Algeria. Mainly because the south has a very harsh climate and the environmental conditions change fast [5].
These last decades, technology has developed very fast in several sectors. Among these new technologies, we find the sensors, the actuators, the controllers, and its integration in common objects according to the IoT. There are many authors who have to used the IoT for agriculture monitoring and precision agriculture such as J. Marin et al. who automatized the grass production [6]. L. Parra et al. that presented the use of sensors for monitoring the orange trees [7]. Or the application of F. Llario et al. to control the behavior of goats and sheep to prevent wolf attacks [8]. Following the aforementioned examples, if we implement these new technologies in the classical greenhouses, they will become automatic greenhouses. The purpose of an automatic greenhouse is to ensure that the plant needs are covered in an efficient and accurate way. And the advantage of these automatic greenhouses is that they can irrigate plants, give them heat and light according to the environmental conditions. Moreover, the automatic greenhouses are able to fertilize the plants when it is needed. The IoT and the integration of algorithms, artificial intelligence, and cloud computing are some of the technologies and tools that can be used to have a smart greenhouse.
In this paper, we propose the design of a system and the required mechanisms for monitoring the environmental parameters in a greenhouse. In addition, the system is composed of different algorithms that are responsible for taking actions to increase or decrease the value of different environmental parameters to ensure the wellbeing of the plant. The objective is to increase production using different sensors and actuators. We are going to detail what sensors and actuators will be needed for the smart greenhouse. Moreover, we are going to integrate our system with the CoAP protocol. In addition, we have designed the required algorithms for the automation of the actions in the greenhouse.
The rest of the paper is structured as follows. The related work in this axis of research is presented in the second section. In the third section, we propose a new design of a greenhouse that will be adaptable to the climate of southern Algeria, we also propose the algorithms that control our greenhouse and the use of the CoAP protocol. The results of our algorithm and discussion are presented in the fourth section. The last section is dedicated to the conclusion of our work with some perspectives that we wish to realize in the future.

Related work
In this section, we present the related work. Several works and research have been done to manage and monitor the internal microclimate of an automated greenhouse.
In [9], the authors presented a scheme of a greenhouse environmental monitoring system based on a wireless sensor network (WSN). The monitoring and management center can control the temperature and the humidity of the greenhouse. Moreover, it measures carbon dioxide, and collect information about the intensity of illumination. They evaluated their algorithm with the NS2 simulation tool. They compared their algorithm with the TSPN algorithm. Their results remarked that the proposed algorithm requires much less time than the TSPN. U. A. Waykole and D. G. Agrawal presented a prototype system in [10]. It contains a PIC16F877A microcontroller, a temperature sensor (LM35), a light dependent resistance (LDR), and a humidity sensor. Furthermore, their system had different actuator components (heating, two cooling fans, and solenoid valve) to meet the requirements of the system. It also uses an LCD screen to display the data obtained from the sensors and those of the user. The purpose of their system was to regulate the temperature, the light intensity, and the humidity to a user-defined value. In addition, it displays the current temperature value, the user-defined temperature value, the value of humidity, and the value of light intensity. The system has been tested in real time.
The authors of [11] have developed a greenhouse monitoring and control system based on Zigbee networks. The system could monitor temperature, humidity, soil moisture, and the concentration of carbon dioxide in a greenhouse. The system is also capable of saving this data in a database. They used the proportional-integral-derivative controller (PID) control method for greenhouse temperature control. The system was implemented using low power wireless components that are easy to install.
In [12], the authors presented a WSN with multiple sensor nodes and three commercial sensors to measure temperature, humidity, and light. Their configuration was tested in a real greenhouse for four hours in order to evaluate the reliability of the network and its capability to detect the microclimate. They used the LM35 temperature sensor, the SY-HS-220 moisture sensor, and an LDR as a light sensor. temperature and humidity using ZigBee technology and the WSN system. They used the Peripheral Interface Controller (PIC) as hardware, an LCD Display, and Zigbee as a communication technology. The C compiler and MP Lab IDE were utilized as a software. The data from the greenhouse was measured by the sensor. Then, the data was displayed on the LCD screen of the receiver, which supports up to 100 m of range. To test the feasibility of the developed node, they deployed a simple sensor network in the agriculture department of the Melaka Tengah greenhouse in Malaysia.
The authors in [14] presented a monitoring and control system for a greenhouse following the new IoT design. Their system can monitor different environmental parameters such as humidity, soil moisture, temperature, and the presence of fire among others. The GSM module is used to send a message to the registered number. The messages were sent if one or more parameters exceed certain limits. They used a soil moisture sensor that monitored soil moisture to send an alarm when the soil is running out of water. An MQ-5 sensor was selected to detect toxic gases, as carbon dioxide, if they were present. In addition, an SY-HS-220 air humidity sensor was utilized to monitor the water content of the greenhouse. An LM35 sensor for air temperature was used to measure the temperature in the greenhouse. Finally, a color sensor was utilized for detecting color changes in the sheets. Their system was tested under various combinations of inputs in their laboratory and the experimental results were found as expected.
Another monitoring and control system for a smart greenhouse was proposed K.H Athira and P. Indusekhar in [15]. Whenever sensor values attain a certain threshold, the sensors send a signal to the mega 328P AT microcontroller. The microcontroller processes it and forwards it to the computer using Zigbee technology. The corresponding automation output values are displayed on the computer and greenhouse warnings are sent to the farmer as a message via GSM. They used the DHT11 sensor that measures the temperature and humidity of the greenhouse. Furthermore, they add to the system a light sensor to detect if the greenhouse plants need light or not, and a soil moisture sensor that tests if the soil needs water or not.
A. J. Ramadhan [16] proposed a new system to monitor and control remotely the temperature, humidity and soil moisture of greenhouses. The system implemented a control process to define the parameters required for plant growth. The system algorithms were in charge of activating and/or stopping the actuators in case the system detected a modification of the climatic parameters. He also used GSM and Internet technologies to monitor greenhouses from anywhere. In addition, he used an ATmega 328 MCU as a microcontroller. To monitor the temperature and humidity of the greenhouse they proposed to utilize an RHT03 for the temperature sensor and an EC-5 analog output sensor for soil moisture.
Shirsat, D.O. et al. [17] described the design of an IoT-based greenhouse monitoring and control system using Arduino. Their system was in charge of taking the right decisions. It was responsible for providing the farmer with the sensor measurement via the IoT web server. Besides, this system helped farmers to control greenhouses from distant places. To control and monitor the greenhouse, they included a series of sensors. The utilized sensors are the following ones, a sensor for soil moisture, a sensor for monitoring the light of greenhouse, a Network Protocols and Algorithms ISSN 1943-3581 2018 www.macrothink.org/npa 57 DHT11 sensor for air humidity, and an LM35 for air temperature. Their system was tested in real time.
The main difference between our proposal and the current ones are the usage of the COAP protocol to communicate our nodes. We use nodes to sense the environment, nodes with actuators to modify the sensed parameters and a controller to activate and deactivate the actuators.

Proposed approach
In this section, we present a proposal for our greenhouse monitoring system. First of all, the used sensors, actuators and controller are detailed. Then, the utilized communication protocol is shown. Finally, the utilized algorithms are shown.

Proposed design for automation of greenhouse
In this subsection the sensors, actuators and the control method are detailed. After a thorough study in the literature that treats the problem of management and control of greenhouses, we will use the following material for the control of our greenhouse. The proposed design can be seen in Fig. 1. In our design, we include sensors, actuators, and a controller.
On the one hand, we select to monitor three environmental parameters in our system. The monitored parameters are the temperature of the air, the relative humidity of the air and the pH of the soil. We use nodes with WiFi antennas to gather de data from each sensor. Moreover, the node is responsible to send the gathered data to the controller. The deployment and the utilized sensors are detailed below: -Air temperature sensors: They are placed in different places of the greenhouse to measure air temperature. Since many plants are sensitive to the temperature of the air during irrigation, it is preferable to avoid irrigation especially if the greenhouse is very hot or very cold. The air temperature sensor used in our design is LM35. On the other hand, the actuators are selected. There are actuators at the fan, the heater, the sprinklers, the window, a reservoir for lime and one for organic matter. The fundamental objective of the actuators is for the equipment to function automatically. Each actuator is connected to one node with a WiFi antenna. The node will receive information from the controller indicating if the actuator must be turned on/off. The details of the actuators are described below.
-The fan: It is responsible for cooling the air if the temperature of the greenhouse is inferior to the ambient temperature. It is necessary for arid zones like the south of Network Protocols and Algorithms ISSN 1943-3581 2018 Algeria, especially in summer. -The heater: It is necessary especially during the winter and it can improve the growth of plants in the summer by keeping the temperature of the greenhouse above the ambient levels. -The water valve or the sprinkler: Especially in summer and in the southern areas of Algeria where the climate is hot and dry, the irrigation is needed to ensure that the plant has enough available water. Therefore, it is preferable to use automated water valves to irrigate plants in case of lack of water in the soil. The controller is in charge of acquiring the data of the various sensors and it controls the various actuators. Thus, we have embedded our algorithms in the controller. The proposed algorithms allow checking the temperature, humidity, and pH measured by the sensors with different thresholds of temperature, humidity, and pH. After the various treatments, the controller makes the decision and sends a command to the actuators as needed. And at the same time, the controller sends information about the current status of the greenhouse to the farmer via the LoRaPAN. The controller receives the data from the nodes with sensors via WiFi and sends the data to the actuator with the same technology.

Protocol description: CoAP
The Constrained Application Protocol (CoAP) description is presented in this subsection. CoAP [18] is an application layer protocol similar to, simpler and interoperable with HTTP. It meets the requirements of Machine-to-Machine communications in constrained environments, works over UDP and provides optional reliability. It also allows asynchronous message exchanges, low header overhead and the usage of URIs and Content-type.
There are four types of messages in CoAP: • Confirmable messages (CON): Confirmable messages have the type 0. These messages require an ACK. The format of the CoAP message is the one presented in Fig. 2. The fixed header size is 4 bytes. The version must have the value 01. Type indicates the message type as explained before. The TKL is the length of the variable field Token. The code provides information on the message. It is divided into two sections. The class section has 3 bits and corresponds to  (2), client error (4) and server error (5). The detail section has 5 bits and it further indicates the information of the message. Token may have a length ranging from 0 to 8 bytes and it is utilized to correlate petitions and responses. Options is a field that may have 0 or more bytes. In the case of the observer option, it may have a length of 3 bytes. The payload may have a length of 0 or more bytes. If there is a payload, it is preceded by a payload marker of 1 byte of length (0xFF).
The CoAP message occupies the field where the UDP payload is supposed to be (see Fig.  3). The length of the CoAP packet may vary according to the message type, the token size, the options, and the data forwarded on the payload. However, the maximum length of the CoAP payload is 1024 bytes.    Both petitions and responses share the same message format. Furthermore, the message ID allows detecting duplicate messages and provides reliability. The reliability is obtained forwarding confirmable messages. These messages utilize a predetermined timeout and an exponential back-off until an ACK is received. The received ACK must have the same ID as the petition. If the message cannot be processed correctly, the response is performed with an RST message. If no reliability is required, NON messages are forwarded. These messages do not receive ACK responses. However, in order to detect duplicates, the message ID is utilized. As well as for CON messages, if the NON message cannot be processed correctly, an RST response is received. Multicast messages are supported as well.
Petitions are performed utilizing either CON or NON messages. The responses of CON messages are usually piggybacked on ACKs, although the ACK may be received separately prior to receiving the response. Said separated response would be performed utilizing a CON message. Fig. 4 presents an example of CON messages both with and without piggybacked responses. A petition with a message id, the resource whose information is wanted, and the token is forwarded. The response matches the message id and the token and includes the code that indicates that the message is carrying content and the information itself. For the piggybacked response this is performed in an ACK message whereas, for the separate response, it occurs on a CON message. The responses of NON messages are performed utilizing other NON messages (See Fig. 5). The message id and the token match the petition as well as for CON messages. Furthermore, the response includes the code for content and the requested information as well. Empty messages are forwarded utilizing either RST or ACK messages.  The observe option, specified in a separate RFC [19], allows the client to subscribe to a determined resource so as to receive it periodically. The subscription is performed utilizing a GET message with the observe option set to 0 (register). To unsubscribe, the observe option must be set to 1. The client and the Token value are then added to the observe list and the client will receive the information of a resource without sending GET messages continuously.

Proposed algorithms for automation of the greenhouse
The proposed algorithms to control the environmental conditions in the greenhouse are presented in this subsection. As it was mentioned above, the algorithm is applied in the controller. The controller gathers the data form the nodes with sensors and each time that the controller receives a new value it applies the algorithms. According to the gathered data and the pre-set threshold values, the controller evaluates the need of activating one or more actuators in order to modify the environmental parameters, see Fig. 6, Fig. 7 and Fig. 8. The algorithm to optimize the temperature inside the greenhouse is presented in Fig. 6. This algorithm shows how to adjust the temperature of the greenhouse. Firstly, it needs to know the type of plant grown in the greenhouse to know the temperature threshold. Then, the controller checks the current temperature, according to the data from temperature sensors, with the temperature threshold. Thus, the controller checks if the greenhouse is too hot or too cold for the plants and evaluates the need for turning on/off the actuators. If the greenhouse is too hot, then the controller sends a message to the node that controls the fan to turn it on. On the contrary, if it is too cold, the controller will send a message to the node responsible of the heater. This process is stopped when the temperature of the greenhouse becomes optimal, which means that the current temperature equals the threshold temperature. The process will start again when new data from temperature sensors is received and the received temperature values are above or below the established thresholds.

Start System T i > T threshold No
The procedure to adjust the humidity of the greenhouse can be seen in Fig. 7. Firstly, the controller receives the data from the nodes with humidity sensors. According to the type of plant grown in the greenhouse a moisture threshold is selected. Then, the current humidity value is compared to the humidity threshold. Therefore, it is possible to evaluate if the greenhouse is too wet or too dry. If the greenhouse is too wet, the controller sends a message to the actuator which opens the window. On the contrary, if it is too dry, the controller sends a message to the actuators responsible of turning on the sprinklers to distribute the water. As in the temperature algorithm, this algorithm finishes when the humidity values are the desired ones and starts again when new data with values outside of the thresholds is received. www.macrothink.org/npa Finally, Figure 8 shows the steps to adjust the pH of the greenhouse. Firstly, the data from the pH sensors is gathered and forwarded from the sensor nodes to the controller. The controller selects the threshold value depending on the plant species that are present in the greenhouse. Later, the controller checks the current pH with the pH threshold. Thus, it can determine if the soil is very rich or poor in organic matter. If the soil is very rich, then the pH value should be increased. Thus, the controller, sends a message to the controller that is responsible of controlling the reservoir of organic matter and it opens the reservoir. If the opposite situation is detected and the soil is poor, the pH is decreased by opening the lime reservoir with the actuator node. The algorithm stops as in the previous cases when the data of pH is between the thresholds and starts when it is not.

Results and discussion
In this section, the results are presented. We show the changes in the environmental parameters inside the greenhouse when we implement the WSN and apply the aforementioned algorithms. www.macrothink.org/npa the southwest of Algeria. The plants grown in this greenhouse were tomato plants. We focused on the control and management of temperature and humidity. Figure 9 shows the measures of the temperature for the morning during several hours. In [19], the threshold temperature for a tomato greenhouse in the morning is between 20 and 25 ° C. So that, after the application of our algorithm, all measured temperatures became between 20 and 25 °C as shown in Table 1 and Figure 9.
The temperature measured in all hours exceeds 25 ° C. So, we remark that the actuators which is turned on by the controller is the fan. It runs all the time and the heater does not work because this area is very hot for most of the year.   Figure 10 shows the measures of the temperature for the night during several hours. In [19], the threshold temperature for a tomato greenhouse in the night is between 13 and 17 ° C. Therefore, after the application of our algorithm, all measured temperatures became between 13 and 17 ° C as shown in Table 2 and Figure 10.
The temperature measured in all hours exceeds 17 ° C. Thus, we remark that the fan runs all the time and the heater does not work because this area is very hot even during the night throughout the year.  humidity for a tomato greenhouse was 75%. So that, after the application of our algorithm, all measured humidity is nearly or equal to 75% as shown in Table 3 and Figure 11.
The humidity measured in all hours were less than 75%. Consequently, we remark that with the data gathered by the sensors, and the set thresholds, the controlled activates the sprinkler during all the time to increase the humidity levels in the greenhouse. The window does not open by the controller because the humidity levels measured by the sensors never exceeds the threshold, the area has a dry climate. Figure 11. Management and control of the humidity Table.3. Measured humidity before and after their controls Time Before After -The proposed system is very easy to deploy. The sensor networks with the sensor nodes and actuator nodes with the wireless controller to centralize the information are easy to deploy and configure. -The proposed system facilitates the management and monitoring of greenhouses in a purely automatic way without the intervention of the farmer, with permanent control of the internal climate of the greenhouse. -The system is modular and flexible. If we change the plant species, we only will need to adjust the established thresholds. In case we need to include more sensors and actuators, the controller can be reconfigured to include the new actuators and how to communicate with them. If it is needed, it will be possible to include other parameters including the sensors, actuators, and programming a new algorithm. -The design of the system is robust and reliable, our proposed algorithms runs very well.

Conclusion
In this paper, we have proposed new a design and algorithms for the control and management of greenhouses based on WSN. The algorithms that have been proposed are based on the tests of the parameters measured by the different sensors in real time. The algorithm compares the gathered data with given thresholds. We have considered three environmental parameters (temperature, humidity, and pH of soil). The proposed solution is very promising and very important for the future of agriculture in southern Algeria as demonstrated by the obtained results. These results show that the conditions of the environment in the greenhouse were able to be modified so as to match the optimal values of temperature and humidity.
In terms of perspective, in our future work, we hope to validate our algorithms with real data, to check if our algorithms control the greenhouse's internal climate. We also plan to add other parameters such as air quality as in [21] and consider other types of farming such as hydroponic farming as in [22]. Finally, for the system to be controlled remotely our future investigations will be on the development of the LoRaPAN communication.