55
Bachelor Thesis HALMSD UNIVERSITY Bachelor Programme in Computer Engineer Smart Greenhouse Computer engineer, 15 credits Halmstad 2020-06-12 Filip Joneus, Andreas Ellingsen

f1440106/... · 2020. 6. 16. · Willab Garden previously collaborated with a company from Italy regarding the development of a similar product. However, this was not carried out

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

  • Bachelor Thesis

    HALMSTAD

    UNIVERSITY

    Bachelor Programme in Computer Engineer

    Smart Greenhouse

    Computer engineer, 15 credits

    Halmstad 2020-06-12

    Filip Joneus, Andreas Ellingsen

  • Halmstad University

    School of Information Technology

    Smart GreenhouseSystem architecture for remote monitoring and control

    Authors:Joneus, FilipEllingsen, Andreas

    Supervisor:Ourique de Morais, Wagner

    Degree thesis submitted for the degree of

    B.Sc. Computer Engineering

    June 12, 2020

  • Abstract

    Although automated greenhouse systems are widely used in industrial horticulture, the availabilityof similar, but simpler and affordable systems for residential greenhouses is low. The purpose ofthis project is, therefore, to design and develop a smart greenhouse system that supports stand-alone and remote monitoring and control of residential greenhouses. More specifically, this thesisfocused on the design and implementation of the user interface and communication model ofa smart greenhouse system. This project proposes a system architecture that can be used forconverting a regular greenhouse into a smart greenhouse. The purpose of this is to enable usersto monitor and control vital crop factors based on their needs. The resulting system is a user-friendly mobile application, a cloud-based storage service, and a responsive greenhouse system.Further development could focus on user experience and publish/subscribe distribution to achievelow power consumption.

  • Abstrakt

    Automatiska växthussystem används i stor utsträckning inom industriell trädg̊ardsodling mentillgängligheten för liknande, enklare och prisvärda system för bostadshus är l̊ag. Syftet meddetta projekt är därför att designa och utveckla ett smart växthussystem som stödjer monitoreringoch kontroll av mindre privata växthus. Denna avhandling fokuserar specifikt p̊a design och im-plementering av ett användargränssnitt och en kommunikationsmodell för ett smart växthussys-tem. Detta projekt föresl̊ar en systemarkitektur som kan användas för att konvertera ett vanligtväxthus till ett smart växthus. Syftet med detta är att göra det möjligt för användare att över-vaka och kontrollera viktiga grödofaktorer baserat p̊a deras behov. Det resulterande systemet ären användarvänlig mobilapplikation, en molnbaserad lagringstjänst och ett responsivt växthussys-tem. En vidareutveckling av systemet kan fokusera p̊a användarvänlighet och publish/subscribedistribution för att uppn̊a l̊ag energiförbrukning.

  • Acknowledgements

    The authors of the project would like to especially thank Thomas Lithén from Halmstad University.He has provided the project with a lot of hardware and help for testing. Further Nicolina Månssonat Halmstad University deserves a big thanks for helping finding an ”office” for the group, andalso especially thanks to our supervisor Wagner Ourique de Morais for feedback during the projectand thesis. We would also like to thank Willab Garden for supporting the project with funding,equipment, and their knowledge in culture.

  • List of Figures

    1.1 System functional design from a user perspective. . . . . . . . . . . . . . . . . . . . 2

    2.1 Google Nest Hub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 System architecture, Iot based smart agricul-ture . . . . . . . . . . . . . . . . . . . 72.3 System architecture, IoT Based Smart Agriculture System . . . . . . . . . . . . . . 72.4 Proposed system architecture, WSN article . . . . . . . . . . . . . . . . . . . . . . 82.5 Sensor data processing sequence diagram . . . . . . . . . . . . . . . . . . . . . . . . 92.6 System design architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.7 UART module communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.8 Transmission of eight bits data package with optional parity bit . . . . . . . . . . . 13

    3.1 Proposed and chosen system architecture . . . . . . . . . . . . . . . . . . . . . . . 16

    4.1 LAMP stack overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.2 SAM3X8E baud rate equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.3 Oscilloscope UART monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.4 Mobile application flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.5 Live monitor view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.6 Control view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.7 Statistics view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.8 Hardware sequence diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    5.1 Application start page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.2 Live monitor page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265.3 Control mode & Autonomous mode . . . . . . . . . . . . . . . . . . . . . . . . . . 265.4 Control mode & Autonomous mode . . . . . . . . . . . . . . . . . . . . . . . . . . 275.5 Responsiveness calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.6 System responsiveness w. fiber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.7 System responsiveness w. 4G mobile hotspot . . . . . . . . . . . . . . . . . . . . . 285.8 Individual component price list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.9 Full system integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.10 System communication sequence diagram . . . . . . . . . . . . . . . . . . . . . . . 30

  • Contents

    1 Introduction 11.1 Purpose & Goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Delimitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.5 Report Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2 Background 52.1 Literature Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    2.1.1 Home automation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.2 Automated greenhouses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.1.3 Industry automation in greenhouses . . . . . . . . . . . . . . . . . . . . . . 8

    2.2 System Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2.1 System architecture analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    2.3 Internet Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.3.1 Internet connectivity analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    2.4 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.4.1 User interface analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    2.5 Communication Protocol & Web Server . . . . . . . . . . . . . . . . . . . . . . . . 112.6 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    2.6.1 UART Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    3 Method 153.1 Choice Of Platforms And System Architecture . . . . . . . . . . . . . . . . . . . . 15

    3.1.1 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.1.2 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.1.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    3.2 Measuring The Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    4 Implementation 194.1 Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    4.1.1 PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.1.2 MySql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    4.2 Internet Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.2.1 Internet connectivity implementation . . . . . . . . . . . . . . . . . . . . . . 21

    4.3 Mobile Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3.1 Live Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3.2 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.3.3 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.3.4 Web store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.3.5 Microprocessor sequence diagram . . . . . . . . . . . . . . . . . . . . . . . . 24

    5 Result 255.1 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    5.1.1 Live monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265.1.2 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265.1.3 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

  • 5.2 System Responsiveness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.3 Costs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    5.3.1 Hardware components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.3.2 Server- & Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    5.4 Full System Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.4.1 Full system sequence diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 30

    6 Discussion 316.1 Project discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316.2 Further Development And Research . . . . . . . . . . . . . . . . . . . . . . . . . . 326.3 Social Aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    6.3.1 Integrity & security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326.3.2 Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326.3.3 Economy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    7 Conclusion 35

    Bibliography 38

    A Appendix 39A.1 UART configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

  • Chapter 1

    Introduction

    Systems for automated greenhouses that monitor and act upon parameters such as humidity,temperature and crop nutrients are widely developed for large-scale horticulture industries[1][2].However, such systems are built upon advanced PLC industrial components with the implemen-tation of, for instance, SCADA-systems[1][3]. Thus, such systems may not necessarily be suitablefor hobby gardeners.

    Considering the limited availability of simple, affordable, and user-friendly systems for small-scalegreenhouse gardening, the authors of this project contacted one of the largest greenhouse produc-ers in Sweden, Willab Garden. Willab Garden previously collaborated with a company from Italyregarding the development of a similar product. However, this was not carried out because of theexpenses and the interest in the market was lower than today. Willab Garden have recently seen agrowing interest in the market for these types of products and think that this project could becomea good start of a selling end product.

    The idea of a smart greenhouse that could monitor and control vital parts for plants was presentedand the interest of such system was established. Successfully, an agreement to accomplish theproject in collaboration with Willab Garden was made, where they are funding the project with abudget of 10.000 SEK.

    1.1 Purpose & Goal

    The purpose of the project is to develop a prototype that would enable hobbyist gardeners toremotely monitor and control different parameters in their greenhouses. Effectively convert a tra-ditional greenhouse to a smart greenhouse (SGH).

    The main question of this thesis is to propose a system architecture and implement a proto-type of such system.

    The goals of the project are:

    • Investigate how existing smart or automated greenhouses have been developed from a soft-ware and hardware architecture point of view.

    • Design a system architecture for a SGH that can accommodate the technical and operationalrequirements.

    • Develop a prototype for a SGH that enables to send sensor values and retrieve commands toactuate on in the greenhouse.

    • Develop a prototype for a mobile application for remote monitoring and control.

    To keep the greenhouse pleasurable for potential customers, the system must be adequately inte-grated from an aesthetical point of view. Regardless of previous technical background on potentialcustomers, it’s crucial that the system is sufficiently easy to use whilst maintaining a high degree

    1

  • of reliability. By optimizing the environment for plants this project also aims to extend seasonsfor different types of crops. Achieving higher and faster yield for plants should also be possible[4].

    1.2 System Overview

    The overall functional design is to convert a greenhouse to an IoT product where the user canmonitor and control selected variables based on their needs and crops from a remote location.Figure 1.1 describes how the system should work from a user perspective.

    Figure 1.1: System functional design from a user perspective.

    1.3 Delimitations

    Decisions will be made towards the Swedish market and recommendations from Willab Garden aretaken into account. This project is separated into two parts. This thesis is one part of the projectand is focusing on the following areas:

    • System architecture and design.

    • Internet communication.

    • User Interface.

    The other part of the project consists of two mechatronic’s engineer students that are focusing athardware and sensors that will monitor and control the greenhouse[5].

    This project is limited in the following parts:

    • Use of existing microcontroller developer boards.

    • The application prototype is intended for android-based devices.

    • Develop a prototype where most of the parts can be reused if further developed.

    • Internet connectivity is assumed available in a close range of the greenhouse.

    • The report will not go in-depth about data storage and web server design.

    2

  • 1.4 Requirements

    The requirements for the project are divided into two parts, system design and system function-ality. Requirements have been worked out with Willab Garden but also with consideration of theorigin project idea from the author’s. The requirements are stated below.

    System design has the following requirements:

    • An embedded systems mounted in the greenhouse as one unit that holds all sensors andactuators.

    • The user shall be able to communicate remotely with the system.

    • Using a mobile phone as a user interface.

    System functionality has the following requirements:

    • Monitoring of:

    – Temperature

    – Air humidity

    – Soil humidity

    – Wind speed

    • Controlling of:

    – Temperature.

    – Soil humidity.

    – Light.

    1.5 Report Overview

    The report is divided into eight chapters. The second chapter Background describes related workand architecture for these types of systems used today in both the industry and the private sector.Analyses goes in-depth and listing possible architectures and solutions according to the literaturereview. The third chapter ?? describes theories, useful in the project. In the fourth chapterMethod a clear project specification is made and how the implementation will be structured.Here a motivation of platforms and hardware components used during the implementation canbe found. Under the chapter Implementation all different parts of the implementation aredivided up for a more detailed explanation. In the Result chapter the obtained results are shownand under chapter Discussion the author’s share some of their thoughts regarding the project,proposed further development and information about environmental and ethical impacts. The lastchapter Conclusion is a short conclusion is provided that summarizes this project.

    3

  • 4

  • Chapter 2

    Background

    This project started under the fall of 2019 while the authors started to investigate what’s on themarket in the area of automated greenhouses. By visiting local companies such as Tönnersjö Trädg̊ardand Willab Garden, it was clear that automated greenhouses were widely developed for use ofindustry[3], but from a hobbies point of view, something was missing in the market. Tönnersjö Trädg̊ardmeant that these types of systems are crucial in the industry and companies not investing will havegreater challenges in the future and not be competitive in the industry. This was also confirmedby the collaborators of the project Willab Garden where they pointed out that they have beenlooking into this case before. At that time, the market interest was not as high as today and costsfor the end customer was reasons for Willab Garden to not take the project into a final product.

    Since the project includes many areas such as system architecture design, hardware development,user interface development, the project is divided into two different parts and groups. This part,the Computer Engineering part aims to focus on communication, data storage, server and userinterface development. The other part, Mechatronic Engineering are focusing on the hardwareand hardware-related software against sensors and actuators.

    2.1 Literature Review

    2.1.1 Home automation

    Home automation systems started to increase in popularity in the early 2000s and is today an wellestablished market expected to be wort around 114 billion dollars by the year of 2025 [6]. Homeautomation systems control and monitor functions inside or outside the home without a personintervening. These systems often monitor parameters such as energy consumption and can, forinstance, unlock doors via applications. The number of areas where home automation is appliedincreases each year[7] and some of the more developed areas in home automation are lighting, heat-ing, and security. Such devices are often cloud-connected, making them accessible from anywhere.

    In the article Mobile based home automation using Internet of Things (IoT)[8] a home automa-tion system is developed using an Arduino with Ethernet connection. Here, the microcontrolleris acting as a server where the user can send requests via an IP-address to turn on one of theappliances (simulated by LEDs). In the article Internet of Things: Ubiquitous Home Control andMonitoring System using Android based Smart Phone[9] an android application is used to controlan Arduino via internet. The JavaScript Object Notation (JSON) is used to send data inbetweenthe microcontroller and mobile application. Similarly to the implementation in the article Mobilebased home automation using Internet of Things (IoT)[8] an Ethernet shield is used with the Ar-duino microcontroller. The overall architecture with a mobile application, JSON and HypertextTransfer Protocol (HTTP) protocols is often used and can almost be seen as one of the standardsfor IoT today.

    There are also open-source platforms such as Home Assistant where users can implement dif-ferent types of automation based on their needs. Home Assistant[10] is an open-source softwareplatform that not only includes integration with other products but also a mobile application that

    5

  • can be modified to the user’s needs. The platform also gives predefined logic and code to set upthe system not only for monitoring and controlling but also for automation. Home Assistant ismodular and the user or developer can add sensors and actuators based on their needs. The codefor controlling the selected hardware can then be provided to the platform.

    Some of the world’s leading tech companies such as Google, Samsung and Apple have also developedtheir own products, Google Nest Hub, Samsung SmartThings and Apple Homekit. Google NestHub is a device for controlling any other devices compatible with the application Google Assistant.That enables companies and developers to build an automated system in a specific area where usersthen collect products from different companies to build their system. Google Assistant then worksas a bridge to control any home automation system. Google Nest Hub has over 5000 compatibleproducts from over 400 companies that connect through WiFi and Bluetooth[11]. Philips Hue is anexample of a stand-alone home automation light system that is compatible with Google Assistant.A big advantage of such a system is the scalability of adding products. Figure 2.1 is an overview ofhow the system could work when Philips Hue (light), Google Chrome (TV) and Id Lock (door lock) isconnected.

    Figure 2.1: Google Nest Hub

    Apple Homekit for home automation and re-mote control works in a similar way as theGoogle Nest Hub, where the central unit isan iPad or Apple TV accessed via apple id. Aphone or apple watch with the same apple idcan then remote control actuators and mon-itor sensor data. Actuators and sensors areadded and named to the system via a uniquecode. The user is then adding various lev-els of automation to each actuator or controlthem manually. Companies and developersare given the opportunity to develop prod-ucts, where Apple if requirements are fullfilled, accepts the product to ”Apple Home-kit Certified” and products are then avail-able for adding into Apple Homekit. Most ofthe products in the area of smart automatedhomes are developed using WiFi as commu-nication standard, both for internet connec-tion and communication inside the systembetween hardware modules. These systems

    are built on the requirement of WiFi access in every room where to put a sensor or actuator.

    2.1.2 Automated greenhouses

    In order to provide a solution that will accomplish the projects goal, research on the subjectis presented here. One example is where they used a Raspberry Pi as a controller unit. It isdescribed in the article Iot based smart agriculture[12], written in India where one-third of thenation’s capital comes from farming. The system developed in the report controls humidity, light,water, motors, heating, motion detection and was build on a three nodes architecture. The firstnode communicates with a PC or mobile application and distributes data. Node two controls theactuators and collects data from sensors and the third node is a sensor or actuator passing datato node two. Their proposed system architecture is shown in figure 2.2.

    6

  • Figure 2.2: System architecture, Iot based smart agricul-ture

    The conclusion of the report is that all three nodes are successfully integrating with each otherand that such system definitely helps to improve the yield of crops. One drawback of this systemis the degree of embedded hardware needed in the greenhouse. Having both a microcontrollerand a raspberry pi could give unnecessary computational resources. A similar implementation isdescribed in ”IOT Based Smart Agriculture System”[13] where an Arduino board and an externWiFi module is used as a slave to the cloud computing algorithm. The report describes how cloudcomputing is used and implemented for making decisions depending on input from both the userand the greenhouse. Users communicate via an android application for setting up conditions andturn on and of actuators depending the current environment. The system works as a guard andsends alarm notifications to the user for the thresholds made up by the user. One of the limitationsin this system architecture according to the authors is the strong dependency on internet accesswhere they are solving it with an additional GSM module for SMS alarming. An overview of thesystem is presented in figure 2.3.

    Figure 2.3: System architecture, IoT Based Smart Agriculture System

    Different communication models and technologies can be employed to connect distributed systems,such as one composed by a mobile application and a node equipped with a microcontroller. Inthe article GSM based Automatic Irrigation Control System for Efficient Use of Resources andCrop Planning by Using an Android Mobile[14], a system where an android mobile applicationcommunicates through a GSM module and Universal Asynchronous Receiver Transmitter (UART)is described. The system can both monitor moisture and temperature and also control the waterlevel. Messages are passed to the user over SMS where the end-user can then respond dependingon the given information. They are pointing out the possibility of solar cells as an alternativepower source for higher reliability.

    7

  • In the report Automated Control System for Arduino and Android Based Intelligent Greenhouse[15]only a microcontroller is used as a controller unit. The systems is built around an Arduino thatcommunicates with an Android application via Ethernet. Light, heater, cooler and water pump arethe four actuators enabled to be controlled in the system. While temperature, light and humiditycan be monitored. The architecture does not include any storage for data, but instead only reactsupon input from the mobile application. A drawback of the system is the implementation whichimplies only one measurement or instruction can be done at a time. Another part where thissystem also can have an issue in the future is missing data storage, something that is becomingmore and more important. Conclusions are made that the system is reliable, works well for homeautomated greenhouses and is of low price.

    2.1.3 Industry automation in greenhouses

    As mention in the article[1][3] for the industry advanced PLC systems is usual to handle largeheating sources, compressors for watering and nutrition. When the authors of this report visitedTönnersjö Trädg̊ardar the system was described in detail both in terms of functionality and invest-ments. The control system used at Tönnersjö Trädg̊ard comes from a company called Senmantic[3],focusing on industrial scale greenhouse automation. In the industry of horticulture it is commonthat the daily activities are divided into several smaller greenhouses instead of a large one. Thesesystems are designed to scale where each small greenhouse is seen as a module. A starting costfor the Senmatic system including pellets burner (heat source), compressors for water distribu-tion and water nutrition is in range of 1.000.000 to 2.000.000 SEK. In the article Study on theContext-Aware Middleware for Ubiquitous Greenhouses Using Wireless Sensor Networks[16] theauthors describes different types of wireless sensor networks (WSN) and how they could be used tocreate a SGH. The article describes different types of WSN technologies and proposes the followingsystem architecture.

    Figure 2.4: Proposed system architecture, WSN article

    The proposed system in figure 2.4 is similar to the Senmatic system. In their implementation theyalso present a sequence diagrams that explain how the communication in the system is working.The result from the report is that the proposed architecture gives a response time in 0.47 secondsusing a local network. The use of wireless sensors also provides scalability and an easy system toinstall. Figure 2.5 shows how the sensor data is processed. The application part is the graphicaluser interface (GUI) which is locally installed where the user can monitor sensor data. The datais accessed by queering the database.

    8

  • Figure 2.5: Sensor data processing sequence diagram

    2.2 System Architectures

    In the following sections, possible solutions and analyses are presented according to the literaturereview 2.1. The architecture is divided into four parts consisting of system architecture, internetconnectivity, user interface and communication protocol. An analysis is provided for each solutionwith aspects of the literature review 2.1, the project goals 1.1 and Willab Garden recommendations.

    After analyzing the literature review 2.1, there are three main possible solutions to a system ar-chitecture for such prototype. Figure 2.6 describes the three main possible solutions for this type ofsystem.

    Figure 2.6: System design architectures

    Figure 2.6.A is a cloud-based architecture. Cloud-based implementation enables the use of powerful com-putational resources, implementation of artificial intel-ligence (AI) and future technologies. Depending onthe implementation the hardware can also be rented orhosted. There is no need for a processor with largecomputational power since everything is moved to thecloud.

    In figure 2.6.B shows a system where everything isbuilt locally. There is a microcontroller that con-trols all actuators and sensors but also a Rasp-berry Pi that has a server for data storage andcommunication. The data would also be storedlocally. The minicomputer is then connected tothe internet and the user can access and communi-cate with the system. This system gives a fullyfunctional Linux operating system and two dedi-cated processors for controlling the SGH. This sys-tem can however be scaled down to only use a mini-computer without the use of its dedicated microcon-troller.

    Last figure 2.6.C shows an architecture where using amicrocontroller as a computational resource and to com-municate with the sensors and actuators. Then make useof the cloud as a database, server and also work as a mid-dle hand to communicate between user and greenhouse.Here a local server can also be built directly at the mi-crocontroller which effectively gives similar possibilitiesthat with a mini-computer. Having a local server at themicrocontroller would also enable direct communication with the SGH.

    9

  • Regardless of architecture design, each one of them needs to be able to both control actuatorsbut also receive data from sensors. The hardware needs to have possibilities to handle pulse withmodulation (PWM), analog-to-digital converter (ADC) and digital input signals. More on thistopic can be found in the Mechatronic Engineering part report[5].

    2.2.1 System architecture analysis

    Regarding the selection of system architecture, evaluations of advantages with disadvantages ofeach solution are done to fit the project goals. A system including a mini computer and microcon-troller where the SGH itself stands for server and database locally is seen as a drawback, especiallysince hosting own hardware not seems to be the future[17]. In a final product such system caneasily be seen as overqualified, power-consuming and there is a lot of actual hardware integrationinto the SGH. This setup also gives an expensive computational power that is not needed and noteasy scalable for custom circuit boards.

    There is also an opportunity of not using the microcontroller only using a Raspberry Pi. Us-ing only a mini-computer such as Raspberry Pi has many advantages especially the benefits ofhaving an operating system. With an operating system calling I/O ports different language op-portunities would speed up the developing process. Missing analog I/O ports is the big drawbackin such solution in combination with again the hosting of data and power consumption. Addingextended analog input/output (I/O) ports is possible but requires additional hardware. The pos-sibility here is also to use the cloud for data storage, but then a mini-computer is overqualified andan unused computational resource.

    Since people’s greenhouses often are adjacent to the house but the distance varies greatly, soalso the internet connectivity. Using an architecture with only a IoT gateway and cloud com-puting requires a lot of data transferring, which can easily exclude regions, areas and customersfrom such solutions. Even thus such solution comes with many benefits, such as minimal actualhardware to integrate, low production costs and all resources in one place. In a small perspectivewhere WiFi and bandwidth are seen as unlimited, such solution is to prefer. Switching to a widerperspective thinking of those who do not have unlimited bandwidth, transferring massive amountsof data seems like a bad idea. There is also the aspect of strong internet dependent, where thesystem stops working if the internet connection is lost.

    Using a microcontroller as a computational resource inside the greenhouse, and cloud base webserver and database provides many benefits. Not least the system still works if the connection islost and it also enables implementation of an energy-efficient system with relatively little hardwareto integrate into the greenhouse. This makes the system more reliable and robust compared toif internet connectivity is necessary for the system to work. Data can be stored in the cloud forhistorical views that can be accessed by the mobile application. It also has no real disadvantagesassociated with hardware in and outputs. An implementation of such system may require longerdevelopment time, but are also closest to a custom made product for the wide market where priceand performance must be meet.

    Regarding the embedded control system this project aims to be able to reuse it’s componentsif the prototype turns out well, programming in Arduino IDE is not preferable. This is due tothe Arduino IDE does not have debugging features and is not build around fully custom softwaredevelopment. Having a microprocessor and IDE where code in C/C++ can be written is probablya better choice both for scalability and towards a final product with custom made circuit boards.

    2.3 Internet Connectivity

    Connecting the embedded control system to the internet gives four different opportunities. Themost used techniques for private use at villas are WiFi, 4G, Ethernet and power-line communica-tion (PLC) also known as homeplug.

    4G connectivity is in Sweden widely accessible, over 99.9% of the population has 4g access [18][19].

    10

  • PLC is a technology that enables data transfer trough existing power cables. It works with bothdirect current(DC) and alternative current(AC), on different voltages levels. PLC solution re-lated to home automation systems has been researched before, and as stated in the article Designof Smart Home System Based on Power Line Communication Technology and Wireless SensorNetworks[20], that PLC will put new home automation ideas on the table.

    2.3.1 Internet connectivity analysis

    Having a 4G solutions that require the end-user to have some extra payment service will be avoided.The main reason for this is to create a prototype as close to a possible final product. Having extraservices the end-user needs to add to the system is not adding any additional value to the product.

    From the interviews and meeting the author’s have had with Willab Garden, they pointed outthat there are almost no users that have Ethernet cable drawn to their greenhouse. Since Ethernetis not commonly available in greenhouses this is not an option itself but can be added as an option.A problem regarding PLC is that Sweden’s power grid provides three phases not only in the trans-portation of electricity but also into the villas. These three phases are later divided among differentfuses that are used for different parts of the house. The problem with PLC solutions is that it willwork differently depending on how the phases and connections are divided in the house. There areproducts available that can connect two or more phases that allow PLC to work between them butthis has to be installed by an electrician.

    WiFi allows for multiple solutions. If the users have Ethernet or power line the user could add aWiFi connector and the system could connect to the WiFi signal. The majority of Sweden’s villaowner has internet through fiber cable and WiFi is standard to use[21]. The system could thendirectly connect to the existing WiFi signal. In the case of to week or none signal strength at thegreenhouse location, a WiFi range extender could be used. There will still be problems in the casewhere the greenhouse is too far away from the closes available range extender access point in thehouse. A separate 4G module could then be placed within range.

    Willab Gardens recommendations is to provide both WiFi and Ethernet.

    2.4 User Interface

    To enable the user to interact with their SGH via a mobile phone remotely gives two choices,a mobile application or a website. Using a web page that is mobile scale adapted and can beaccessed from any web browser. The other option is to develop a mobile-based application as theuser interface. Using SMS can also be used as an additional backup or feature like the authorsdone in the report IoT Based Smart Agriculture System[13].

    2.4.1 User interface analysis

    The recommendation from Willab Garden is to develop a native mobile application. This optionalso gives a lot more options and can provide a better user interface hence experience compared toa web page. According to the literature review, chapter 2.1 SMS can function as an alarm system,but not as the only communication channel. With a mobile application, future development ofa notification system is possible and this is considered a big advantage compared to a web pagesolution.

    2.5 Communication Protocol & Web Server

    Since there is a need for a storage service that can collect data, some server is needed. Storingdata is needed for two main reasons:

    • Historical data views for the user.

    • Analyse of data for future improvement and adjustment.

    11

  • The market has and is still shifting towards renting space for cloud computing and less investingand hosting its own hardware [17]. The meaning of cloud computing is a remote place where theserver is located and connected to the internet. There is then no need for the company to investin hardware and maintaining it. Willab Garden does not have this knowledge from before andinvesting in own hardware is not if their interest.

    Depending on what system architecture chosen, some data storage in the cloud could also actas a communication channel to exchange data between the user and the system[13]. A commonlyused technique for web pages is to use some middle service also known as distributed systems.These services are acting as a server holding data storage services and provides a solution for usersand systems to exchange information and not send data directly between endpoints. Represen-tational State Transfer (REST) is a big part of today’s internet and enables for example a userto request data from a web server through some application where the data can be stored or aresponse be returned. Another system at the other end can connect to the same REST service andretrieve data that it needs, and it could for example include instructions from the user.

    Another design choice that has to be made is where to place the webserver for communicationbetween the user and the control system. As in the report Iot based smart agriculture[12] theyplaced it locally in the system and in ”IOT Based Smart Agriculture System”[13] the server isplaced remotely in the cloud equally with good results.

    When selection architecture and web server with database access two main communication pro-tocols may be used in this kind of system. One traditional web server that allows for HTTP(S)requests and with some backend language like PHP, is the most commonly used today. HTTPis the standard used for long. The first well-documented version 0.9 is from 1991 and the latestversion 2.0 and 3.0 is powering almost the hole internet today. There is a lot of documentationand support since it is so widely used.

    The more advanced technology named MQTT allows for a publish-subscribe solution. MQTThas two main benefits that in general IoT development and mobile application can take advantageof. First is that data transferred over the internet is more lightweight since it is transferred asbyte arrays instead of text. This reduces power consumption. Studies also show that MQTT is upto six times faster than HTTP when transferring data from a sensor to a MySql database[22][23].Another very useful tool that MQTT provides is the use of publish-subscribe models[24]. Thesystem can be set up in such a way that polling data can be avoided and different parts of thesystem can subscribe and get notified when something has changed.

    2.6 Theory

    2.6.1 UART Theory

    UART is a computer hardware module that enables converting of parallel data to serial. Insteadof using a clock, it is operating on start and stop bits to detect when to read incoming bits. Itenables the possibility for modules to communicate in bits over two wires, one for transmitting(TX) and one for receiving (RX).

    Figure 2.7: UART module communication

    The measurement of bit frequency is called baud rate and has to be configured to the same onboth modules for correctness of data. To decide and calculate the baud rate the developer needs

    12

  • to take the processor clock speed into account that will be used for the TX and RX pins. OftenTX and RX pins run at some factor lower than the master clock (MCK).

    For each byte transmission modern UART modules have the option from five to nine data bitssize. A parity bit can be added to the end of each data package for error detection, the bit tellsthe receiver if the number of bits is odd or even. After the stop bit is received the receiver convertsthe high and low bits to a binary number corresponding to a character in ASCII format.

    The principles of one-byte transmission are as follows:

    1. TX wire stays high while not transmitting.

    2. TX is pulled low for one cycle to start transmission.

    3. Predefined number of data bits is sent.

    4. Parity bit is sent after the data (optional).

    5. Stop bit is sent.

    Figure 2.8: Transmission of eight bits data package with optional parity bit

    13

  • 14

  • Chapter 3

    Method

    Since the project uses different methodologies, tools, languages and techniques they are describedindividually bellow. By using different types of cloud-based communication platforms such asGitHub, Slack and Google Drive to share information, the authors hoping to achieve a pleasantdevelopment process. The project is following the Lips project model[25] developed by TomasSvensson and Christian Krysander, to facilitating projects, especially in teaching environments.Lips project model consists of three phases a before, during and after phase, all three are describedbelow.

    • Before: The before phase is where the authors of the report are collecting information onthe subject. Writing project plan, reading related work and project specification are done inthis phase.

    • During: Choose and implement hard- and software, writing code and testing of ideas fromthe before phase. Testing and verification of implementations are taking place at the end ofthis phase.

    • After: This is the phase where analyzing of results are taking place. Conclusion, results andcomplete project reports are ending the project.

    3.1 Choice Of Platforms And System Architecture

    This section is aiming to describe the choices done in the project for implementation. Since theproject consists of different parts such as system architecture, hardware and software they aredivided into own sections described below.

    3.1.1 Architecture

    According to the architecture chapter 2.2, opportunities for architecture are many and different.Picking the pieces out of the cake and customize an architecture aiming to fit this project are donewith aspects on a future Swedish market. To reduce dependency on internet and increases thereliability most of the logic is put on a microcontroller. The microcontroller then communicateswith sensors and actuators via its I/O pins. Then to be able to reach the microcontroller remotely,it is extended with a WiFi module. Web server and storage is outsourced and put into the cloudboth to avoid extra hardware and the functionality of existing web servers supplies. The server isalso working as a middle hand in between user and greenhouse. By posting a request to the webserver the user can both put instructions and retrieve data. HTTP will be used with a LAMPstack placed in the cloud. Developing of an Android mobile application are taking place to fulfilla full-scale system prototype.

    15

  • Figure 3.1 is an overview of the chosen system architecture and its components.

    Figure 3.1: Proposed and chosen system architecture

    3.1.2 Hardware

    According to the related work 3.1.1 there is need for a microcontroller and WiFi module. Thechosen microcontroller is an ARM-based Atmel SAM3X8E that sits on a developer board namedArduino Due. There are microcontroller boards that have build-in WiFi modules but the chosenboard is well known by the author’s and the limitation in time for the project made this choice toensure that implementation will be possible. There are few WiFi modules at the market today thatare small and provide a basic application programmer interface (API) build in to make transmissioncontrol protocol (TCP) or user datagram protocol (UDP) connections. The WiFi module ESP8266is successfully implemented in a similar system[26] and is therefore also selected in this prototype.It has a small processor, low cost and a build-in API with AT commands[27] that can be usedwithout further configurations. Both modules also operate on the same voltage level, and theWiFi module can be configured to act as both access point and station mode. Another feature forfurther development are the deep sleep functionalities both modules includes, necessary for an endproduct. More regarding the selection av hardware components can be found in the MechatronicEngineering parts report[5].

    • Atmel SAM3X8E & Arduino Due boardThe Arduino Due board consists of 54 digital I/O pins where twelve of them can be usedas PWM outputs. It also consists of twelve analog inputs with ADC built-in. It has fourdedicated ports for serial UART communication and can run with clock speed up to 84 Mhz.The microprocessor placed at the board is a 32-bit ARM Cortex-M3 from Atmel. It has abuilt-in flash of 512K bytes and a nested vector interrupt controller configurable for interruptson certain pins. This processor holds all the functionalities needed for the SGH.

    • ESP8266The ESP8266 is a stand-alone WiFi module from the China-based company SparkFun Elec-tronics. It has a built-in microcontroller and a printed circuit board (PCB) WiFi antenna.Except pins for ground and power, it has two dedicated pins for serial UART communica-tion, two general-purpose input-output (GPIO) pins, one reset pin and one enable pin. TheESP8266 version -01 comes with 4Mb flash memory, flashed with AT command[27] software.The AT command version is 1.3.0.0.

    • Segger j-linkFor real-time hardware debugging software a Segger j-link is used, hoping to speed up thedeveloping process. The chosen developer board (Arduino Due) has support for connectionvia a JTAG interface which is the same interface as the Segger j-link. The j-linker is alsohardware that can be borrowed from the university.

    16

  • 3.1.3 Software

    Some parts of the software have been chosen based on the related work while other parts areselected because of the capability of working together with the selected hardware. Parts of thesoftware are only used for testing and validation and speeding up the development process whileothers are a part of the final prototype.

    • SEGGER Embedded StudiosSegger Embedded Studios (SES) is and integrated developer environment (IDE) with themain focus on hardware close programming. It is free of use for non-commercial, supports theselected processor and includes necessary setup files. SES gives two language opportunitiessuch as C and C++ where C is chosen according to previous experience and in consolationwith the Mechatronics Engineering part. SES also works cross platforms between Windows,Linux and OSX.

    • Serial communication monitoringWhile testing the ESP8266 module individually to ensure it performs as expected, a stand-alone serial communication program where used. Both the Linux terminal program Moserialand Arduino IDE were used to monitor serial communication.

    • Android StudiosAs described earlier in the report, developing a mobile application is taking place afterinvestigation according to 2.1 and recommendation from Willab Garden. Android Studios isan IDE developed for developing mobile applications for the Android operating system, whichincludes the feature of having an android virtual device (AVD, virtual mobile device). Javaand Kotlin are the two language opportunities, where Java is selected according to previousexperience.

    • Web Server and DatabaseTo not host own hardware and simulate the market shift towards renting resources in thecloud[17], the webserver will be placed in Google Cloud. The chosen solution will be opensource and a commonly used solution to be able to make the project within the time limi-tation. The system will consist of a general LAMP stack. LAMP stands for Linux, Apache,MySql and PHP. Google Cloud also have full support and a separate service to install aLAMP stack.

    3.2 Measuring The Result

    The result will be measured to confirm whether the project goals have been achieved. The threemost important factors are that the interface is pleasing to use, system reliability and systemresponsiveness over a longer period. The table below describes the way the result will be measured.

    • User InterfaceA user interface is always self-judging in the simplicity of using it. The application willbe built around daily commonly used design and patterns that are well known for dailysmartphone users. This is to ensure a user-friendly layout and design. Since the project incollaboration with Willab Garden aims to create a prototype as close to how a product couldlook like therefore this is one of the most important measurements. A small survey will alsobe done with potential users that have no experience or knowledge from the project to testthis. The survey will be setup in such way that the user shall do some predefined tasks andexecute them with no help. Then score how easy or hard it was. This measurement is doneto see if the goal of developing a mobile application prototype is fulfilled.

    • System ResponsivenessThis system contains both hardware that controls sensors and actuators, hardware for in-ternet communication, web server and mobile application for the end-user. All these partsare connected and the responsiveness will be measured in execution time, which implies thetime it takes to update the greenhouse from the webserver. of the project goals is to proposea system architecture that can accommodate the technical and operational requirements.This will describe how well the proposed architecture and implementation works. But alsomeasure how responsive the system is from a user perspective.

    17

  • • CostThe system will be evaluated in therms of costs. Both the costs of all hardware parts thatthe actual system includes, but also a monthly server-/database costs of having the systemrunning. A limit of 10.000 SEK is set to ensure the system is affordable to the private market.

    • System IntegrationThe project is divided into two parts as described earlier and in the end, the two parts haveto merge and be implemented together to test the full system. All parts will be integratedand tested inside a greenhouse provided by Willab Garden. Measurements and tests will bedone to ensure the system works as indented to satisfy the project goals. The system will alsobe tested during a longer period to ensure it works properly over time. This measurement ischosen to verify that the goal of being able to send sensor values and retrieve commands isworking as intended in the SGH.

    18

  • Chapter 4

    Implementation

    Implementations are divided into each module and described below. For the microprocessor, theAtmel SAM3X/SAM3A data sheet is used as a reference manual.

    4.1 Web Server

    The system stores each sensor data in tables. This enables the user to show historical data viewsbut also to set up future automation algorithms that can be calculated in the cloud but also locallyin the embedded system, both are used in this implementation. This is to allow robustness in thesystem so the system does not rely on internet connectivity to function but can close windows,have some default watering intervals etc. Also since the embedded system is directly connected tothe internet thru a WiFi module, the ESP8266 WiFi module can be set up to be an access pointat the same time so the user could connect to the system to control it locally if needed.Google Cloud (GC) is used as infrastructure for both storage and hosting of computational capacityfor the servers. CG is set up in such a way that it runs a Linux virtual machine that is placed atthe closest CG server from Sweden, currently Finland. The web server is configured as a LAMPstack.

    Figure 4.1: LAMP stack overview

    The web server also serves the purpose of sharing information between the mobile application (theuser) and the SGH. Using a table for holding instruction values such as LED on/of enables this.The only thing that needs to be configured on GC for Apache is to allow for outside incomingconnections over HTTP to get through the GC firewall.

    4.1.1 PHP

    The PHP script is created in such a way that they create URL endpoints for different functions.It is not a full REST API used with all the HTTP methods but a simplified version. Duringdevelopment, the functionalities of the script have been testes on a local setup LAMP stack. Afterverifying the code works as intended it has been moved to GC.

    19

  • To enable the PHP scripts for accessing and querying the database the official MySql connec-tion libraries (mysqli) have been used.

    4.1.2 MySql

    The database serves two purposes in this system which is to store historical data and status flagsof different modes and actuators. Historical data is stored from the embedded system at fixed timeintervals. Actual data that is being stored at fixed time intervals are:

    • Air temperature.

    • Air humidity.

    • Wind speed.

    Each type of data has it’s own table with a unique id and timestamp that is set by the databasewhen created. In this way the system can easily add more sensors and data points that are ofinterest for storing.

    Status flags are used slightly differently than sensor values that are accumulated in tables asdescribed above. The main purpose here is to have some data that describes the current state ofthe greenhouse. The status flags that are stored are:

    • Watering interval. The user can set how often per day the system should water.

    • Watering time. Since the project assumes the user has a water supply in the greenhouse frombefore with pressure a time in seconds is added for how long it should be watering.

    • LED on/off. Holds the state of LED lighting.

    • Roof window. Open or closes the window on a scale from 0-100%.

    • Target temperature.

    • Self Control and Autonomous mode. The user can set the system in self-control mode wherethe user controllers all actuators manually. If switching to autonomous mode the system willhold the target temperature and watering intervals with watering time. It can also hold aspecific moister level. The system then control’s the actuators for watering and roof windowsautomatically.

    When the status flags values are changed, current data points (rows in a table) values are updated.This is to save storage space. Also after discussing what data is important to store for futureuse gardener experts at Willab Garden recommended to start with the basics of temperature andhumidity since this is the two by large important values for optimal yield.

    All data that is being exported (read) from the database and imported (write) is done by storedprocedures. In this way the PHP scripts can be kept at minimal and no SQL statements areneeded to be coded and sent for execution at the database. Multiple user accounts have been setup depending on what rights are needed when modifying the database. The PHP scripts providesa special user account with password to the database server otherwise no connection can be setup.The storage logic is also set up in such way that the SGH can update sensor values often so themobile application can see real-time data. But new sensor values are only stored every 15 minutes.

    20

  • 4.2 Internet Connectivity

    Since the WiFi module includes a flashed version of AT commands and communicates via theUART interface, UART has to be configured on the microprocessor. UART theory is described insection 2.6.1.

    4.2.1 Internet connectivity implementation

    To enable the microprocessor to handle characters sent over UART, some of its dedicated UARTpins have to be configured. This is a feature that is built in the microprocessor and can be ac-tivated by configuring the UART registers. Since the WiFi module has a default baud rate of115200, calculations then have to be done to set the same baud rate on the microprocessor.According to SAM3X8E datasheet, calculations are as follows:

    BaudRate =MCK

    16 ∗ CD

    Figure 4.2: SAM3X8E baud rate equation

    Where CD is a scaling factor and MCK is master clock speed. Both modules are also configuredto use eight-bit data packages with no parity bit. To avoid the microcontroller from polling tocheck for data, it is configured to generate an interrupt for each character that arrives and storesit in a buffer. Since the WiFi module itself has a flashed software from the factory that has ATcommands available and ready to use. This means that the WiFi module can directly be connectedto the selected and configured pins at the circuit board and be used with no more configurations.Then by sending AT commands as a string to the WiFi module, it is forced to execute instructions.Depending on sent AT command, the microprocessor masks out if the WiFi module is done bysearching for the ending line characters “\r\n”.While testing the UART configurations an oscilloscope has been used to analyze voltage levels onthe TX/RX pins. Figure 4.3 shows the microprocessor sending a single character on the TX pin.

    Figure 4.3: Oscilloscope UART monitoring

    All the functionalities with the WiFi module and communication with the webserver was developedin stand alone C files and header files. The purpose of this was to develop a simple API for theother project group so they simple could make function calls from their code.

    21

  • 4.3 Mobile Application

    The smartphone application developed for this project is named Smart Greenhouse and developedfor smartphones using the Android operating system. It is divided into four action buttons, config-ured with click listener for taking the user to different areas to control, monitor and overview dataof the greenhouse. The sections Live Monitoring, Control, Statistics and Web store are describedindividually bellow.

    Figure 4.4: Mobile application flowchart

    4.3.1 Live Monitoring

    In the live monitor view is where actual data from the greenhouse are displayed. It consist oftwo parts, one temperature part and one dynamic scroll view part. Before displaying the con-tent on the screen, an HTTP request is sent to the server where greenhouse data is stored.

    Figure 4.5: Live monitor view

    Data is then returned in JSON array formatwhich in turn includes one JSON object foreach sensor. Each object consists of an id,name and data, where the name is used bythe application to identify the type of data.The application is going through every ob-ject in the array and places data in a scrollview, element after element. The scroll viewis implemented as a container of an element,where each element is an object itself con-taining three parts, description, data andunit. That provides possibilities for furtherdevelopment of adding new sensors for livemonitoring. A swipe to refresh function isadded to enables the user a swiping downaction over the screen to update the actual data. The application then sends a new HTTP requestevery time a swipe action is performed and updates all objects with the newest measured datafrom the database.

    22

  • 4.3.2 Control

    Controlling the greenhouse is done in two modes, self-controlling mode and autonomous mode,where one excludes the other. Switching between the modes is done trough a bottom navigationbar. When entering the control section the application opens up the mode the system is set to andshows the set parameters values. Each mode has its constraint layout which is a flexible view thatgives developers opportunities to place objects in different ways. The self-control mode has a scrollview where every cell has its object. Each object can be of three different types depending on theactuator it controls. If an actuator only has two stages (on/off), it is controlled with a switch buttonindicator showing on or off status. Ever time status is changed it sends the new value to the servervia a new HTTP request. Actuators can also be controlled via a sliding bar giving a value from zeroup to hundred. It programmed to track every time the user releases the sliding bar and then updates

    Figure 4.6: Control view

    the database. The third and last type of actuatoris number based controlled. It is built on a textinput field where only numbers are allowed, to seta value to actuate on. By switching to autonomousmode using the bottom navigation bar resets all val-ues from the previous mode since the system itselfcontrols all actuators. In the autonomous mode,two things can be automated individual or together,temperature and watering. Temperature is providedvia a text input field to provide the desired set-point temperature. Watering must be automatedwith two desired values, both watering interval andwatering interval time. Watering interval is a valuein hours to tell the system how many hours to bein between watering. Watering interval time, on the other hand, is for the system to know howmuch to water every time. Both of these value has to be set. The view then has a send button,for storing the values into the database.

    4.3.3 Statistics

    To better understand the behavior in the greenhouse, analyzing data is obvious from the author’sperspective and so also from the collaborators Willab Gardens. For the end customer visualizinghistorical data is necessary to predict potential of harvest and plants prosperous. The applicationis built to display historical data of all connected sensors in three different time perspectives, day,week and month. While entering the statistics section, the application receives data from the serverin JSON array format as described in live monitor chapter 4.3.1. The application then parses themeasured values for the last 24 hours, seven and 30 days into three different views, one for each time

    Figure 4.7: Statistics view

    perspective. The whole statistics section is imple-mented as nested scroll views for both scrolling be-tween actuators but also time perspectives. For ac-tuators, a bottom navigation bar is used to switchbetween actuators. To then swipe between differenttime perspectives views, a so-called page adapter isused, which keeps control of the three different timeperspectives. So while the user swipes, a new viewis opened and the previous destroyed. To then dis-play graphs in views an open-source library calledGraphView is used. GraphView is customized forAndroid mobile applications, creating a graphicalrepresentation of data. The library gives functionalities of different data representations and doesthe scaling of graphs compares to mobile screen size. It is sets up an (x,y) coordinate system,which then is used to add data points in (time, value) format to a linear data set. The data setis then customized to highlight every point with a dot, and a line in-between dots. The scaling ofeach graph is set to fit each time perspective. A dot selector is added which indicates which of thethree actual pages the user is looking at.

    23

  • 4.3.4 Web store

    Giving the user opportunity to visit Willab Garden webshop via the application is added forone reason. Willab Garden business perspective of visually see a full-scale system. It is simplyimplemented and by pressing the webshop button a new action is started where the applicationopens the actual mobile web browser. The browser starting page are set to Willab Gardens productssite, for future option of making purchases via the application.

    4.3.5 Microprocessor sequence diagram

    This system combines high-level language and response that will go to the low-level hardware. Tomake this possible some parsing of JSON data is needed so it can become usable in C language forthe hardware. For this project an open-source JSON parser library called frozen have been usedthat can process a JSON string and store the values directly in the program’s variables. Figure5.5 describes the sequence diagram at the lower level of how the request is sent and response ishandled.

    Figure 4.8: Hardware sequence diagram

    24

  • Chapter 5

    Result

    The results is evaluated according to section 3.2.

    5.1 User Interface

    Design of the user interface for this the smart greenhouse system is done to show functionalitiesand to give the full system experience. The user interface is meant to be used for mobile phonesusing Android operating systems. While running the application, starting page is a view with fourbuttons taking the user into different areas for controlling, monitor and view data generated fromthe greenhouse.This four sections are as follows:

    • Live Monitor

    • Control

    • Statistics

    • Web store

    Figure 5.1: Application start page

    25

  • 5.1.1 Live monitor

    Figure 5.2: Live monitor page

    The live monitor page are set up to show value from allconnected sensors connected to the greenhouse. Whileentering the page, all actual sensors data are retrievedfrom the web server. Temperature is always set to beshown in the upper ”greenhouse” as a minimum amountof values. Then the page is dynamically implemented,so depending on the number of connected sensors, everysensor gets its monitor object contains three parameters.The first parameter is a description, which described themeasured value, implemented as a string in java. Thesecond parameter is the actual measured value which isimplemented as a double and is the only possible valueto update. Third and last is the unit to each measuredvalue also implemented as a string. Time is set to showthe time stamp of the measured value provided by thedatabase, not least to ensure the user of its relevance.An added feature is the swipe refresh function, whichenables the user to pull the screen down for refreshingvalues of all monitor objects.

    5.1.2 Control

    Control of the greenhouse can be done in two ways, self-control- and autonomous mode. In self-control mode all actuators are implemented as stand-aloneobjects, putted in as list which gives dynamic of adding more actuators. To give the user theexperience of real-time response, whenever the states are changed on one of the objects, the valueis set into the database. To switch between the two modes, a bottom navigation bar is implemented,which also keeps track and updates the server of the mode status. In autonomous mode, the userinstantly gets information on what temperature and interval thresholds the system is set to viagray tint text in the green boxes. By clicking on the boxes, a software number keyboard pops upand the user can input new thresholds. By clicking the send button, values updates in the databaseand tint are set to newly provided values.

    Figure 5.3: Control mode & Autonomous mode

    5.1.3 Statistics

    Looking at the behavior of the greenhouse over time is an important feature to be able to predictharvest. The user interface then gives the opportunity of looking into both temperature and

    26

  • humidity. By clicking one of the bottom navigation bar buttons, data from the database areretrieved and displayed graphically in graphs. Having time on the x-axis and measured unit onthe y-axis where the y-axis scales itself, depending on the distribution of data and getting thehighest possible accuracy. Then by swiping over the screen, three-time perspectives are shown,today, average the last seven days and average each day the last thirty days. The graphs are alsotaken care of when data of days are missing and if the system is shut down.

    Figure 5.4: Control mode & Autonomous mode

    5.2 System Responsiveness

    To test the system responsiveness the system are setup to take a fixed value for sensor valuescorresponding to air temperature, air humidity and wind speed. Actual readings from the sensorare avoided since depending of used sensor, measurement time will vary greatly. The systemresponsiveness is measured in three structured ways, such as:

    1. Open a TCP connection to send sensor values. Closes after all data is sent.

    2. Open a TCP connection to retrieve data from the server. Closes after all data is retrieved.

    3. Both 1 and 2 in combination, to test a whole cycle of send and retrieve data.

    All three of the tests are done both with a WiFi router connected to fiber and a phone with 4Gconnectivity used as a hotspot. The test are simulated ten times to then calculate an average.Each test are done for one minute, and calculation of time effectively becomes:

    ResponseT ime =60 ∗ 10

    SUM(allRequests)

    Figure 5.5: Responsiveness calculation

    In table 5.6 and 5.7 measured time corresponding to the tests is presented.

    Tests Requests Response Time (sec)Send data 185 0.32

    Receive data 168 0.35Both send & receive 92 0.65

    Figure 5.6: System responsiveness w. fiber

    27

  • Tests Requests Response Time (sec)Send data 130 0.46

    Receive data 136 0.44Both send & receive 74 0.81

    Figure 5.7: System responsiveness w. 4G mobile hotspot

    According to the test tables, conclusions are made that system responsiveness differs dependingon what internet connectivity is used, fiber or 4G. Fiber is up to 24% faster than 4G connection.Further tests were made to investigate where most of the time were consumed. By performingAT commands test for the WiFi module, not involving TCP connections, the number of requestsraised to 15.000 times during one minute. The conclusion is therefore made that most of the timeis spent on open and close TCP connections.

    During the test the google server in Finland was unfortunately out of resources and temporar-ily placed in USA so the distances for data transportation were a lot higher.

    5.3 Costs

    5.3.1 Hardware components

    The total cost for the prototype including all the hardware excluding taxes was 4 663 SEK. Thisis well under budget of 10.000 SEK. Volume, custom made PCB and taxes could make a largeimpact and further lower the cost. Figure 5.8 list the individual costs of all hardware components,with a total value of 4 663 SEK.

    Component Price (SEK)Solenoid Valve 179.00Power Supply 319.92Relay Module 159.92Plug (230 V) 31.92Mounting box 547.00

    LED-list 251.69Mounting bracket 131.00Plastic Enclosure 21.70Linear Actuator 1 698.00

    Anemometer 431.97Breadboard 26.20

    AM2302 143.00Arduino Due 303.78

    Cable Trunking 66.70Cable Gland(s) 135.50Junction Box(s) 135.50

    Power Cable 79.92Total 4 662.72

    Figure 5.8: Individual component price list

    5.3.2 Server- & Database

    During the development of the prototype (five months) the cost for Google Cloud services was 250SEK/month. This does not include the license fee for Apache webserver and MySQL databasethat has to be added for a commercial product if it is not open source. During this time the N1standard CPU with 3.75 GB memory was used. The system was never above 0.1% meaning thatjust this small setup could provide the functionality for hundreds of users.

    28

  • 5.4 Full System Integration

    According to the main goals of this project 1.1, an implementation of a prototype for a smartgreenhouse system is done. Unfortunately where Willab Garden not able to provide the projectwith a greenhouse to integrate and test the system. The system was instead tested in full scale asproposed but without sensor and actuators mounted inside the greenhouse. The control system ismounted inside an IP classified box where sensors and actuators are connected trough for controland monitoring via the mobile application. Figure 5.9 shows the whole project system overviewand according to expected system overview 1.1 the design works as expected.

    Figure 5.9: Full system integration

    29

  • 5.4.1 Full system sequence diagram

    Figure 5.10 describes the full system in a sequence diagram that includes all communication. Notethat HTTP requests from the mobile application and the SGH are two parallel processes and canbe executed at a random time from different geological locations.

    Figure 5.10: System communication sequence diagram

    The result of the developed API for WiFi communication takes care of everything from the greenSGH symbol in figure 5.10. The API makes the HTTP requests and returns the result parsed ina C struct that later can be accessed in the code.

    30

  • Chapter 6

    Discussion

    6.1 Project discussion

    When summarizing this project, looking at the journey of an own idea growing into a prototype,there are things to reflect on. Not least, inevitable to overlook the consequences of the COVID-19pandemic across the world while this project took place. That in some parts slowed down theproject and was the reason Willab Garden was not able to supply a greenhouse for integrating thehardware into.Neither the importance of pilot studies and related work and what impact it has on the result. Butalso pros and cons of having two parallel developing processes as expected to end up in one. Fromthe author’s perspective, some of the benefits of ongoing parallel processes has been the amountof work put in, problems seen from different perspectives and coming from different educationbackgrounds have been valuable. The drawbacks have in some parts been the groups sometimesworking to isolated from each other, which has led to extra, unexpected problems. During thestart of the project, the group’s parts were carefully discussed, but in hindsight, they should havebeen better specified to facilitate implementation.

    The project ended up in a prototype that converts a regular greenhouse into a smart greenhouse asexpected in section System Overview. Total cost (4 663 SEK) of the prototype are well under thegiven budget of 10.000 SEK. Taking aspects as volume, taxes and custom made PCBs into account,manufacturing costs for an end product will fall heavily. According to section Purpose & Goal,the architecture is well established scientifically. All technical parts are well implemented, both interms of functionality and user-friendliness, but not in terms of reliability. Considering that thetime in the project is relatively short, system reliability requires further development to take careof edge cases. The native mobile application is well implemented and enables the user to controlall parts in the greenhouse. It is implemented to handle dynamically adding/removing of sensorand actuators. For seamlessly adding of sensors and actuators into the system, more work need tobe done on the server- and hardware side.

    Working with mobile application development has been new to both group members, even thoughthe Java language was known since before. It has given a better understanding of view-baseddevelopment not least when it comes to building dynamic views. The understanding of Javasclass-based structure has increased, which has been necessary.

    Another part that also has been completely new for the group is the need to set up a web serverthat allows for incoming traffic that can process data and send a response. This part was howeverquite easy since there is a lot of documentation and tools that make much of the setup needed.Using Google’s infrastructure as a service (IaaS, Google Cloud) enables quick setup of tools. Se-curity is an area that requires more work and implementation. Setting up a certificate for HTTPSto protect the URL endpoints is of importance.

    Due to the chosen hardware in this project, working with UART was unavoidable. UART wasan interface new to both the group members, but the implementation has been valuable for the

    31

  • understanding of computer engineering. Not least for the understanding of circuits and currents,seen as a vital part of computer engineering.

    As this project aims to be an own project with Willab Garden as collaborator, there has notbeen easy to evaluate whose advice to follows. Doing a project in that constellation requiresclearer communication from both sides or just their expertise of greenhouses as guidance. Theirlist of expected functionalities for a market product has not been fully completed, but it is seenpartly as a consequence of the COVID-19 pandemic. Even though the project did not get troughall Willab Garden functionalities, it ends as a well-designed prototype with all implemented partsworking. However, all parts require further developing, testing and analyzing. Overall the authorsare pleased with the results, especially set to the relatively short time given for the project.

    6.2 Further Development And Research

    To create a faster system and a more user-friendly application interface that can handle notifica-tion it is suggested to change the HTTP protocol to MQTT. This enables for publish/subscribefunctionality and reduce data being sent and response times. This is also important so unnecessarypulling can be avoided. A small server could also be coded at the processor to avoid pulling. Sincethe proposed system uses a table in the cloud storage acting as a middle service to exchange infor-mation (status flags) between the mobile application and SGH the use of a relational database isnot necessary. It would be interesting to see if the system could benefit from a non-relational real-time storage service and the use of JSON formatted data in something like google Firebase that isused by over 1.5 million mobile applications. Google claims data can be synced in milliseconds.

    6.3 Social Aspects

    6.3.1 Integrity & security

    In a system where data is collected and stored, integrity is an issue that has to be taken careof. Even though this project mostly focusing on system design and prototype building, integrityhas been taken into account, especially in the system design. From an integrity point of view thesystem is designed to not store any information about the users. Data is collected and could beconnected to a specific greenhouse but does not say anything about the user. There are of coursealways possibilities with data analysis, to see patterns of use and retrieve intrusive user data. Inthe future, if the focus would be a product for the market, the integrity aspect is something totake in to account for this type of product. Another topic of discussion is also where to host datato ensure customers privacy of such system.

    6.3.2 Environment

    According to the articles about home automation 2.1.1 and automated greenhouses 2.1.2 manyof them pointed out the environmental aspect as one of the most important. From the author’sperspective, it is crystal clear that automated greenhouses in the future will have positive environ-mental effects if the implementation is done correctly. This is also a conclusion from the reportGSM based Automatic Irrigation Control System for Efficient Use of Resources and Crop Planningby Using an Android Mobile[14] where they state that “automated greenhouses can be useful indifferent areas to help to avoid over and under irrigation and reduce the wastage of water”. Whatis also proven[28] according to industry usage and the yield of crops is such system can achieve 92% higher efficiency than a conventional approach. There are of course a consumption point of thisas well, going from an environmental area without electricity consumption to start consume elec-tricity and material to build such system. Depending on the choice of hardware and functionalityrequirements for the embedded system, there are, at least from the author’s point of view futurepossibilities to build a stand-alone, self-supplied ecosystem using rainwater and solar panels. Tobe able to count on the benefits of a self-sufficient system to achieve a small environmental effect,further studies on energy consumption of such system are necessary. Such optimized system formaximum yield would also help for a more sustainable future. That speaks for that automatedsmart greenhouses are a part of a greener and more energy-efficient future.

    32

  • 6.3.3 Economy

    As the market of home automation has grown the last decade with everything from home project tofull-scale platform systems, the authors can see a market for automated greenhouses. That is alsoconfirmed by Willab Garden where they have seen a growing demand for controlling functionalitiesin greenhouses. More market-related investigation needs to been done to ensure the scale andpricing of development costs of such system.From the authors perspective, the economical challenge of a future market product would be thedevelopment costs, rather than production- or selling costs of such systems.

    33

  • 34

  • Chapter 7

    Conclusion

    This reports main purpose was to investigate and propose a system architecture for automatedgreenhouses. The system should intend to be remotely monitored and controlled by the ease ofa mobile application. This project was divided into two parts, where this part (Computer Engi-neering) focusing on system architecture and user interface. The project resulted in a full-scaleprototype including a mobile application, web server, database and embedded system ready tointegrate into a greenhouse.

    Results show that the system is responsive and can be accessed remotely with a response timeat 0.65 seconds. It also shows that any greenhouse can be converted to a smart greenhouse forremote control. These systems are widely used in the industry and this report presents suchsystem for the private horticulture market. Related articles points out that yield of crops andless water wastage can improve with such system to help for a more sustainable future. Furtherdevelopment and interesting research would be towards focusing on an energy-efficient integratedgreenhouse system that is acting as a self supplies ecosystem. Another option is to focus more onplant environment optimization where calculations can be done on a longer period.

    35

  • 36

  • Bibliography

    [1] S. Bhutada, S. Shetty, R. Malye, V. Sharma, S. Menon, and R. Ramamoorthy. Implemen-tation of a fully automated greenhouse using scada tool like labview. In Proceedings, 2005IEEE/ASME International Conference on Advanced Intelligent Mechatronics., pages 741–746,July 2005.

    [2] D. Xu and H. Li. Intelligent greenhouse control-system based on agent. In 2008 Interna-tional Conference on Intelligent Computation Technology and Automation (ICICTA), vol-ume 1, pages 390–394, Oct 2008.

    [3] Senmatic. Industrial horticulture. https://www.senmatic.com/. Accessed: 2020-03-6.

    [4] R. K. Kodali, V. Jain, and S. Karagwal. Iot based smart greenhouse. In 2016 IEEE Region10 Humanitarian Technology Conference (R10-HTC), pages 1–6, Dec 2016.

    [5] O. Johansson and G. Andersson. Smart greenhouse. Halmstad DiVA, 2020.

    [6] Furtune Business Insights. Market reaserch report. pages 0–140, April 2019.

    [7] Sam Francis. Fast-growing sectors within robotics and automation. https://roboticsandautomationnews.com/2018/01/12/. Accessed: 2020-05-04.

    [8] K. Mandula, R. Parupalli, C. A. S. Murty, E. Magesh, and R. Lunagariya. Mobile basedhome automation using internet of things(iot). In 2015 International Conference on Control,Instrumentation, Communication and Computational Technologies (ICCICCT), pages 340–343, 2015.

    [9] Rajeev Piyare. Internet of things: ubiquitous home control and monitoring system usingandroid based smart phone. International journal of Internet of Things, 2(1):5–11, 2013.

    [10] Home Assistant. Awaken your home. https://www.home-assistant.io/. Accessed: 2020-04-09.

    [11] Google. Nest hub. https://store.google.com/us/product/google_nest_hub?hl=en-US.Accessed: 2020-04-09.

    [12] Nikesh Gondchawar and Prof. Dr. R. S. Kawitkar. Iot based smart agriculture. In InternationalJournal of Advanced Research in Computer and Communication Engineering, volume 5, pages838–842, Dec 2016.

    [13] G. Sushanth and S. Sujatha. Iot based smart agriculture system. In 2018 InternationalConference on Wireless Communications, Signal Processing and Networking (WiSPNET),pages 1–4, March 2018.

    [14] D. SG. Pavithra and M. S. Srinath. Gsm based automatic irrigation control system for efficientuse of resources and crop planning by using an android mobile. In IOSR Journal of Mechanicaland Civil Engineering (IOSR-JMCE), pages 49–55, Jul-Aug 2014.

    [15] T. Teslyuk, P. Denysyuk, A. Kernytskyy, and V. Teslyuk. Automated control system forarduino and android based intelligent greenhouse. In 2015 XI International Conference onPerspective Technologies and Methods in MEMS Design (MEMSTECH), pages 7–10, 2015.

    [16] J. Hwang and H. Yoe. Study on the context-aware middleware for ubiquitous greenhousesusing wireless sensor networks. Sensors — Open Access Journal, pages 4539–4561, April 2011.

    37

  • [17] S. Malik and F. Huet. Virtual cloud: Rent out the rented resources. In 2011 InternationalConference for Internet Technology and Secured Transactions, pages 536–541, Dec 2011.

    [18] Näringsdepartementet. Sverige helt uppkopplat 2025, en bredbandsstrategi. https://www.regeringen.se/informationsmaterial/2016/12/sverige-helt-uppkopplat-

    2025---en-bredbandsstrategi/. Accessed: 2020-02-28.

    [19] COMVIQ. Täckningskarta. https://www.comviq.se/tackning. Accessed: 2020-02-28.

    [20] Xiuping Song. Design of smart home system based on power line communication technologyand wireless sensor networks. In Chemical Engineering Transaction, volume 51, pages 757–762,2016.

    [21] TT. Ny teknik, fiber access in sweden. https://www.nyteknik.se/digitalisering/tre-fjardedelar-har-tillgang-till-fiberkabel-i-sverige-6953317. Accessed: 2020-03-6.

    [22] N. Naik. Choice of effective messaging protocols for iot systems: Mqtt, coap, amqp and http.In 2017 IEEE International Systems Engineering Symposium (ISSE), pages 1–7, 2017.

    [23] R A Atmoko, R Riantini, and M K Hasin. IoT real time data acquisition using MQTTprotocol. Journal of Physics: Conference Series, 853:012003, may 2017.

    [24] U. Hunkeler, H. L. Truong, and A. Stanford-Clark. Mqtt-s — a publish/subscribe protocol forwireless sensor networks. In 2008 3rd International Conference on Communication SystemsSoftware and Middleware and Workshops (COMSWARE ’08), pages 791–798, 2008.

    [25] Mattias Krysander. Project model lips. http://lips.isy.liu.se/en/. Accessed: 2020-03-03.

    [26] P. Srivastava, M. Bajaj, and A. S. Rana. Overview of esp8266 wi-fi module based smartirrigation system using iot. In 2018 Fourth Internationa