master of engineering thesis design of a smartphone-based...

90
Master of Engineering Thesis Design of A Smartphone-based Remote Monitoring Device for Food Waste Processing Machines CHUNGBUK NATIONAL UNIVERSITY GRADUATE SCHOOL College of Electrical, Electronic, Information and Computer Engineering RATMALGRE ALEX SYLVESTERE DESIRE KOALA August 2019

Upload: others

Post on 25-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

Master of Engineering Thesis

Design of A Smartphone-based Remote Monitoring Device for Food Waste Processing Machines

CHUNGBUK NATIONAL UNIVERSITY GRADUATE SCHOOL

College of Electrical, Electronic, Information and Computer Engineering

RATMALGRE ALEX SYLVESTERE DESIRE KOALA

August 2019

Page 2: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

Master of Engineering Thesis

Design of A Smartphone-based Remote Monitoring Device for Food Waste Processing Machines

Advising Professor Ahn, Bierng-Chearl

College of Electrical, Electronic, Information and Computer Engineering

RATMALGRE ALEX SYLVESTERE DESIRE KOALA

This thesis is a master’s thesis of engineering

August 2019

Page 3: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

This thesis is recognized as a master’s thesis of RATMALGRE ALEX SYLVESTERE DESIRE KOALA.

Committee Chairman AHN, JAE-HYUNG ㊞

Committee Member AHN, BIERNG-CHEARL ㊞

Committee Member LI, SHU ㊞

CH U N G B U K N A TIO N A L U N IV ER SIT Y GR A D U A TE SCHOOL

August 2019

Page 4: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- i -

Table Of Contents

Abstract ····························································································································· iii

List of Tables ···················································································································· v

List of Figures ················································································································· vi

Ⅰ. INTRODUCTION ································································································ 1

Ⅱ. HARDWARE DESIGN ···················································································· 5

2.1 Operating Principles of the Device ····························································· 5

2.2 Device Design Concept ···················································································· 6

2.3 Components Description ··················································································· 9

Ⅲ. PROGRAMMING ····························································································· 16

3.1 Software Structure ···························································································· 16

3.2 Database and Data Format ············································································ 17

3.3 WiFi Configuration and Connection ··························································· 20

3.4 Firebase Database Connection ······································································· 20

3.5 Camera Connection ·························································································· 21

3.6 Temperature/Humidity sensor Connection ·················································· 21

3.7 Module to Module Communications ··························································· 22

3.8 Smartphone Application ·················································································· 24

3.9 Program Design ································································································ 24

Ⅳ. CONSTRUCTION AND TESTS ································································ 37

4.1 Construction ······································································································· 37

Page 5: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- ii -

4.2 Tests ····················································································································· 39

4.3 Future Work ······································································································ 43

V. CONCLUSION ···································································································· 45

REFERENCES ············································································································ 47

APPENDIX ·················································································································· 49

Page 6: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- iii -

Design of a Smartphone-based Remote Monitoring Device for Food Waste Processing Machines

RATMALGRE ALEX SYLVESTERE DESIRE KOALA

Radio and Communications Eng. Track

Dept. of Electrical, Electronics, Information and Computer Eng.

Graduate School of Chungbuk National University, Cheongju City, Korea

Supervised by Prof. Ahn, Bierng-Chearl

A bstract

This thesis presents a development of a smartphone-based remote monitoring

device for food waste processing machines. The device will be used for real time

monitoring on a smartphone of the image, the temperature and the humidity of a

food waste processing machine under operation and for ON/OFF control of the

power, a fan, a heater, a valve and a motor of the food waste processing

machine.

The device developed in this thesis consists of hardware employing an MCU,

a video camera, a WiFi module, a temperature/humidity sensor, and a AC relay

switch, and software consisting of data structure, data acquisition, data

Page 7: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- iv -

management and transfer, smartphone application program, and data communication

via WiFi channel. For hardware and associated firmware, Arduino-based

open-source solutions have been employed. For software part, programming for a

user smartphone application and web-based database management have been

carried out. The designed device has been implemented and tested. Results of the

test show that the developed device meets the design requirements.

* A thesis for the degree of Master in August 2019.

Page 8: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- v -

List of Tables

Table 2.1 Device specifications ······················································································ 7

Table 2.2 Specifications of the components ································································· 9

Table 2.3 ESP8266 specifications ················································································· 11

Table 3.1 Communication links of the system ··························································· 17

Table 3.2 UC1-Authentication ····················································································· 29

Table 3.3 UC2-Switch ON/OFF ··················································································· 30

Table 4.1 Conditions of environment of the EMC test..............................................40

Page 9: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- vi -

List of Figures

Fig. 1.1 DOW-100 food waste processing machine ····················································· 3

Fig. 1.2 The internal processing unit of DOW-100 ··························································· 4

Fig. 2.1 Block diagram of the proposed system ·························································· 6

Fig. 2.2 Schematics of the proposed system ······························································ 8

Fig. 2.3 ArduCAM UNO board ················································································· 10

Fig. 2.4 Block diagram of ESP8266 WiFi module ··················································· 12

Fig. 2.5 ArduCAM shield wiring ················································································· 12

Fig. 2.6 Mounting of the camera module on the ArduCAM UNO board ······················· 13

Fig. 2.7 I2C bus communication configuration ··························································· 13

Fig. 2.8 DHT11 sensor ·································································································· 14

Fig. 2.9 08-port relay module ······················································································· 15

Fig. 3.1 Database structure ······························································································· 19

Fig. 3.2 Stored data ········································································································· 19

Fig. 3.3 DHT11 wiring to MCU ····················································································· 22

Fig. 3.4 Communication links ·························································································· 23

Fig. 3.5 User-Push-Data class diagram ············································································· 25

Fig. 3.6 Global class diagram ·························································································· 26

Fig. 3.7 Global use case diagram ···················································································· 28

Fig. 3.8 Login sequence diagram ····················································································· 32

Page 10: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- vii -

Fig. 3.9 Login layout interface ························································································· 34

Fig. 3.10 Main interface ·································································································· 35

Fig. 3.11 ‘About’ page interface ······················································································ 36

Fig. 4.1 The device installed in a box ············································································ 37

Fig. 4.2 Camera stream test ··························································································· 38

Fig. 4.3 Switch ON/OFF test ························································································· 39

Fig. 4.4 Electrostatic discharge immunity test points ······················································· 40

Fig. 4.5 Conducted emission measurement set-up ···························································· 41

Fig. 4.6 Radiated emission (below 1GHz) measurement set-up ······································· 41

Fig. 4.7 Radiated emission (above 1GHz) measurement set-up ········································ 42

Fig. 4.8 Radiated RF immunity set-up ········································································ 42

Fig. 4.9 SetAlarm use case diagram ················································································ 43

Fig. 4.10 SetAlarm sequence diagram ·············································································· 44

Page 11: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 1 -

I. INTRODUCTION

Information technology is in the era of smart things with everything from the

discreet beauty accessory like a watch to something as big as a house. Everything

is getting smarter being more and more connected to internet. The number and

diversity of mobile devices are growing bigger and bigger [1]. That use of mobile

devices introduces the need for wireless services and for remote monitoring and

control [2].

This work has been carried out in cooperation with Dowoosys Company.

The company wants to use wireless technologies to implement wireless services to

its bio-waste disposal machine (DOW-100) shown in Figs. 1.1 and 1.2. DOW-100

is a food waste disposer that uses microorganisms to biologically disintegrate food

wastes. DOW-100 can handle up to 3.2 kg waste per day [3]. Temperature and

humidity inside the machine are critical to keep the microorganisms alive.

Therefore there is a need for monitoring the temperature and humidity of the food

waste disposer. The flaws in the running of the waste disposer can only be

detected by directly accessing the inner part of the device. Dowoosys wants to

integrate IoT technology into DOW-100 to reduce maintenance costs.

Several IoT-based techniques have been investigated in order to find a suitable

design. In [4], a technique has been proposed to connect home appliances to

Page 12: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 2 -

mobile networks for monitoring and controlling purposes using a mobile phone or

a web browser. In [4], solutions have bee presented based on an WiFi AT

command and a Bluetooth remote control. The AT-based solution is device-

dependent and might need further processing to work with diverse equipments.

Piyare and Lee introduced a smart home-control and monitoring system using

embedded micro-web server with IP connectivity [5]. Here an embedded

micro-web server with an IP connectivity has been used to remotely control home

environment equipment of a smartphone.

In this thesis, a system is proposed that uses Android studio as a main

module. The designed device is an Android-based computing module connected to

temperature and humidity sensor and to a camera. The overall device can be

accessed and controlled from an Android-based mobile application (GLIoT).

Chapter II gives a description of the device including the global block diagram

and the schematics of the proposed system as well as the components employed.

Chapter III presents the programming of the system including the modeling of the

system. Chapter IV deals with the constructions of the device and the tests that

have been performed to confirm the proper operation.

Page 13: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 3 -

(a)

(b)

Fig. 1.1 DOW-100 food waste processing machine. (a) External view and (b)

construction

Page 14: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 4 -

Fig. 1.2 The internal processing unit of DOW-100

Page 15: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 5 -

II. HARDWARE DESIGN

2.1 Operating Principles of the Device

Fig. 2.1 shows the block diagram of the proposed device for food waste

processing machines. The device is installed inside the waste processing chamber

and monitors the process of waste disposal through a camera, a humidity sensor

and a temperature sensor. The temperature and the humidity are collected by the

DHT11 sensor and read by the MCU as digital input. The values of the collected

temperature and the humidity are uploaded to Google's Firebase Realtime Database

for data storage and retrieval. The proposed device also switches five relays

ON/OFF to control the AC power, the air circulation fan and the water valve.

The user uses an Android application to monitor the waste processing machine

with video and temperature/humidity data and to control the relays. The

smartphone communicates with the device via internet by connecting to a nearby

WiFi router, which may be in a remote location. The device is connected to

internet via a WiFi router installed near the food waste processing machine. The

video image is transmitted directly for the device to the smartphone while the

temperature/humidity data are stored on the Firebase Realtime Database and then

accessed by the smartphone. In this way, the user can monitor and control the

device in real time at any place in the world.

Page 16: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 6 -

Fig. 2.1 Block diagram of the proposed system

2.2 Device Design Concept

Table 2.1 shows the specifications of the device to be developed in this thesis.

The power for the device is supplied by an AC/DC adapter with 12V/2.1A. The

video camera has a resolution of 1920x1080 and a speed of 15 frames per

second. The camera's video data is transmitted to the MCU via SPI bus and the

MCU does the video streaming via the WiFi module.

The temperature sensor measures the temperature inside the food waste

Page 17: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 7 -

processing machine in the range of 0-50°C, while the humidity sensor measures

20-90% RH. The connection between the device and the internet is done with a

2.4GHz WiFi module. Relays have a voltage-current rating of 250VAC/10A with

an integrated relay driver, which is controlled by a 5V digital signal directly from

the MCU. The temperature and humidity data will be stored on Google's free-

service Firebase Realtime Database and will be accessed by the smartphone in

real time. Stored temperature and humidity data can be retrieved for later analysis

and display of values versus time.

Table 2.1 Device specifications

PARAMETERS SPECIFICATIONS

Power Voltage: 12VCurrent: 2.1A

CameraResolution: 2MP (1920x1080)

Video speed: 15fpsInterface: SPI

Cable length: 150mmHumidity Measurement 20-90%RH ± 5%

Temperature Measurement 0-50◦C ± 2◦C

Communication WiFi 2.4GHz Relay Switch 250ACV/10A

Relay Controller Integrated relay (5V control imput)Number of relays supported: 5

Database Server Google Firebase

Smartphone Application

Video live streamingTemperature/humidity display

Relay ON/OFF control: 5 buttons

Page 18: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 8 -

The smartphone application will have such functions as video live streaming,

temperature/humidity data display, and ON/OFF control of five relays. Fig. 2.2

shows the schematic of the device developed in this thesis. Commercial

off-the-shelf (COTS) hardware components have been used while open-source

firmware have been used for camera streaming function, temperature/humidity

sensor readout function, and the WiFi connection function.

Fig. 2.2 Schematics of the proposed system

Five relays are connected to the main board Arduino UNO through the pins

Page 19: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 9 -

D2, D3, D4, D5, D6. The data pin of the DHT11 sensor is connected to pin D7.

The pins of the camera (CS MOSI MISO SCK GND VCC SDA SCL) are

connected to the corresponding pins of the same labels on the Arduino UNO.

Based on the device specifications, components have been selected as shown in

Table 2.2.

Table 2.2 Specifications of the components

2.3 Components Description

1) ArduCAM UNO Module

The ArduCAM UNO module is the Arduino UNO board with an integrated

ESP8266 WiFi module and a camera interface. The ArduCAM UNO uses the

8-bit AVR microcontroller ATmega328P. The main features of the ArduCAM

Model Number Specifications

Camera ArduCAM Mini 2MP/5MP 2MP/5MP

Humidity Sensor DHT11 20-90%RH ± 5% Temperature

Sensor DHT11 0-50◦C ± 2 ◦C

WiFi module ESP8266802.11n

70m range (indoor) 250m range

(outdoor)Relay Switch 08-port relay 250V/10A

MCU ArduCAM UNO 3.7-5V/500mAATmega328P

Main Module Power

KingAM AC

100-240 DC 12V 1A

DC 7-12V AC/DC adapter

Page 20: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 10 -

UNO module include a built-in ESP8266-12 E WiFi module and a 2 megapixels

camera [6]. Fig. 2.3 shows the photograph of the ArduCAM UNO board.

Fig. 2.3 ArduCAM UNO board

2) ESP8266 WiFi Module

The ESP8266 WIFI module is integrated to the arduCAM UNO board to

allow applications like IP webcam and related home automation services. The

ESP8266 module integrates many modules including an antenna switches, an RF

balun and a power amplifier [7]. The specifications of the ESP8266 are

summarized on the Table 2.3 [3].

The modules interacts with each other depending on the application. The

functional block diagram of the ESP is shown on Fig. 2.4. The CPU includes

programmable RAM/ROM interfaces (iBUS), data RAM interfaces (dBUS) and

AHB interface. iBUS and dBUS can be connected to a memory controller. AHB

Page 21: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 11 -

is used to access registers. ROM and SRAM memory units are integrated by

ESP8266; The RAM limit when ESP8266 is configured in station mode is 50 kB

and the SPI flash is used to store the program. The radio of ESP contains a

receiver and a transmitter at 2.4GHz, a high speed clock generator and a crystal

oscillator.

Table 2.3 ESP8266 specifications

PARAMETERS SPECIFICATIONS

Protocols 802.11 b/g/n (HT20)

Frequency Range 2.4Ghz-2.5Mz

TX Power802.11 b: +20 dBm802.11g: +17 dBm

802.11n: +14 dBm

RX sensitivity

802.11 b: -91 dbm (11 Mbps)

802.11g: -75 dbm (54 Mbps)

802.11n: -72 dbm (MCS7)

CPU Tensilica L106 32-bit processor

Antenna PCB trace, Ceramic chip

Operating voltage 2.5V – 3.6VOperating temperature

range -40℃-125℃

WIFI mode Station/AP

WIFI security WPA/WPA2

Page 22: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 12 -

Fig. 2.4 Block diagram of ESP8266 WiFi module

3) Camera Module

The camera module used is the ArduCAM Mini 2MP/5MP. The features of

the camera include an OV2640 image sensor, I2C and SPI interfaces support [8].

The I2C communication interface is used for the internal configuration of the

sensor and the SPI communication interface is for the camera configuration and

control. The wiring and mounting are shown in Fig. 2.5 and Fig. 2.6 respectively.

Fig. 2.5 ArduCAM shield wiring

Page 23: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 13 -

Fig. 2.6 Mounting of the camera module on the ArduCAM UNO board

I2C communication interface is directly connected to the image sensor

OV2640. I2C interface can be configured either as a master or as a slave. I2C

master configuration allows to read an write the registers of the OV2640 sensor.

The Serial Data (SDA) and the Serial CLock (SCL) are the only lines needed for

I2C communication bus. SCL is initiated by the master and synchronizes the data

transfer between master and slaves and SDA carries the data. The wiring is

shown in Fig. 2.7.

Page 24: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 14 -

Fig. 2.7 I2C bus communication configuration

4) Temperature/Humidity Sensor

A temperature/humidity sensor has been employed in order to collect the

temperature and the humidity within the food waste processing machine. The main

features of the sensor include a measurement range from 0 degree celsius to 50

degrees.

Fig. 2.8 DHT11 sensor

Page 25: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 15 -

5) Relay

A 08-port SONGLE relay has been employed to meet the system

specifications. The main features of the relay include switching by 10A and

material that supports high temperature [9].

Fig. 2.9 08-port relay module

Page 26: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 16 -

III. PROGRAMMING

3.1 Software Structure

The architecture of the proposed system consists of a communication part

handled by a WiFi connectivity, a camera unit for live streaming, a temperature

and humidity monitoring unit and a remote switch ON/OFF control unit. The

functionalities associated with the aforementioned units are handled and run in a

timeline manner.

The first module to run is the WiFi module, then the connection to Firebase.

The third module to be executed is the camera module which handles the

connection to the camera and the retrieval of the camera feed. After the camera

module, the temperature and humidity modules are run. This allows the retrieval

of the temperature and the humidity from inside the food waste disposer and the

display of retrieved data. The next step is the execution of the mobile application.

This module is the last module to be executed. Table 3.1 summarizes the program

modules developed in this thesis.

Page 27: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 17 -

Table 3.1 Communications links of the system

Links Stages Variables

1. DHT11-ArduCAM

1.1 DHT11 collects the temperature and the Humidity

temp, hum1.2 DHT11 sends the data to ArduCAM UNO

1.3 ArduCAM UNO reads and Format the data

2. ArduCAM-Firebase

2.1 ArduCAM authenticates to Firebase temp, hum, led1, led2, led3, led4, led5

2.2 Firebase acknoledge ArduCAM and alloes READ and WRITE operations

2.3 ArduCAM Stores temp and hum2.4 ArduCAM reads the values of led1, led2,

led3, led4, led5

3. ArduCAM UNO- Camera 2MP

3.1 ArduCAM generates a webserver to host the stream from the Camera

None3.2 The camera captures and hosts the video stream on the server initiated on ArduCAM

4. ArduCAM UNO- Relay

4.1 ArduCAM performs a READ operation in Firebase to read the values led1, led2, led3, led4, led5

led1, led2, led3, led4, led5

4.2 ArduCAM changes the sates of the pins corresponding to led1, led2, led3, led4, led5 accordingly

5. GLIoT-Firebase

5.1 The user’s actions are collected by GLIoT led1, led2, led3, led4, led5

5.2 GLIoT matches the actions of the user to the variables led1, led2, led3, led4, led5

5.3 The changes in the variables are updated in Firebase

3.2 Database and Data Format

GLIoT displays the temperature and the humidity of the food waste disposer

where the sensors are installed. The data stored in the database is formatted

Page 28: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 18 -

following the specifications of the database of Firebase as shown in Fig. 3.2. The

real time database of Firebase is structured as a JSON tree [10]. The data is

formatted into JSON objects and then stored. When the data is stored, it becomes

a node instead of a table like in SQL database.

The format and structure of the temperature and humidity data are presented

on the Fig. 3.1. The database has many children used to store data from the main

module and from the mobile application. The hum child is used to store the

humidity collected with DHT11. The value of the humidity humVal is formatted

as a String and represents the humidity level inside the food waste disposer.

humVal can be accessed from the mobile application and is displayed in

percentage.

The temp child is used to store the humidity collected with DHT11. The value

of the humidity tempVal is formatted as a String and represents the humidity level

inside the food waste disposer. tempVal can be accessed from the mobile

application and is displayed in percentage.

The led1 child is used to store the state of the electronic device connected to

the first port of the SONGLE relay. The power of the food waste disposer has

been connected to the first port of the relay. led1 allows to turn the food waste

disposer off when needed. The led2 child represents the fans in the food waste

disposer. A change in the state of led2 allows to either turn the fans OFF or ON.

Page 29: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 19 -

Fig. 3.1 Database structure

Fig. 3.2 Stored data

Page 30: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 20 -

GLIoT can be subdivided into four main modules managed by the MCU, the

camera, the relay and the sensor. The global communication architecture of our

system evolves around transmitting the data collected by the sensors and also the

data transmitted and received by the mobile application.

3.3 WiFi Configuration and Connection

The ArduCAM Uno module integrates a ESP8266 WiFi module that can be

programmed as station or an AP. For the proposed system, the WiFi module as

been set as a station. This configuration allows the system to scan for available

networks and connect to a selected network. The WiFi module is also

programmed to handle the authentication and the connection de the database as

well as the communication with the mobile phone. The details of the program can

be seen in the Appendix.

3.4 Firebase Database Connection

Firebase is integrated in the development environment of Arduino studio.

Firebase is used for IoT applications requiring a realtime data management for

transmission, storage to retrieval. The collected temperature and humidity data are

uploaded to Firebase to be stored. ArduCAM also performs a READ operation to

Firebase when checking the states of the pins of the relay. ArduCAM UNO reads

the state of the pins connected to the relay from the database and change the

states of those pins accordingly. The user actions on the mobile phone are

Page 31: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 21 -

detected by Firebase and any change in the variable led1, led2, led3, led3, led4 is

stored.

3.5 Camera Connection

ArduCAM UNO is connected to the ESP8266 module. In order to stream the

video remotely, the ESP8266 is used to generated a web server to host the stream

from the camera. The camera captures and host the video stream on the server

initiated by ArduCAM.

3.6 Temperature/Humidity Sensor Connection

The temperature sensor DHT11 is connected to the main module ArduCAM

UNO board to collect the ambient temperature of the food waste disposer. DHT11

collects the temperature and the humidity from DOW-100. The collected

temperature and humidity data are sent to ArduCAM UNO. ArduCAM UNO

formats the temperature and the humidity. DHT11 combines digital signal

acquisition and sensing technology to collects the temperature and the humidity

that are formatted into decimal and integral parts [11].

A single-wire two-way communication interface configuration is used to between

the DHT11 and the main module. The data is transmitted between DHT11 and

ArduCAM UNO in a 40 bits long sequences [11]. Fig. 3.3 shows the connection

diagram of the DHT11 module.

Page 32: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 22 -

Fig. 3.3 DHT11 wiring to MCU

3.7 Module to Module Communications

The temperature/humidity sensor DHT11 collects the temperature and the

humidity and sends the data to the main module ArduCam UNO board. This is

the communication link 1 shown on Fig. 3.4 below. The communication link 2 is

the accessed to Google’s Firebase Realtime Database via internet through the

router to store the data collected by ArduCAM UNO. Link 3 and link 4 represent

respectively the camera feed being uploaded to the MCU and the remote control

of the relay. Link 5 is for the connection of the smartphone to Firebase to

retrieve the values of the temperature and the humidity.

Page 33: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 23 -

Fig. 3.4 Communication links

Page 34: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 24 -

3.8 Smartphone Application

System design can be defined as the process of defining the architecture, the

interfaces of the system, its modules and the data it manipulates to satisfy specific

requirements known as user requirements [12][13]. System design involves

different types of design including architecture design, interface design, data

structure design, and algorithm design.

GLIoT has been developed in Java, a object-oriented language. Object-oriented

systems can be modelled by describing the static and dynamic interactions

between the objects. For this purpose, the Unified Modeling Langage (UML) is

used. UML provides a standard way to visualize the design of a system [14].

UML offers three different types of diagrams including structure diagrams,

behavior diagrams and interaction diagrams.

The structure diagrams (Class diagram) provide a view of the system to build

with an emphasis on the components of the system with their interactions. The

Behaviors diagrams (Use case diagram) provide a view on the behaviors of the

system with an emphasis on what must happen. The interaction diagram (Sequence

diagram) is one type of behavior diagram. This type of diagrams provide an

emphasis on the flow and control of data.

3.9 Program Design

1) Class Diagram

Page 35: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 25 -

Class diagram describes the static structure of the system in terms of classes

and the interactions between them. The class diagram models the entities of the

system. The entities are composed of states which are collections of attributes and

operations on states are objects [15]. An object can be created by providing an

object definition. The object definition should contain all the attributes and

operations that can be carried on the object. The Push class that represents an

interaction of “pushing data” by the user is linked to the User class and to the

Data class. Fig. 3.5 shows the class diagram.

Fig. 3.5 User-Push-Data class diagram

The global class diagram of the system shown in Fig. 3.6 is composed by the

classes MainInterface, Push, Stream, Data, Action, Alarm, AlarmDetails, Switch

and User. MainInterface represents the main interface of GLIoT, Stream represents

the action of “streaming” the camera feed and Switch the action of “switching

ON/OFF”.

Page 36: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 26 -

Fig. 3.6 Global class diagram

2) Use Case Diagram

Use case diagram shown in Fig. 3.7 is a representation of the interactions

between the user and the use cases of the system in which the user is involved

[16]. The use case diagram is built using different use cases that have to be

defined as scenarios involving different type of users and their interactions with

Page 37: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 27 -

the system. A scenario is a brief user story made of actions that describe who is

using the system and what they are trying to accomplish. The definition of a

script involve different types of scripts and messages.

A Step is a simple, discrete action that is part of a scenario and that is

performed by the either the “system” or a “user”. An Actor is an UML element

representing the role of a person, object or device that interacts with a system. A

Basic path describes a sequence of events when everything goes as expected. Also

known as the "Happy path", "Basic course", "Sunny day scenario", "Primary path",

"Expected path". An Alternate path is produced by a tested rule with an

alternative set of steps that run in parallel with part of the Basic path. An

Exception path is the result of a step in the basic path that fails to produce a

successful result.

The use case associated to the authentication process is described on Table

3.2. When the user tries to access the system, the system displays the login

interface for the user to enter his credentials. After that the system checks the

user’s details and if the details match the system displays the main interface.

Table 3.3 describes the use case associated with the Switch ON/OFF

functionality of our system. When a user triggers a button on the mobile

application to switch ON/OFF a device, the system receives the command and

sends it to Firebase. Firebase then sets the states of the corresponding device in

the database. The MCU automatically detects the change of state in the database

and updates the states of the hardware.

Page 38: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 28 -

Fig. 3.7 Global use case diagram

Page 39: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 29 -

Table 3.2 UC1 authentication

UC1: Authentication

Description: Authenticate to get access to the system using a login and a passwordBasic path:

1. User tries to access the system

2. The System displays the login interface for the user to fill-in his credentials

3. The User fills in his login and the password

4. The System checks the credentials of the User

5. The User accesses the SystemAlternate path:

4.a. The System replies that the login or the password are not correct and the process

goes back to Point 2.Outcome: The User accesses the System

Page 40: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 30 -

Table 3.3 UC2-Switch ON/OFF

UC2: Switch

Description: Remotely switch On or OFF electronicsBasic path: 6. User triggers a button to switch ON or OFF a device7. The System The System receives the command and send it to the server 8. The Server Upload the state of the device to the database9. The micro-controller accesses the server and reads the state of the device10. The device state is changes by the micro-controller and the device is switched ON or

OFFAlternate path:7.a. The System replies that the server cannot be reached and the process goes back to

point 1.

8.a. The server replies that the state of the LED cannot be updated. The process goes back to point 6.

9.a. The server replies that the state of the LED cannot be read from the database and the

process goes back to point 6.

10.a The micro-controller replies that the state of the LED cannot be changed and the process goes back to point 6.

11. Outcome: The User accesses the System

Page 41: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 31 -

3) Sequence Diagram

A sequence diagram is the representation of the objects of a system and the

interactions including messages exchanges between them in time sequence [17].

The sequence diagram uses a few components and symbols to describe the system

flow through time. An Actor represents entities that interact or are external to the

system. An Object represents a class that demonstrates how the represented class

behaves in the context of the system. Lifetime symbols represent the time flow

from top to bottom. Lifetime symbols are dashed vertical lines that shows the

sequential events that occur to an object during the charted process. Loops are

used to model circumstance where a defined condition is fulfilled. The sequence

diagram of the log-in activity is presented on Fig. 3.8. The sequences described

on Fig. 3.8 are similar to the steps of UC1 describes in Table 3.2

Page 42: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 32 -

Fig. 3.8 Login sequence diagram

4) User Interface Design

Android Studio provides a very convenient user interface design tool as

presented in section 1.3.5. The user interface is essentially composed of screen

layouts. The screen layout consist of different components depending on the

commands to be performed on the interface.

4.1) Screen Layouts

Page 43: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 33 -

The layout defines the structure for a user interface in the application [18].

The arrangement of elements, the choice of the colors and graphics are very

important in designing a screen layout. There are three layout screens in GLIoT.

The Login screen shown in Fig. 3.9 is a layout where the user identifies and

requests access to GLIoT. The main screen is the first screen the user is directed

to after logging in. The about screen is the layout that allows the user to contact

Dowoosys Company.

Each of the above mentioned screen allows the user to carryout some actions

and interact with the different components of our system mentioned in section 2.

An attractive design has been reached by applying beautiful and discreet colors.

The color system has been defined in the application themes of the project as

follows:

The colorLightPrimary has been set to #263238

The colorPrimaryDark has been set to #7B1FA2;

The colorAccent has been set to #FFC107.

4.1.1) Login Screen

In order to implement the login activity in our system, Firebase of Android

studio has been used. Firebase is integrated to Android Studio and provides an

authentication with various sign-in-methods including Email/Password, Phone,

Google, Microsoft. For our project, the authentication method has been set to

Email/Password. Therefore the login screen has to be designed in a way to allow

to user enter his email and password.

Page 44: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 34 -

Fig. 3.9 Login layout interface

4.1.2) Main Screen

The general arrangement of the main screen is shown on Fig. 3.10. The main

screen consists of the streaming layout, the toggle button, gauges and the

temperature and humidity displays. All the elements in the main menu address the

user requirements mentioned in section 2.

The streaming layout allows the user to remotely retrieve the video from the

camera. The temperature Gauge provides the user with a graphic display of the

temperature collected by the DHT11 sensor. The temperature view displays directly

the numerical value of the temperature collected by the sensor. The Humidity

Page 45: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 35 -

Gauge provides the user with a graphic display of humidity collected by the

DHT11 sensor. The humidity view displays directly the numerical value of the

humidity. The five (05) toggle buttons each allows the user to remotely control

the electronic devices connected to them.

Fig. 3.10 Main interface

4.1.3) 'About' Screen

This screen is the place for the user to reach eventually the administrators of

the system. The company GL can be reached through the support desk mail and

telephone. The current version of GLIoT can also be checked and updated through

this screen. The design of the about screen is shown in Fig. 3.11.

Page 46: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 36 -

Fig. 3.11 'About' page interface

Page 47: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 37 -

IV. CONSTRUCTION AND TESTS

4.1 Construction

The final product has been manufactured and deployed in a food waste

disposer of Dowoosys Company (DOW-100). The constructed device is shown in

Fig. 4.1. The modules including the camera, the relay, the power braker and the

power breaker can be seen in Fig. 4.1.

Fig. 4.1 The device installed in a box.

Page 48: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 38 -

4.2 Tests

The functionalities of the device including live camera streaming, ON/OFF

switch and temperature and humidity retrieval have also been tested. The test was

performed in a shield room with an ambient temperature of 19℃ and with a

relative humidity of 30% RH. The video live streaming and the switch ON/OFF

functionalities are respectively shown in Figs. 4.2 and 4.3.

Fig. 4.2 Camera stream test

Page 49: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 39 -

Fig. 4.3 Switch ON/OFF test

The proposed system has also been tested according to the test standards EN

301 489-1 V2.11 , EN 301 489-17 V3.2.1, EN 61000-3-2:2014 and EN

61000-3-3:2013 which are standard tests for Electromagnetic Compatibility (EMC).

The test report revealed that the manufactured device meets the EMC standard for

radio equipment and services. The conditions of environment for the EMC test are

summarized in Table 4.1.

Page 50: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 40 -

Table 4.1 Conditions of environment of the EMC test

Shield roomTemperature 21℃Humidity 37% R.H.Pressure 1011 hPa

OATSTemperature 23℃Humidity 54 %hPaPressure 1011 hPa

Fig. 4.4 Electrostatic discharge immunity test points

Fig. 4.4 shows points for electrostatic discharge immunity tests. Fig. 4.5 shows

a setup for conducted emission tests. Figs. 4.6 and 4.7 show a setup for radiated

emissions below 1GHz and above 1GHz respectively. Fig. 4.8 shows a setup for

radiated RF immunity tests.

Page 51: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 41 -

Fig. 4.5 Conducted emission measurement set-up

Fig. 4.6 Radiated emission (below 1GHz) measurement set-up

Page 52: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 42 -

Fig. 4.7 Radiated emission (above 1GHz) measurement set-up

Fig. 4.8 Radiated RF immunity set-up

Page 53: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 43 -

4.3 Future work

Future improvements of our device as well as of the mobile application

include an alarm setting interface. This interface will allow the user to set a timer

for automatic turn ON/OFF functionalities of the food waste processor. The model

of the alarm functionality is described by the use case diagram and the sequence

diagram shown in Figs. 4.9 and 4.10.

Fig. 4.9 SetAlarm use case diagram

Page 54: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 44 -

Fig. 4.10 SetAlarm sequence diagram

Page 55: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 45 -

V. CONCLUSION

The objective of this thesis is to design and implement a smartphone-based

remote monitoring device for food waste processing machines. The device should

integrate a temperature sensing and monitoring through an intuitive Android

mobile application. This thesis describes the design process of the device and the

development process of the mobile application.

First, the thesis describes the device and proposes a global architecture. The

device will manage physical quantities including temperature and humidity. The

components of the device were described and analyzed. The specifications for the

devices have also been collected to determine the electronic products to be used

in the design of the device.

The thesis analyzes the communication between the components of the devices.

The communication analysis included the description of the communication

interface and the data format used by each component. The WIFI protocol is

chosen for data collection, transmission and storage as well as for the

communication between the main module and the mobile application.

The mobile application design has also been presented. A model of the mobile

application has been analyzed using UML class diagrams, use case diagrams and

sequence diagrams. After that the design of the user interfaces is presented.

Finally, the constructed device is presented and the tests are performed. The test

Page 56: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 46 -

reports show that the device developed in this thesis meets performance

specifications.

Page 57: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 47 -

REFERENCES

[1] R. S. Chathish and M. S. H. Prasad, "WAP and SMS based emerging

techniques for remote monitoring and control of a process plant", Proc. ICSP

'04, Beijing, China, 31 Aug. - 4 Sep. 2004, p. 2672-2675

[2] [Online], consulted 22/04/2019

https://howtomechatronics.com/tutorials/arduino/how-i2c-communication-works-and

-how-to-use-it-with-arduino/

[3] ESP8266EX Datasheet [Online],

https://www.espressif.com/sites/default/files/documentation/0a-esp8266ex_datasheet

_en.pdf consulted 24/04/2019

[4] R. Piyare and S. R. Lee, “Smart Home-control and Monitoring system using

smart phone”, Proc. 1st Int. Conf. Converg. Appl. (ICCA), Vol. 24, pp. 83-86,

2013

[5] N. M. Meijis adn F. P. Voorwinden, “Remote mobile control of home

applicances”, Consum. Electron., Vol. 49, No. 1, pp. 123-127, 2003

[6] Arduino, ArduCAM ESP8266 UNO board User Guide, Rev 1.0, Apr 2016

[7] Espressif Sstems, “ESP8266EX dtasheet”, v. 6.0, 2018

[8] [Online], consulted on 08 May 2019

http://www.arducam.com/product/arducam-2mp-spi-camera-b0067-arduino/

[9] [Online] consulted on 09 May 2019

Page 58: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 48 -

http://www.fecegypt.com/uploads/dataSheet/1480848003_2_channel_5v_10a_relay_

module.pdf

[10] Firebase Realtime Database [Online] consulted on 09 May 2019

https://firebase.google.com/docs/database/?gclid=CjwKCAjw_MnmBRAoEiwAPR

RWWy61ehy1emIjVcqvstIsW0HM5CfrE2RG3DdhfwaLQNi6iCXotMucuxoC9qcQ

AvD_BwE

[11] OSEPP Electronics, DHT11 Humidity & Temperature Sensor, available online

[12] A. Dennis, B. H. Wixon, and R. M. Roth, System Analysis and Design 5th

Ed., New York: John Wiley & Sons, 2000

[13] [Online] consulted on 09 March 2019

https://en.wikipedia.org/wiki/Systems_design

[14] [Online] consulted on 01 April 2019

https://en.wikipedia.org/wiki/Unified_Modeling_Language

[15] S. S. Alhir, Learning UML, Sebastopol, CA: O'Reilly & Associates, 2003

[16] [Online] consulted on 05 April 2019

https://en.wikipedia.org/wiki/Use_case_diagram

[17] [Online] consulted on 09 April 2019

https://en.wikipedia.org/wiki/Sequence_diagram

[18] [Online] consulted on 10 April 2019

https://developer.android.com/guide/topics/ui/declaring-layout

Page 59: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 49 -

APPENDIX

Program Listing

A.1 WiFi Connection and Video Streaming Program

#include <ESP8266WiFi.h>#include <WiFiClient.h>#include <ESP8266WebServer.h>#include <ESP8266mDNS.h>#include <Wire.h>#include <ArduCAM.h>#include <SPI.h>#include "memorysaver.h"#if !(defined ESP8266 )#error Please select the ArduCAM ESP8266 UNO board in the Tools/Board#endif//This demo can only work on OV2640_MINI_2MP or OV2640_MINI_2MP_PLUS or ARDUCAM_SHIELD_V2 platform.#if !(defined (OV2640_MINI_2MP)||defined (OV2640_MINI_2MP_PLUS)||defined (OV5640_MINI_5MP_PLUS) || defined (OV5642_MINI_5MP_PLUS) \ || defined (OV5642_MINI_5MP) || defined (OV5642_MINI_5MP_BIT_ROTATION_FIXED) \ ||(defined (ARDUCAM_SHIELD_V2) && (defined (OV2640_CAM) || defined (OV5640_CAM) || defined (OV5642_CAM))))#error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file#endif// set GPIO16 as the slave select :const int CS = 16;

//you can change the value of wifiType to select Station or AP mode.//Default is AP mode.int wifiType = 0; // 0:Station 1:AP//AP mode configuration//Default is arducam_esp8266.If you want,you can change the AP_aaid to your favorite nameconst char *AP_ssid = "arducam_esp8266";//Default is no password.If you want to set password,put your password here

Page 60: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 50 -

const char *AP_password = "";//Station mode you should put your ssid and passwordconst char *ssid = "gliot"; // Put your SSID hereconst char *password = "gliot1234"; // Put your PASSWORD herestatic const size_t bufferSize = 4096;static uint8_t buffer[bufferSize] = {0xFF};uint8_t temp = 0, temp_last = 0;int i = 0;bool is_header = false;

ESP8266WebServer server(350);//PORT

#if defined (OV2640_MINI_2MP) ||defined (OV2640_MINI_2MP_PLUS)|| defined (OV2640_CAM)ArduCAM myCAM(OV2640, CS);#elif defined (OV5640_MINI_5MP_PLUS) || defined (OV5640_CAM)ArduCAM myCAM(OV5640, CS);#elif defined (OV5642_MINI_5MP_PLUS) || defined (OV5642_MINI_5MP) || defined (OV5642_MINI_5MP_BIT_ROTATION_FIXED) ||(defined (OV5642_CAM))ArduCAM myCAM(OV5642, CS);#endifvoid start_capture() { myCAM.clear_fifo_flag(); myCAM.start_capture();}void camCapture(ArduCAM myCAM) { WiFiClient client = server.client(); uint32_t len = myCAM.read_fifo_length(); if (len >= MAX_FIFO_SIZE) //8M { Serial.println(F("Over size.")); } if (len == 0 ) //0 kb { Serial.println(F("Size is 0.")); } myCAM.CS_LOW(); myCAM.set_fifo_burst(); if (!client.connected()) return; String response = "HTTP/1.1 200 OK\r\n"; response += "Content-Type: image/jpeg\r\n"; response += "Content-len: " + String(len) + "\r\n\r\n"; server.sendContent(response); i = 0; while ( len-- )

Page 61: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 51 -

{ temp_last = temp; temp = SPI.transfer(0x00); //Read JPEG data from FIFO if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while, { buffer[i++] = temp; //save the last 0XD9 //Write the remain bytes in the buffer if (!client.connected()) break; client.write(&buffer[0], i); is_header = false; i = 0; myCAM.CS_HIGH(); break; } if (is_header == true) { //Write image data to buffer if not full if (i < bufferSize) buffer[i++] = temp; else { //Write bufferSize bytes image data to file if (!client.connected()) break; client.write(&buffer[0], bufferSize); i = 0; buffer[i++] = temp; } } else if ((temp == 0xD8) & (temp_last == 0xFF)) { is_header = true; buffer[i++] = temp_last; buffer[i++] = temp; } }}void serverCapture() { myCAM.flush_fifo(); myCAM.clear_fifo_flag(); start_capture(); Serial.println(F("CAM Capturing")); int total_time = 0; total_time = millis(); while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));

Page 62: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 52 -

total_time = millis() - total_time; Serial.print(F("capture total_time used (in miliseconds):")); Serial.println(total_time, DEC); total_time = 0; Serial.println(F("CAM Capture Done.")); total_time = millis(); camCapture(myCAM); total_time = millis() - total_time; Serial.print(F("send total_time used (in miliseconds):")); Serial.println(total_time, DEC); Serial.println(F("CAM send Done."));}

void serverStream() { WiFiClient client = server.client(); String response = "HTTP/1.1 200 OK\r\n"; response += "Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n"; server.sendContent(response); while (1) { start_capture(); while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)); size_t len = myCAM.read_fifo_length(); if (len >= MAX_FIFO_SIZE) //8M { Serial.println(F("Over size.")); continue; } if (len == 0 ) //0 kb { Serial.println(F("Size is 0.")); continue; } myCAM.CS_LOW(); myCAM.set_fifo_burst(); if (!client.connected()) { Serial.println("break"); break; } response = "--frame\r\n"; response += "Content-Type: image/jpeg\r\n\r\n"; server.sendContent(response); while ( len-- ) { temp_last = temp; temp = SPI.transfer(0x00); //Read PEG data from FIFO

Page 63: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 53 -

if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while, { buffer[i++] = temp; //save the last 0XD9 //Write the remain bytes in the buffer myCAM.CS_HIGH();; if (!client.connected()) { client.stop(); is_header = false; break; } client.write(&buffer[0], i); is_header = false; i = 0; } if (is_header == true) { //Write image data to buffer if not full if (i < bufferSize) buffer[i++] = temp; else { //Write bufferSize bytes image data to file myCAM.CS_HIGH(); if (!client.connected()) { client.stop(); is_header = false; break; } client.write(&buffer[0], bufferSize); i = 0; buffer[i++] = temp; myCAM.CS_LOW(); myCAM.set_fifo_burst(); } } else if ((temp == 0xD8) & (temp_last == 0xFF)) { is_header = true; buffer[i++] = temp_last; buffer[i++] = temp; } } if (!client.connected()) { client.stop(); is_header = false; break; } }}void handleNotFound() { String message = "Server is running!\n\n";

Page 64: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 54 -

message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET) ? "GET" : "POST"; message += "\nArguments: "; message += server.args(); message += "\n"; server.send(200, "text/plain", message); if (server.hasArg("ql")) { int ql = server.arg("ql").toInt();#if defined (OV2640_MINI_2MP) ||defined (OV2640_MINI_2MP_PLUS)|| defined (OV2640_CAM) myCAM.OV2640_set_JPEG_size(ql);#elif defined (OV5640_MINI_5MP_PLUS) || defined (OV5640_CAM) myCAM.OV5640_set_JPEG_size(ql);#elif defined (OV5642_MINI_5MP_PLUS) || defined (OV5642_MINI_5MP_BIT_ROTATION_FIXED) ||(defined (OV5642_CAM)) myCAM.OV5642_set_JPEG_size(ql);#endif delay(1000); Serial.println("QL change to: " + server.arg("ql")); }}void setup() { uint8_t vid, pid; uint8_t temp;#if defined(__SAM3X8E__) Wire1.begin();#else Wire.begin();#endif Serial.begin(115200); Serial.println(F("ArduCAM Start!")); // set the CS as an output: pinMode(CS, OUTPUT); digitalWrite(CS, HIGH); // initialize SPI: SPI.begin(); SPI.setFrequency(4000000); //4MHz

//Reset the CPLD myCAM.write_reg(0x07, 0x80); delay(100); myCAM.write_reg(0x07, 0x00); delay(100); //Check if the ArduCAM SPI bus is OK

Page 65: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 55 -

myCAM.write_reg(ARDUCHIP_TEST1, 0x55); temp = myCAM.read_reg(ARDUCHIP_TEST1); if (temp != 0x55) { Serial.println(F("SPI1 interface Error!")); while (1); }#if defined (OV2640_MINI_2MP) ||defined (OV2640_MINI_2MP_PLUS)|| defined (OV2640_CAM) //Check if the camera module type is OV2640 myCAM.wrSensorReg8_8(0xff, 0x01); myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid); myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid); if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))) Serial.println(F("Can't find OV2640 module!")); else Serial.println(F("OV2640 detected."));#elif defined (OV5640_MINI_5MP_PLUS) || defined (OV5640_CAM) //Check if the camera module type is OV5640 myCAM.wrSensorReg16_8(0xff, 0x01); myCAM.rdSensorReg16_8(OV5640_CHIPID_HIGH, &vid); myCAM.rdSensorReg16_8(OV5640_CHIPID_LOW, &pid); if ((vid != 0x56) || (pid != 0x40)) Serial.println(F("Can't find OV5640 module!")); else Serial.println(F("OV5640 detected."));#elif defined (OV5642_MINI_5MP_PLUS) || defined (OV5642_MINI_5MP) || defined (OV5642_MINI_5MP_BIT_ROTATION_FIXED) ||(defined (OV5642_CAM)) //Check if the camera module type is OV5642 myCAM.wrSensorReg16_8(0xff, 0x01); myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); if ((vid != 0x56) || (pid != 0x42)) { Serial.println(F("Can't find OV5642 module!")); } else Serial.println(F("OV5642 detected."));#endif //Change to JPEG capture mode and initialize the OV2640 module myCAM.set_format(JPEG); myCAM.InitCAM();#if defined (OV2640_MINI_2MP) ||defined (OV2640_MINI_2MP_PLUS)|| defined (OV2640_CAM) myCAM.OV2640_set_JPEG_size(OV2640_320x240);#elif defined (OV5640_MINI_5MP_PLUS) || defined (OV5640_CAM) myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is

Page 66: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 56 -

active HIGH myCAM.OV5640_set_JPEG_size(OV5640_320x240);#elif defined (OV5642_MINI_5MP_PLUS) || defined (OV5642_MINI_5MP) || defined (OV5642_MINI_5MP_BIT_ROTATION_FIXED) ||(defined (OV5642_CAM)) myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH myCAM.OV5640_set_JPEG_size(OV5642_320x240);#endif

myCAM.clear_fifo_flag(); if (wifiType == 0) { if (!strcmp(ssid, "SSID")) { Serial.println(F("Please set your SSID")); while (1); } if (!strcmp(password, "PASSWORD")) { Serial.println(F("Please set your PASSWORD")); while (1); } // Connect to WiFi network Serial.println(); Serial.println(); Serial.print(F("Connecting to ")); Serial.println(ssid);

WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(F(".")); } Serial.println(F("WiFi connected")); Serial.println(""); Serial.println(WiFi.localIP()); } else if (wifiType == 1) { Serial.println(); Serial.println(); Serial.print(F("Share AP: ")); Serial.println(AP_ssid); Serial.print(F("The password is: ")); Serial.println(AP_password);

WiFi.mode(WIFI_AP); WiFi.softAP(AP_ssid, AP_password); Serial.println("");

Page 67: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 57 -

Serial.println(WiFi.softAPIP()); }

// Start the server server.on("/capture", HTTP_GET, serverCapture); server.on("/stream", HTTP_GET, serverStream); server.onNotFound(handleNotFound); server.begin(); Serial.println(F("Server started"));}

void loop() { server.handleClient();}

Page 68: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 58 -

A.2 Temperature/Humidity Readout Program

#include <ESP8266WiFi.h>#include <FirebaseArduino.h>

//Temperature and Humidity#include "dht.h"dht DHT;#define dht_apin 2//Firebase#define FIREBASE_HOST "gliot-874eb.firebaseio.com"#define FIREBASE_AUTH "iL5YwwrfWGcAuc4MVfHpUKLvSvFbNDzYusfYlZ2d"//Wifi #define WIFI_SSID "gliot"#define WIFI_PASSWORD "gliot1234"void setup() {Serial.begin(9600); pinMode(port1, OUTPUT); pinMode(port2, OUTPUT); pinMode(port3, OUTPUT); pinMode(port4, OUTPUT); pinMode(port5, OUTPUT);// connect to wifi.WiFi.begin(WIFI_SSID, WIFI_PASSWORD);Serial.print("connecting");while (WiFi.status() != WL_CONNECTED) {Serial.print(".");delay(500);}Serial.println();Serial.print("connected: ");Serial.println(WiFi.localIP());

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);delay(1000);

}

void loop() {//String result = Firebase.getString("/led1/status");if(Firebase.failed()){ Serial.println("Failure"); Serial.println(Firebase.error()); }

Page 69: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 59 -

DHT.read11(dht_apin); float h = DHT.humidity; //Serial.println(h); float t = DHT.temperature; //Serial.println(t);

Firebase.setString("temp/tempVal", String(t)); delay(300); Firebase.setString("hum/humVal", String(h)); delay(1000);}

Page 70: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 60 -

A.3 Relay Control Program

#include <ESP8266WiFi.h>#include <FirebaseArduino.h>//Temperature and Humidity#include "dht.h"dht DHT;#define dht_apin 2//Firebase#define FIREBASE_HOST "gliot-874eb.firebaseio.com"#define FIREBASE_AUTH "iL5YwwrfWGcAuc4MVfHpUKLvSvFbNDzYusfYlZ2d"//Wifi #define WIFI_SSID "gliot"#define WIFI_PASSWORD "gliot1234"

//Relayint port1 = 14;//14int port2 = 4;//4int port3 = 5;//5int port4 = 13;//13int port5 = 12;// void setup() {Serial.begin(9600); pinMode(port1, OUTPUT); pinMode(port2, OUTPUT); pinMode(port3, OUTPUT); pinMode(port4, OUTPUT); pinMode(port5, OUTPUT);// connect to wifi.WiFi.begin(WIFI_SSID, WIFI_PASSWORD);Serial.print("connecting");while (WiFi.status() != WL_CONNECTED) {Serial.print(".");delay(500);}Serial.println();Serial.print("connected: ");Serial.println(WiFi.localIP());Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);delay(1000);

}void loop() {//String result = Firebase.getString("/led1/status");if(Firebase.failed())

Page 71: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 61 -

{ Serial.println("Failure"); Serial.println(Firebase.error()); }if(Firebase.getString("/led1/status") == "on"){ digitalWrite(port1, 0); }else{ digitalWrite(port1, 1); }delay(1000); if(Firebase.getString("/led2/status") == "on"){ digitalWrite(port2, 0); }else{ digitalWrite(port2, 1); } delay(500); if(Firebase.getString("/led3/status") == "on"){ digitalWrite(port3, 0); }else{ digitalWrite(port3, 1); } delay(500); if(Firebase.getString("/led4/status") == "on"){ digitalWrite(port4, 0); }else{ digitalWrite(port4, 1); } delay(500); if(Firebase.getString("/led5/status") == "on"){ digitalWrite(port5, 0); }else{ digitalWrite(port5, 1); } delay(500); }

Page 72: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 62 -

A.4 Smartphone Application

package com.example.gorokssoft.myiot;import android.app.ProgressDialog;import android.bluetooth.BluetoothGatt;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.os.Handler;import android.preference.PreferenceManager;import android.support.annotation.NonNull;import android.support.v4.widget.SwipeRefreshLayout;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.Editable;import android.text.TextWatcher;import android.util.Log;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.webkit.WebChromeClient;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.Button;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import android.widget.ToggleButton;import com.android.volley.Request;import com.android.volley.RequestQueue;import com.android.volley.Response;import com.android.volley.VolleyError;import com.android.volley.toolbox.StringRequest;import com.android.volley.toolbox.Volley;import com.google.android.gms.tasks.OnCompleteListener;import com.google.android.gms.tasks.Task;import com.google.firebase.database.DataSnapshot;import com.google.firebase.database.DatabaseError;import com.google.firebase.database.DatabaseReference;import com.google.firebase.database.FirebaseDatabase;import com.google.firebase.database.ValueEventListener;import org.json.JSONArray;import org.json.JSONException;

Page 73: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 63 -

import org.json.JSONObject;import de.nitri.gauge.Gauge;

public class MainActivity extends AppCompatActivity {

ProgressDialog dialog;

Context context = this; private final String SERVER_ADDRESS = "https://myiotgl.000webhostapp.com/api/weather/Old/Select_last.php"; Gauge tempTv, humTv; private ToggleButton D1on, D2on, D3on, D4on, D5on; private WebView myWebview; private SwipeRefreshLayout swipeRefreshLayout; private TextView tempTV1, humTV1; private EditText text1, text2, text3, text4, text5;

private ProgressDialog progressDialog;

//Database FirebaseDatabase databse = FirebaseDatabase.getInstance(); DatabaseReference myRef = databse.getReference();

final DatabaseReference ledstate1 = myRef.child("led1").child("status"); final DatabaseReference ledstate2 = myRef.child("led2").child("status"); final DatabaseReference ledstate3 = myRef.child("led3").child("status"); final DatabaseReference ledstate4 = myRef.child("led4").child("status"); final DatabaseReference ledstate5 = myRef.child("led5").child("status"); final DatabaseReference humidity = myRef.child("hum").child("humVal"); final DatabaseReference temperature = myRef.child("temp").child("tempVal");

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tempTv = (Gauge) findViewById(R.id.tempTV); humTv = (Gauge) findViewById(R.id.humTV); tempTV1 = (TextView) findViewById(R.id.tempTV1);

Page 74: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 64 -

humTV1 = (TextView) findViewById(R.id.humTV1);

text1 = (EditText) findViewById(R.id.textView3); text2 = (EditText) findViewById(R.id.textView4); text3 = (EditText) findViewById(R.id.textView5); text4 = (EditText) findViewById(R.id.textView6); text5 = (EditText) findViewById(R.id.textView7);

//Saving the changes on the EditText fields SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); final SharedPreferences.Editor editor = prefs.edit();

//Retrieving the Data text1.setText(prefs.getString("text1", "")); text2.setText(prefs.getString("text2", "")); text3.setText(prefs.getString("text3", "")); text4.setText(prefs.getString("text4", "")); text5.setText(prefs.getString("text5", ""));

text1.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override public void afterTextChanged(Editable s) { editor.putString("text1", s.toString()); editor.apply(); } });

text2.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

Page 75: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 65 -

@Override public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override public void afterTextChanged(Editable s) { editor.putString("text2", s.toString()); editor.apply();

} }); text3.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override public void afterTextChanged(Editable s) { editor.putString("text3", s.toString()); editor.apply();

} }); text4.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override public void onTextChanged(CharSequence s, int start, int before, int count) {

}

Page 76: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 66 -

@Override public void afterTextChanged(Editable s) { editor.putString("text4", s.toString()); editor.apply(); } }); text5.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override public void afterTextChanged(Editable s) { editor.putString("text5", s.toString()); editor.apply();

} });

progressDialog = new ProgressDialog(this);

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);

swipeRefreshLayout.setColorSchemeResources(R.color.swipe1, R.color.swipe2, R.color.swipe3);

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeRefreshLayout.setRefreshing(true); (new Handler()).postDelayed(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(false);

Page 77: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 67 -

streamVideo(); //getState(); getData(); updateLED(); } }, 3000);

} });

D1on = (ToggleButton) findViewById(R.id.onoff1); D2on = (ToggleButton) findViewById(R.id.onoff2); D3on = (ToggleButton) findViewById(R.id.onoff3); D4on = (ToggleButton) findViewById(R.id.onoff4); D5on = (ToggleButton) findViewById(R.id.onoff5);

streamVideo();

getState();

getData();

updateLED();

}

@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; }

@Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == R.id.settings) { startActivity(new Intent(MainActivity.this, Settings.class));

}

return super.onOptionsItemSelected(item);

}

Page 78: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 68 -

private void streamVideo(){ myWebview = (WebView) findViewById(R.id.stream); String url = "https://youtu.be/bccFAIiyaEI"; String frameVideo = "<html><head> <meta name=\"viewport\" content=\"width=device-width, minimum-scale=0.1\"> </head> <body style=\"margin: 0px; background: #757575;\"> <img style=\"webkit-user-select: none;\" src=\"http://gliot.iptime.org:350/stream\" width=\"100%\" height=\"100%\"></body></html>";

myWebview.getSettings().setJavaScriptEnabled(true);

myWebview.setWebChromeClient(new WebChromeClient()); myWebview.loadData(frameVideo, "text/html", "utf-8");

myWebview.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return false; } });

}

private void getData() { humidity.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { Log.d("file", "humidity is+" +dataSnapshot.getValue().toString()); humTV1.setText(dataSnapshot.getValue().toString()+"%"); humTv.setValue(Float.parseFloat(dataSnapshot.getValue().toString())); }

@Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value",

Page 79: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 69 -

databaseError.toException());

} });

temperature.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { Log.d("file", "temperature is+" +dataSnapshot.getValue().toString()); tempTV1.setText(dataSnapshot.getValue().toString()+"\u00B0"+"C"); tempTv.setValue(Float.parseFloat(dataSnapshot.getValue().toString())); }

@Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value", databaseError.toException());

} });

}

private void updateLED(){

D1on.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled progressDialog.setMessage("Updating..."); progressDialog.show(); ledstate1.setValue("on").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void>

Page 80: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 70 -

task) { if(task.isSuccessful()){ D1on.setBackground(getResources().getDrawable(R.drawable.circle_button)); D1on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D1on.setChecked(false); }

} });

} else {

progressDialog.setMessage("Updating..."); progressDialog.show(); ledstate1.setValue("off").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D1on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked)); D1on.setTextColor(getResources().getColor(R.color.colorAccent)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D1on.setChecked(true); }

Page 81: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 71 -

} });

} } });

D2on.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled progressDialog.setMessage("Updating..."); progressDialog.show();

ledstate2.setValue("on").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D2on.setBackground(getResources().getDrawable(R.drawable.circle_button2)); D2on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D2on.setChecked(false); }

} });

Page 82: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 72 -

} else {

progressDialog.setMessage("Updating..."); progressDialog.show(); ledstate2.setValue("off").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D2on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked2)); D2on.setTextColor(getResources().getColor(R.color.unchecked2)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D2on.setChecked(true); }

} });

} } });

D3on.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled progressDialog.setMessage("Updating..."); progressDialog.show();

ledstate3.setValue("on").addOnCompleteListener(new

Page 83: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 73 -

OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D3on.setBackground(getResources().getDrawable(R.drawable.circle_button3)); D3on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D3on.setChecked(false); }

} });

} else {

progressDialog.setMessage("Updating..."); progressDialog.show(); ledstate3.setValue("off").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D3on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked3)); D3on.setTextColor(getResources().getColor(R.color.unchecked3)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this,

Page 84: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 74 -

"Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D3on.setChecked(true); }

} });

} } });

D4on.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled progressDialog.setMessage("Updating..."); progressDialog.show();

ledstate4.setValue("on").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D4on.setBackground(getResources().getDrawable(R.drawable.circle_button4)); D4on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D4on.setChecked(false); }

}

Page 85: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 75 -

});

} else {

progressDialog.setMessage("Updating..."); progressDialog.show(); ledstate4.setValue("off").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D4on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked4)); D4on.setTextColor(getResources().getColor(R.color.unchecked4)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D4on.setChecked(true); }

} });

} } });

D5on.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled progressDialog.setMessage("Updating..."); progressDialog.show();

Page 86: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 76 -

ledstate5.setValue("on").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D5on.setBackground(getResources().getDrawable(R.drawable.circle_button5)); D5on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D5on.setChecked(false); }

} });

} else {

progressDialog.setMessage("Updating..."); progressDialog.show(); ledstate5.setValue("off").addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ D5on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked5)); D5on.setTextColor(getResources().getColor(R.color.unchecked5)); progressDialog.dismiss(); Toast.makeText(MainActivity.this, "Update Successful", Toast.LENGTH_SHORT).show(); }else{ progressDialog.dismiss();

Page 87: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 77 -

Toast.makeText(MainActivity.this, "Update Failed...Try Again", Toast.LENGTH_SHORT).show(); D5on.setChecked(true); }

} });

} } });

}

private void getState(){ ledstate1.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue().toString(); Log.d("file", "Value is+" +value); if(value.equals("on")){ D1on.setChecked(true); D1on.setBackground(getResources().getDrawable(R.drawable.circle_button)); D1on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); }else{ D1on.setChecked(false); D1on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked)); D1on.setTextColor(getResources().getColor(R.color.colorAccent)); } }

@Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value", databaseError.toException());

Page 88: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 78 -

} });

ledstate2.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue().toString(); Log.d("file", "Value is+" +value); if(value.equals("on")){ D2on.setChecked(true); D2on.setBackground(getResources().getDrawable(R.drawable.circle_button2)); D2on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); }else{ D2on.setChecked(false); D2on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked2)); D2on.setTextColor(getResources().getColor(R.color.unchecked2)); } }

@Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value", databaseError.toException());

} });

ledstate3.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue().toString(); Log.d("file", "Value is+" +value); if(value.equals("on")){ D3on.setChecked(true); D3on.setBackground(getResources().getDrawable(R.drawable.circle_b

Page 89: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 79 -

utton3)); D3on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); }else{ D3on.setChecked(false); D3on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked3)); D3on.setTextColor(getResources().getColor(R.color.unchecked3)); } }

@Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value", databaseError.toException());

} });

ledstate4.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue().toString(); Log.d("file", "Value is+" +value); if(value.equals("on")){ D4on.setChecked(true); D4on.setBackground(getResources().getDrawable(R.drawable.circle_button4)); D4on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); }else{ D4on.setChecked(false); D4on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked4)); D4on.setTextColor(getResources().getColor(R.color.unchecked4)); } }

Page 90: Master of Engineering Thesis Design of A Smartphone-based ...ael.cbnu.ac.kr/AEL-results/theses/코알라/코알라(2019-8).pdfDesign of A Smartphone-based Remote Monitoring Device

- 80 -

@Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value", databaseError.toException());

} });

ledstate5.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue().toString(); Log.d("file", "Value is+" +value); if(value.equals("on")){ D5on.setChecked(true); D5on.setBackground(getResources().getDrawable(R.drawable.circle_button5)); D5on.setTextColor(getResources().getColor(R.color.colorLightPrimary)); }else{ D5on.setChecked(false); D5on.setBackground(getResources().getDrawable(R.drawable.circle_buttonunchecked5)); D5on.setTextColor(getResources().getColor(R.color.unchecked5)); } } @Override public void onCancelled(@NonNull DatabaseError databaseError) { Log.d("file", "Failed to read Value", databaseError.toException());

} }); }

}