Download as pdf or txt
Download as pdf or txt
You are on page 1of 111

DESIGN AND VALIDATION OF A REMOTE PH MONITORING SYSTEM

USING INTERNET OF THINGS TECHNOLOGY

CHUKWU, CHIMDI OGBONNAYA


B.ENG (MOUAU)
G2015/MENG/ELECT/FT/638

DEPARTMENT OF ELECTRICAL/ELECTRONIC ENGINEERING,

FACULTY OF ENGINEERING,

SCHOOL OF GRADUATE STUDIES

UNIVERSITY OF PORT HARCOURT

Supervisor APRIL, 2019


ENGR. (DR.) S. I. ORAKWUE
TITLE PAGE

DESIGN AND VALIDATION OF A REMOTE PH MONITORING SYSTEM USING


INTERNET OF THINGS TECHNOLOGY

CHUKWU, CHIMDI OGBONNAYA


B.ENG (MOUAU)
G2015/MENG/ELECT/FT/638

DEPARTMENT OF ELECTRICAL/ELECTRONIC ENGINEERING,

FACULTY OF ENGINEERING,

SCHOOL OF GRADUATE STUDIES

UNIVERSITY OF PORT HARCOURT

Supervisor APRIL, 2019


ENGR. (DR.) S. I. ORAKWUE

i
DECLARATION

I, CHUKWU, CHIMDI OGBONNAYA with Registration Number G2015/MENG/ELECT/FT/638


declare that this dissertation on: DESIGN AND VALIDATION OF A REMOTE PH
MONITORING SYSTEM USING INTERNET OF THINGS TECHNOLOGY was carried
out by me; that it is my original work and that it has not been submitted wholly or in part for the
award of a degree in any institution.

_________________________ _____________________

SIGNATURE DATE

ii
CERTIFICATION

This is to certify that the thesis presented by Chukwu, Chimdi Ogbonnaya with the matriculation

number G2015/MENG/ELECT/FT/638 of the Department of Electrical/Electronic Engineering

meets the requirements of thesis report for the award of Masters of Engineering degree in the Faculty

of Engineering, University of Port Harcourt, Rivers State, Nigeria.

DR. (MRS.) STELLA I. ORAKWUE ____________________ __________________

(Supervisor) Signature Date

DR. ESEOSA OMORUGUIWA ____________________ __________________

(Head of Department) Signature Date

EXTERNAL SUPERVISOR ____________________ __________________

Signature Date

iii
DEDICATION

This work is dedicated to God Almighty, the author and finisher of our faith. I would like to also

dedicate this work to my father, Mr. C.C. Chukwu, for his reaffirmed faith in me while running this

programme, until its completion.

iv
ACKNOWLEDGEMENTS

I profoundly thank the Almighty God for his mercy, grace and faithfulness for seeing me through

my Master’s Degree programme. I thank my amiable supervisor, Dr S. I. Orakwue, for her priming

and growth stimulating supervision...your efforts will not be forgotten.

v
ABSTRACT
The world is in the era of the Internet of Things (IoT), where both sensors, machines, home
appliances, and everday devices can communicate with each other over a Local Area Network or
the internet at large. This work proposes a remote system for monitoring pH levels for fish tanks
based on IoT technology. Various literature were studied in order to determine the pH conditions
which are considered as favourable for the growth of catfish fingerlings. It was realized that catfish,
in their life span, are most vulnerable as fingerlings.A remote pH monitoring system was proposed
to attempt solving this problem. A microcontroller-based pH monitoring unit was assembled,
configured and programmed with wireless communication capabilities using the IEEE 802.11x
standard. The proposed system was also programmed to send pH information to remote clients in
the LAN. WebSocket technology in combination with JavaScript was used to stream real-time pH
information to the remote client’s browser. The proposed model is based on the linear relationship
between pH levels of substances and the corresponding DC voltage readings gotten from the pH
meter. The established linear model was applied to the microcontroller’s source code which then
was used to confirm the buffer solutions’ pH level. The developed system can send email alerts when
exposed to unfavourable pH conditions. Water samples were taken from a fish tank at the case study
premises each day for two working weeks. Each day’s sample was measured both electronically
using the proposeded remote monitoring system and traditionally using a pH reagent. The daily
results, using both approaches, were compared and their relative differences were calculated. The
developed IoT based remote monitoring system was noted to operate with accuracy in the range of
±0.2, thereby validated the design of the proposed remote pH monitoring system.

vi
TABLE OF CONTENTS

TITLE PAGE i
DECLARATION ii
CERTIFICATION iii
DEDICATION iv
ACKNOWLEDGEMENTS v
ABSTRACT vi
INTRODUCTION 1
1.1 Background of Study 1
1.2 Statement of Problem 2
1.3 The aim of this Work 5
1.4 The objectives of this Work 5
1.5 The scope of the Work 5
1.6 The significance of the Work 6
1.7 Organization of this Work 6
2 LITERATURE REVIEW 8
2.1 Microcontrollers 8
2.2 Analogue to Digital Converter (ADC) 9
2.2.1 Relating ADC value to Voltage 9
2.3 TCP/IP 11
2.4 Simple Mail Transfer Protocol 11
2.5 Internet of Things 11
2.6 Wireless Sensor Network 13
2.7 pH 13
2.7.1 Impact of pH level on catfish 17
2.7.2 Buffer Solution 17
2.7.3 pH Reagent 17
2.8 Water Quality Parameters and their Standard Values 18
2.9 Local Area Network 20
2.10 African Catfish 20
2.11 Related Works 20
RESEARCH METHODOLOGY 23
3.1 Research Design 23
3.2 Description of the Case Study 23
3.3 Materials 26
3.3.1 Hardware Components 26

vii
3.3.2 Software Components 31
3.3.3 Chemical Materials 32
3.4 Methods 32
3.4.1 Components Assembly and Configuration 33
3.4.2 Calibration of the Sensing Unit 34
3.4.3 Email Alert System Setup 36
3.4.4 Real life pH Sensing Unit testing 37
3.4.5 Manual pH measurement of Test Samples 37
RESULTS AND DISCUSSIONS 40
4.1 Results and Validation 40
4.1.1 System Network 40
4.1.2 pH Measurement Subsystem 42
4.1.3 Email Alerting Subsystem 46
4.1.4 Result Validation 47
4.1.5 Bill of Engineering Materials and Evaluation 49
SUMMARY, CONCLUSIONS AND RECOMMENDATIONS 50
5.1 Summary 50
5.2 Conclusions 50
5.3 Recommendations 51
5.4 Limitations of this Work 51
5.5 Contribution to Knowledge 52
APPENDIX - A 57
APPENDIX – B 60
APPENDIX - C 63
APPENDIX - D 68
APPENDIX - E 83
APPENDIX - G 95

viii
LIST OF FIGURES

2.1 A Picture of a PIC16F84A Microcontroller (Microchip, 2017) 10

2.2 An Ideal Transfer Curve of a 3-bit ADC (CMM, 2017) 10

2.3 A pH-acid volume relationship graph showing increasing Acidity (Clark, 2013) 15

2.4 A pH-alkali volume relationship graph showing increasing Alkalinity (Clark, 2013) 15

2.5 The inverse relationship between H+ and OH- ions (Finesse, 2005) 16

3.1 Workflow of the research design 25

3.2 Flowchart showing how the P4S-342 executes its actions 29

3.3 First off-page reference of the P4S-342 flowchart 29

3.4 Second off-page reference of the P4S-342 flowchart 30

3.5 Block Diagram of the Proposed MCU System 33

3.6 The email flowchart 37

4.1 IPv4 Network details of the microcontroller while on the WLAN 40

4.2 A network diagram of the pH monitoring system 40

4.3 A serial output of the system when measuring from the buffer 7 solution 41

4.4 A serial output of the system when measuring from the buffer 9.2 solution 42

4.5 Real-time remote pH value display from the buffer 4 solution 43

4.6 Real-time remote pH value display from the buffer 7 solution 44

4.7 Real-time remote pH value display from the buffer 9.2 solution 45

4.8 An email alert received from the pH monitoring system 46

4.9 The relative error of pH values of water samples taken on various days 47

ix
LIST OF TABLES

2.1 The table shows the TCP/IP protocol layers (Oracle, 2010) 12

2.2 Water quality parameters and their standard values (Banrie, 2012), (Towers, 2014) 19

3.1 Specification of the pH sensor according to (DFrobot, 2016) 28

3.2 Hardware Specification of the P4S-342 microcontroller (Sollae Systems, 2017) 28

3.3 Software specification of the P4S-342 (Sollae Systems, 2017) 28

3.4 Buffers 4, 7, and 9.2 solutions voltage reading during pH meter insertion 36

3.5 The average voltage readings used to establish the straight line equation 35

4.1 Comparison between electronic and traditional pH measurement approaches 47

4.2 Bill of Engineering Materials and Evaluation for this work 48

x
LIST OF ACRONYMS

ADC Analog-to-Digital Converter

BEME Bill of Engineering Materials and Evaluation

DAC Digital-to-Analog Converter

DIC Dissolved Inorganic Carbon

DNS Domain Name Services

HTTP Hypertext Markup Language

IMAP Internet Mail Access Protocol

IP Internet Protocol

LAN Local Area Network

MCU Microcontroller Unit

PC Personal Computer

POP Post Office Protocol

SMTP Simple Mail Transfer Protocol

TCP Transmission Control Protocol

WLAN Wireless Local Area Network

xi
CHAPTER ONE

INTRODUCTION

Agriculture has come a long way from the stone age where farming was done with

stones and stick to this point where machinery is used and productivity is increased in

correspondence. According to (Verma, 2006), farm mechanization increased

agricultural productivity and profitability.

Agriculture is a lifestyle and a system which in any society provides avenues for food

security and revenue generation. The need for people to have multiple income streams

has led to fish farming becoming an option as means out of immiserization. Many

people delve into the business of fish farming with expectations of breaking even as

early as possible while starting with very little business capital. Farmers would like to

cut cost by running a minimal payroll while trying to maximize profit from production.

Adult fish size is a reflection of its environmental history in a fish’s life while growing

up. The size of adult fish translates to higher prices per fish.

High water quality is an essential and contributory factor to a fish farm’s success

(Towers, 2014). Effective situation data reception from aquaculture setups will enable

farmers to make more proficient decisions in running their businesses. The deployment

of a system for alerting and monitoring will fill that gap, using low-cost electronics, the

power the internet and its technologies.

1.1 Background of Study

Fish farm activities in Nigeria are usually carried out using a manual or ‘traditional’

manner. Their daily operations include various tasks such as water changing, parameter

observation of fish ponds are all done manually. According to (Wellborn, 1987), some

of the parameters that concern most fish farmers are:

1
 Dissolved Oxygen (DO)

 pH

 Temperature

 Ammonia (NH4+)

 Nitrates (N2O-)

 Salinity

 Carbon Dioxide (CO2)

 Water Hardness

 Alkalinity

 H2S.

These parameters, though essential, may not all be considered in an actual pond. An

establishment with the ability to track a list of parameters would have to be a very large

and well-funded one. These parameters are very important in determining the water

quality where the fish live and will affect their life’s quality and development. This

goes on to have economic implications that could arise from; better-controlled water

change rate, better health and size of adult fish which means a more beneficial selling

prize. Making informed decisions is necessary, even though ensuring the parameter

levels can be difficult.

Since determining these parameters as accurately and as efficiently as possible is

substantive, an electronic system which gives the farmers a precise and vivid picture of

the water quality state and the faring of their livestock becomes necessary.

1.2 Statement of Problem

Changes in the domain status of fish fingerlings impact them greatly. Unfavourable pH

levels can be of great harm to them. These harmful conditions can cause poor

physiological development, stunted growth, mutation, and even death, as expressed by


2
(Towers, 2014). Most times, the fish tanks are drained and refilled at certain intervals,

usually depending on fish sizes. This could be of economic concerns as some routine

farm tasks could be executed – for example, water changing, feeding the fish, pH

checking, etc. - without it being absolutely necessary, and probably while on budget

constraints.

Works done with a bias towards electronic catfish monitoring have been hard to come

by. Most literature talk about systems developed with the intent of introducing fish into

the system, just as done by (Rao, et al., 2013). But a work done by (Africa, Aguilar,

Lim, Pacheco, & Rodrin, 2017) was done with the interaction of Tilapia fish in the

monitored aquaculture, with the use of pH, temperature, dissolved oxygen and

ammonia sensors. There are needs for such study to be done with catfish in mind,

especially at the fingerling stage when they are most vulnerable in acidic conditions

(Mustapha & Mohammed, 2018) and alkaline conditions (Tucker & D'Abramo, 2008).

The cost of starting and running most of the existing systems is a big concern. There is

a great need to cut cost as much as possible. (Zhang et al., 2011) came up with a system

that monitored pH, temperature, water level, and dissolved oxygen, while (Ramya,

Balaji, & Akilan, 2015) built a system to monitor pH, temperature, water level, total

dissolved solids and dissolved oxygen. But both (Zhang et al., 2011) and (Ramya et al.,

2015) used SMS messaging as their choice of alert medium. Even though it is easier to

use SMS since mobile phones are very rampant, the use of SMS services is usually

known to incur costs. The use of email services as a form of alert from aquaculture

systems will be a good approach due to the affordable cost of internet service

subscriptions

When the alert frequency from a fish farm within a short period continuously increases

with an increasing number of recipients, SMS alerting might become a cost-ineffective

3
approach for the production environment. This is of concern as there exists the tendency

of pH increase, especially periods when there happens to be abnormal growth increase

of plant life and algae in the aquaculture setting (Tucker & D'Abramo, 2008). This

causes a higher rate of CO2 removal from the water due to increased photosynthesis

during the day than the CO2 which is replaced by means of respiration at night, leading

to sustained high pH levels.

The work done by (Africa et. al., 2017) has plausible features such as a database, and a

data visualization tool using LabVIEW. Although, services provided by LabVIEW

comes with subscription costs which will constitute an extra financial strain that can be

avoided by the startup fish farm.

Other works done in water parameter monitoring have their sensing nodes

communicate using the ZigBee 802.15.4 wireless link. The work done by (Zhang, Li,

Wang, & MaQishe, 2011), the water quality monitoring system had its nodes link by

ZigBee. ZigBee uses a non-IP-addressable communication protocol and IP is a requisite

feature for the IoT (Digi-key, 2016). IEEE 802.11 features the use of IP addressing,

which makes it possible for devices to be addressed and exchange data with other

devices and servers over the internet. ZigBee is a transceiver, meaning the receiver

must also have ZigBee to receive from ZigBee. But with LAN you can receive on your

phone and computer as long as you're connected to the internet. It would make lots of

sense to reuse available and more accessible resources when coming up with a solution

for a startup fish farm’s monitoring system.

This work seeks to design and validate a prototype aquaculture pH monitoring system.

The design looks toward using an inexpensive but effective pH sensor and

microcontroller which can communicate using the IEEE 802.11x communication

4
standard with the ability to send alerts using email. The system will be developed with

the healthy living of Catfish fingerlings in mind.

1.3 The aim of this Work

This work looks to develop a remote monitoring system which will serve as a proof of

concept for an operational platform for the vivid and accurate determination of pH

levels in an observed real-life system of a fish farm. The system solution, when

accomplished, should be valued as a good solution to provide remote pH monitoring

for fish tanks.

1.4 The objectives of this Work

The objectives to be accomplished in the course of designing and validating this system

are:

i. Developing an electronic microcontroller-based system that senses and captures

the pH level information.

ii. Transmission of captured data to a receiver device, on request, via an IEEE

802.11x wireless link.

iii. Alerts of critical values of observed parameters should be able to be reported

via email to appropriate receiver devices

1.5 The scope of the Work

This work revolves around the design and validation of remote pH monitoring system

solution. The parameter to be considered would be pH alone. This work will attempt to

use a low-cost pH measurement kit as the system’s input device. The medium of pH

measurement data would be transferred between the wireless sensor unit and the remote

client device by the use of an IEEE 802.11x link. Observations of pH level in a

fingerling fish tank would be done by getting daily water samples from a fish tank of

the University of Port Harcourt Demonstration Farm, Choba, for 10 days. The water
5
samples would be tested using traditionally - using a pH reagent, and electronically -

using the developed pH monitoring system.

The result from both approaches would be compared for the sake of validating the

developed system.

1.6 The significance of the Work

This work done would impact the catfish farms as follows:

i. Increasing awareness of instantaneous pH levels and possible spikes in pH

levels

ii. Improving the chances of good harvests on fingerlings investment

iii. This work would help provide feedback in the form of email alerts when in

unsuited conditions.

iv. A reasonable room for expansion of pond numbers while maintaining the farm’s

staff strength, since they won’t need getting samples from each and analyzing

them one after the other.

v. Provision of a platform which can help in making a better-informed decision as

regards farm management and administration. With system potentials for

upgrades like the inclusion of local flash storage or a remote DBMS, predictions

can be made for the best time to carry out actions like a water change.

1.7 Organization of this Work

This work is organized into five chapters. The first chapter is the introduces the work,

laying out the study’s background, problem statement. Still, in this chapter, the aim,

objectives, scope and significance of this work are stated.

The second chapter has reviews of various literature that were studied. Other works

which relate to this one were looked at and x-rayed.

6
The third chapter contains details of the design used for the research. It shed light on

the case study where this work was validated. Materials and methods used were also

discussed.

Chapter four takes a look the results gotten from this work. The results were discussed

as well.

Finally, chapter five holds the summary, conclusion, limitations, as well as

recommendations made. Contribution to knowledge from this work is also found in this

chapter.

7
CHAPTER TWO

2 LITERATURE REVIEW

Reviews of previous works done in and around this topic. Farming has experienced

various levels of automation and aquaculture is not left out. According to (Beecham

Research, 2014), jobs of farm experts is not threatened by ICT. But instead, it makes

room for more effective decision making, thereby translating to less waste and higher

efficiency of operation. (Beecham Research, 2014) said, also, that different levels and

complexities of electronic observation and automation introduced into the agricultural

scene. Some farm applications which can be purposed are:

 Fleet management

 Arable farming

 Livestock Monitoring

 Indoor Farming

 Fish Farming

 Forestry

 Storage Monitoring

2.1 Microcontrollers

Microcontrollers are computers built unto chips. These chips are programmed to carry

out almost any function, ranging from control, sequencing, monitoring. A serious

advantage it does not need external components as the necessary peripherals are

inbuilt. Thus, time, space and cost can be saved and are needed to construct low-cost

devices (Microcontroller Chip Technology, 2001).

8
In aquaculture, (Reza, Tariq, & Reza, 2010) opinionated about the monitoring of water

level and management based on the electrical conductivity of the water. The work

studied a water level sensing and controlling, based on a microcontroller, of a wire-

linked and wireless setup. In the work, the PIC 16F84A microcontroller ( Figure 2-1)

was used, which is RISC microcontrollers. The PIC 16F84A was used to offer central

control which the water monitoring system functions with.

2.2 Analogue to Digital Converter (ADC)

This is a device which converts analogue signals to discrete digital codes (CMM, 2017).

When using sensors, parameters which are measured are first converted to a voltage

before the ADC converts it into a digital format which can be processed by a computer

(Raj, 2018). The resolution of an ADC is a factor of the number of bits at the output.

The ADC on the P4S-342 is a 12-bit ADC meaning it has the ability to detect 4,096

discrete analogue levels. VLSB is the smallest step that can be detected which is equal

to VREF/2N for an N bit ADC as shown in Figure 2-2.

2.2.1 Relating ADC value to Voltage

Relating the reference voltage to the maximum discrete value provides a platform for

determining the voltage from a sensor or the corresponding discrete value.

𝑉𝑅𝐸𝐹 Reference Voltage (2.1)


=
2𝑁 ADC Resolution

Reference Voltage 𝑉𝑜𝑙𝑡𝑎𝑔𝑒 𝑀𝑒𝑎𝑠𝑢𝑟𝑒𝑚𝑒𝑛𝑡 (2.2)


=
ADC Resolution 𝐴𝐷𝐶 𝑅𝑒𝑎𝑑𝑖𝑛𝑔

9
Figure 2-1 A Picture of a PIC16F84A Microcontroller (Microchip, 2017)

Figure 2.2: An Ideal Transfer Curve of a 3-bit ADC (CMM, 2017)

10
2.3 TCP/IP

TCP/IP is a set of protocols which enables the sharing of resources in a network

(Aggarwal, Gupta, & Saxena, 2014). At present, Transmission Protocol/Internet

Protocol (TCP/IP) is used as the main means of linking devices, and networks

worldwide (Parziale, et al., 2006). The internet is driven by the TCP/IP architecture

(Hunt). Some of the protocols found in this suite include TCP, UDP, IP, ARP, etc. can

be seen in Table 2.1.

2.4 Simple Mail Transfer Protocol

Simple Mail Transfer Protocol (SMTP) is an application layer protocol used as the

common means for delivering electronic mails between hosts (Riabov, 2007).

According to (Cisco, 2005), SMTP servers listen for a TCP connection on port 25, and

the SMTP client process initiates a connection on that port.

2.5 Internet of Things

The Internet of Things (IoT) is the concept of making objects, sensors and common

non-computers items communicate over networks (Adhao & Mapari, 2017). In the

works of (Rose, Eldridge, & Chapin, 2015), it is understood that the concept of IoT is

yet to have a standardized definition. Though IoT device can be addressed singly so

that individual devices are linked and can be accessed through the web standards.

According to (Gohil, Modi, & Patel, 2013), the heavily anticipated 5G connectivity will

operate based on IP – IPv6 to be precise. IPv6 permits the assignment of

communications addresses to billions of devices (Lopez Research, 2013). Moreover,

Electronics companies are integrating Wi-Fi and cellular wireless capabilities into a

wide array of devices, which gives real support for IoT’s development. Implementation

of IoT devices on a large scale holds great hope of transforming several facets of the

11
way humans live such as healthcare, transportation, housing agriculture, industry, etc.,

as expressed by (Rose et al., 2015).

Table 2.1: The table shows the TCP/IP protocol layers with examples protocols
(Oracle, 2010)

TCP/IP Layer TCP/IP Protocol Examples

Application HTTP, SMTP, NFS, NIS+, DNS, telnet, FTP, and


others

Transport TCP, UDP

Internet IP, ARP, ICMP

Data link PPP, IEEE 802.2

Physical network Ethernet (IEEE 802.3) Token Ring, RS-232, others

12
2.6 Wireless Sensor Network

A Wireless Sensor Network (WSN) is comprised of independently distributed sensors

in space to observe physical parameters, such as pressure, Light, vibration, etc. and to

deliver their data via the network to a centre point.

These networks come to be by using tiny sensor nodes. The sensor network routes to

an outer network by the through a base station. A base station is defined at a specific

distance location. All nodes on the network send the collected information to a base

station which broadcasts this information over the web (Yadav & Yadav, 2014).

In a work done by (Faustine, Mvuma, Mongi, Gabriel, & Tenge, 2014), a Water Sensor

Network system mock-up was developed to monitor Lake Victoria Basin’s quality of

water was done. The system consisted of an Arduino microcontroller, sensors, and a

module for wireless network connection. It detected water temperature, DO, pH, and

electrical conductivity in real-time and transmits the information graphically through a

web portal and mobile phones.

A low-cost WSN was implemented by (Rahim, Ali, Bharti, Sabeel, & Ramya, 2016)

using Arduino and nRF24L01(+). The used nRF24L01(+) was capable of acting as a

transceiver that communicated with multiple sensor units – listening to 6 other devices.

2.7 pH

The pH unit is a solution’s degree of acidity or basicity (Hack_Company, 2010). The

pH is obtained by evaluating the hydrogen ions [H+] concentration. In any given

solution some atoms of water dissociate to form [H+] and hydroxyl ions [OH-]. Acids

are substances which split to give off [H+] or react with water to form [H+]. Bases are

substances that dissociate to release [H+] or react with water to form hydroxyl ions

(Down & Lehr, 2005). Acidic solutions have a relatively higher number of [H+] than

[OH-], while alkaline is vice versa. Below is the formula to calculate a solution’s pH:

13
𝑝𝐻 = − log[𝐻+] (1.3)

Where [H+] is the hydrogen ion activity, which translates to the effective [H+]

concentration, according to (Finesse, 2005).

[H+] and [OH-] measurement in liquids of varying ionic concentrations:

 Pure water: [H+] = 10-7 moles per liter and [OH-] = 10-7 moles per liter

 One molar aqueous HCl: [H+] = 102 moles per liter and [OH-] = 10-14 moles per

liter

 One molar aqueous NaOH [H+] = 10-14 moles per liter and [OH-] = 100 moles

per liter

Figure 2.1 and Figure 2.4 shows the logarithmic behaviour of the pH properties of a

solution moving from alkalinity to acidity and vice versa:

The pH scale helps to determine the higher concentration. The pH scale has a range of

0 and 14. Water (in its purity) is valued at 7.0 on the pH scale. When the pH is less than

7.0, hydrogen ions count exceeds the hydroxyl ions, and the water is considered as

being acidic (Sutar & Patil, 2013). When the pH is greater than 7.0, there are more

hydroxyl ions than hydrogen ions and the water is considered as being alkaline. Figure

2.2 and Figure 2.3 shows the inverse nature of change along the pH scale for an increase

in acidity and alkalinity respectively:

14
Figure 2.2 A pH-acid volume relationship graph showing increasing Acidity

(Clark, 2013)

Figure 2.3: A pH-alkali volume relationship graph showing increasing Alkalinity

(Clark, 2013)

15
Figure 2.4: A table showing the inverse relationship between H+ and OH- ions

(Finesse, 2005)

16
2.7.1 Impact of pH level on catfish

Fish are very sensitive to abrupt changes in the pH of their environment. And such a

drastic change can prove injurious and possibly fatal to the fish. As the pH rises, there

most likely is an increase in harmful compounds like ammonia. pH changes are

particularly hard on young and sick fish. Breeding of some fish species occurs only within

a specific pH range (Sharpe, 2018). According to (Towers, 2014), pond parameters could

change in short notice to the dynamics within the ponds.

According to (Towers, 2014), low pH in pond water is an indicator of a large amount of

dissolved CO2. Also, the fingerlings would experience poor growth and development

when they are exposed to an environment with pH in the range of 9 to 11. The catfish

fingerlings will also die when exposed to acidic environments with pH levels lower than

4. This brings a serious dent to the expected profit of the fish farmer. This will definitely

affect the time that it would take for the fish to get ready to go to market, while more

money is being languished on fish for the unnecessarily prolonged period of time.

2.7.2 Buffer Solution

Buffers are solutions that have constant pH values and are able to maintain a constant

pH level, according to (Omega, 2013). They are used to calibrate the pH measurement

system. pH meters calibration is typically performed at either pH 4 or pH 10 (Omega,

2013). Calibration is usually carried out close to the isopotential point (the signal gotten

by an electrode at pH 7 is 0 mV at 25°C/77°F).

2.7.3 pH Reagent

pH reagents are chemical substances which are used in determining the pH level of

solutions. pH reagents are used as a manual means to determine pH levels of drinking

water, but it also serves as a means to determine pH levels in water in fish tanks. About

4 drops of the pH reagent in 2 ounces of water will lead to a change in colour of the

17
reagent. The final colour is matched against a chart which is then used to establish the

pH value of the water but in the closest integer.

2.8 Water Quality Parameters and their Standard Values

As mentioned earlier, some of the essential parameters which come to mind when

gunning for a healthy fish yield could be Dissolved Oxygen, Temperature, pH, Salinity,

Carbon Dioxide, Ammonia, Nitrite, Hardness, Alkalinity, BOD, H2S. These parameters

have expected levels in which the water quality would be considered as acceptable.

According to (Towers, 2014), fish feed and defecate inside the same water where they

live and the quality of the water inside which live directly affects feed efficiency, the

rate of growth, survival and state of health of the fish. So Table 2 shows the various

parameters and expected values.

18
Table 2.2: Water quality parameters and their standard values (Banrie, 2012),

(Towers, 2014)

Parameter Standard values

Dissolved Oxygen (DO) > 4.0 mg/l

Temperature 26oC – 32oC

pH 7.5-8.5

Salinity > 0.5 ppt

Carbon Dioxide (CO2) < 10 ppm

Ammonia (NH4+ / NH4-N) 0 – 0.5 ppm

Nitrite (NO2) < 1 ppm

Hardness 40 – 400ppm

Alkalinity 50 – 300 ppm

Hydrogen Sulphide (H2S) 0 ppm

BOD < 50 mg/l

19
2.9 Local Area Network

Local Area Network (LAN) is a connection of networking devices that are in a small

geographic area, like an office, a building floor, a building itself, or within a campus

environment (Deal, 2008). In a LAN, PCs, switches, file servers, bridges, routers, etc.

make up the LAN. The transmission media used in LANs include copper cabling and

fibre cabling. Link technologies like Ethernet, fibre distributed data interface and Token

Ring use frames for communication fibre and copper. Today, most networks use

Ethernet and Radio links in some form.

2.10 African Catfish

The African catfish (Clarias Gariepinus) is widely distributed in Nigerian freshwater

and the African fresh and marshy waters as well (Tesfahun, 2018). Catfish is a fish

species largely found in rivers, streams, in Nigeria. This fish species is greatly eaten in

Nigeria. It was reported by (Mpiegbulam, 2017) that in places like Port Harcourt and

Afikpo, both being the state capitals of Rivers State and Ebonyi State respectively, have

their fresh catfish demand force step-up. It came to notice that these states have yielded

tremendously through aquaculture, following the Federal Government’s expressing

agriculture as an unquestionable substitute for petroleum. Aquaculture is viewed by

many as a lucrative business.

2.11 Related Works

(Ramya et. al, 2015) came up with a web-based embedded systems solution to monitor

water contamination from underground water and a fish pond. This work was done in

a bid to ensure that the fish that live in the pond stay healthy while human that drink of

the underground water is not compromised in their health. This monitoring was done

using an Atmel 89C51 microcontroller, pH sensor, temperature sensor, and water level

sensor. A wireless sensor node was created using the microcontroller integrated with

20
the sensors and the monitoring system communicate using the ZigBee communication

standard. An LCD display linked to the microcontroller was used to show the real-time

status of pH, temperature, and water level. Sensed data were stored over the internet

database on a website (www.watermonitoringsystem.in) from where the water quality

is read. Alerts were able to be sent in formatted messages to target receivers through

SMS.

Work was done by (Zhang et al., 2011) where a water quality monitoring system based

on wireless sensor network (WSN) was used. The WSN uses wireless nodes which

sense pH, temperature and dissolved oxygen and send the observed parameter through

ZigBee to a central computer for data storage using a knowledge database. Alerts of

unwanted conditions are sent to desired receivers via SMS, and SMS is also used for

sending actuation commands to the actuators in the monitored system. The wireless

sensor network hardware monitoring equipment deployed in the crab ponds of the local

farmers in Yixing Jiangsu province. Water quality monitoring software deployed in the

control room of PengYao ecological park.

A low-cost prototype of a water quality monitoring system was designed and

demonstrated by (Rao, et al., 2013) for the purpose of continuous pH, light,

temperature, Dissolved Oxygen, and oxidation-reduction potential in an aquaculture

setup in the Center of Aquaculture Pollution Identification and Management (CAPIM)

in the University of Melbourne, Victoria, Australia. The work was done as a component

of the Autonomous Live Animal Response Monitor (ALARM) which is “an aquatic

critter-containing sensor”, as described by (CAPIM, 2012). Low-cost sensors and open

source hardware like the Arduino Mega were used for sensing data and transmitting it

to a computer by USB. The same set of parameters are also checked using a commercial

water quality monitor which reads the same parameters as the low-cost sensors. The

21
data from the low-cost sensors and commercial option eventually compared for a

running period of one month. The read data are stored in a MySQL database.

Concerns in the farming of Tilapia was expressed by (Africa, et al., 2017) in the work

where an automated aquatic system prototype was developed to regulate pH, DO,

temperature and ammonia. Sensors were used to read levels of pH, DO, temperature

and ammonia. The data got from the sensors stored and visualized on a LabVIEW

database. SMS alerts were used as a medium to inform the receiver of harmful levels

that exist in the monitored environment. The prototype was built into a 1 cm3 aquarium.

Two different trials were conducted on a set of 50 fingerlings each for a period of 28

days.

(Sutar & Patil, 2013) designed and built a WSN which was used to monitor a fish farm.

The sensor modules – temperature module and pH module - used the ZigBee standard

to interact with the microcontroller which had central control over them. The gathered

data are sent to the cloud through an IoT hub called Thingspeak.

(Huan, Liu, Li, Wang, & Zhu, 2014) developed and integrated a multiplatform

application for advanced intensive Aquaculture monitoring and control. A WSN to

obtain parameter information on DO, water level, salinity, pH, turbidity and nitrite,

temperature. Actuators for water parameter regulation such as an aerator, drainage

pump, water pump, which are automatically turned on or off. This switching action is

executed if parameter thresholds are exceeded or are beneath. Web-based software and

Android software for sending and checking important instructions and information by

the interaction between computer and humans. The data transmission of the system was

by ZigBee and 3G network.

22
CHAPTER THREE

RESEARCH METHODOLOGY

3.1 Research Design

The research methodology of this work uses an applied research approach. The applied

research approach uses available tools to solve practical real world problems. Making

use of the Top-down paradigm, where a system solution is put together in a modular

fashion, this work attempts to solve a pH level monitoring problem.

The case study was studied, getting to know how it operates using its manual methods.

Then pH requirements for running fish farms were studied to have an informed

knowledge of expected pH levels in fish tanks. In designing the solution, a feasibility

study is being done to determine the best possible materials and processes to be used to

solve the problem. Then the pH sensing unit is first assembled and is made up of a pH

measurement kit and microcontroller. Based on the findings of favourable pH levels, a

program is written and compiled in the microcontroller. The pH measuring unit is then

calibrated using buffer solutions of predefined pH levels - 4, 7, and 9.2. The results of

the calibration are used to develop the pH function which the MCUs to determine pH

levels of solutions with unknown pH levels. The electronic system will be used to

measure the pH level of water in the fish tank, with daily samples taken across a period

of three days. The measurements gotten using the electronic approach will be compared

with results gotten from measurements gotten from the manual method. The research

design is presented in Figure 3.1.

3.2 Description of the Case Study

The case study is the fish farm segment of the University of Port Harcourt

Demonstration Farm, Choba, Rivers State. The farm rears catfish from the infant stages

23
as fries, to youthful fingerlings, till the point of adulthood (Plate F-2 and Plate F-3).

The fish are reared in cement tanks and plastic tanks. In the farm’s daily operations,

water from the tanks is drained and refilled on a daily basis, especially for the tanks

which contain juvenile fries.

24
Figure 3.1 Workflow of the research

25
3.3 Materials

The tools used consist of software components, hardware components, and

chemical materials. The following subsection itemizes the items used in the course of

this work.

3.3.1 Hardware Components

The hardware components that were used are as follows (images can be seen in

Appendix - B):

i. pH Meter Kit and probe

ii. PHPoC Blue microcontroller (P4S-342)

iii. IEEE 802.11n network interface cards

iv. Personal Computer

v. Remote monitoring device/Gateway

3.3.1.1 pH Meter Kit

A pH meter kit is an instrument used for determining the pH value of the solutions. A

Model E-201-C pH probe with meter kit was used. The pH meter kit is made up of a

pH probe and the pH sensor unit. The pH sensor connects to a microcontroller analogue

port. The kit is very good test equipment which gives a reasonable level of accuracy

and a great level of reliability. The specification details of this sensor can be seen in

Table 3.1.

3.3.1.2 PHPoC Blue microcontroller

The is the microcontroller used in actualizing the remote pH monitoring system. This

is the heart of the system. The MCU used is the PHPoC Blue (P4S-342). It is a WLAN

programmable board with the PHPoC interpreter imbedded in it (Sollae Systems,

2017). Hardware and software specification can be seen in Table 3.2 and Table 3.3

26
respectively. The MCU is programmed to run in an infinite loop, as shown in Figure

3.2.

3.3.1.3 IEEE 802.11n network interface cards

Both the remote monitoring device and the microcontroller are fitted with network

adaptors which are IEEE 802.11n compliant. Both the microcontroller and the receiver

device are fitted with IEEE 802.11n adaptors.

27
Table 3.1: Specification of the pH sensor according to (DFrobot, 2016)

Table 3.2: Hardware Specification of the P4S-342 microcontroller (Sollae Systems,


2017)

Table 3.3: Software specification of the P4S-342 (Sollae Systems, 2017)

28
Figure 3.2: Flowchart showing how the P4S-342 executes its actions

Figure 3.3: First off-page reference of the P4S-342 flowchart

29
Figure 3.4: Second off-page reference of the P4S-342 flowchart

30
3.3.2 Software Components

Some of the software that were used in this work include the following:

i. Protocols

ii. Operating System

iii. PHPoC Debugger IDE

iv. Internet Browser

3.3.2.1 Communication Protocols

This work made use of various communication protocols. The protocols which were

used are:

i. TCP, for connection-oriented pH data transfer between the web server, the

gateway, and the remote receiver device.

ii. Internet Protocol (IP) for logically addressing and locating devices on a TCP/IP

network. The 32-bit version of the Internet Protocol (IP v4) was used.

iii. SMTP is the application layer protocol of the TCP/IP suite which was used to

send email alert from the MCU to the receiver mailbox.

iv. WebSocket: The WebSocket protocol was used to ensure a steady stream of pH

information from the MCU to display of the remote monitoring device.

WebSocket also eliminates the need for page refreshes to get the last read pH

value.

3.3.2.2 Operating System

The Operating System used was the MS Windows 8.1. It served as a platform to run

the PHPoC debugger IDE and browser.

31
3.3.2.3 PHPoC Debugger IDE

The PHPoC debugger Integrated Development Environment (IDE) is the tool used for

programming and configuring the PHPoC microcontroller.

3.3.2.4 Programming Languages

Some of the programming languages used are:

i. PHPoC: The backend language which is used to control web server, read from

the analogue port, and computing of sensed data.

ii. JavaScript and Hypertext Markup Language: These are frontend languages

which the internet browser executes. They enable information to be displayed

on the receiver device. They also used to make requests for sensor values and

update the displayed value automatically.

3.3.2.5 Internet Browser

The internet browser is the application software used by the remote device to execute

the front-end codes of JavaScript and HTML. The browser used in this work is the

Mozilla Firefox.

3.3.3 Chemical Materials

Some chemical materials were used while carrying out this work, and they are:

i. pH tablets (pH 4, 7, and 9.2)

ii. pH Reagent

iii. Distilled Water

3.4 Methods

After the materials were gotten, they were used in carrying out various processes that

help in achieving this work’s aim. Before one moves on to assembling the available

32
components, a WLAN should already be set up. And for the sake of this work, a WLAN

hotspot was created using the gateway device.

3.4.1 Components Assembly and Configuration

The physical and software components were assembled. The PHPoC microcontroller

was connected to the PC via USB connection where it was programmed using the

PHPoC debugger IDE. The microcontroller was configured to search for and connect

to the wireless Access Point (AP) created by the internet gateway. The microcontroller

is assigned an IP address by the gateway, using the Dynamic Host Configuration

protocol, this enables the microcontroller unit to be identified and addressed both on

the LAN and the internet at large. The pH probe was connected to the analogue port of

the microcontroller. These are shown in Figure 3.5. The pH measurement kit was

powered through a 5V port on the microcontroller and the analogue port which the pH

sensor is connected to receive signals with voltage levels which corresponded to pH

levels of liquids which the sensor was immersed in.

Figure 3.5: Block Diagram of the Proposed MCU System

33
3.4.2 Calibration of the Sensing Unit

The pH sensing kit was calibrated so that it would be able to work the microcontroller.

The calibration was done using three pH buffer solutions of pH levels – 4, 7, and 9.2.

Each buffer solution generates a corresponding ADC (digital) value when the pH meter

is immersed in it, as shown in Table 3.4.

Table 3.4: Buffers 4, 7, and 9.2 solutions voltage reading during pH meter insertion

pH 4 Voltage Reading pH 7 Voltage Reading pH 9.2 Voltage Reading


4.342041 3.676758 3.106689
4.420166 3.73291 3.106689
4.467773 3.737793 3.105469
4.455566 3.708496 3.106689
4.44458 3.684082 3.106689
4.423828 3.673096 3.106689
4.422607 3.682861 3.10791
4.553223 3.710938 3.10791
4.482422 3.741455 3.106689
4.504395 3.71582 3.106689
4.418945 3.648682 3.10791
4.418945 3.635254 3.106689
Average pH 4.445800667 3.705376556 3.106892583

The read ADC values are used to calculate the original voltage delivered to the

microcontroller from the pH sensor. The voltages which were read from the buffer

solution were calculated using the Equation 3.1. Eventually, a straight linear equation

was then used to develop a pH function/model using the calculated voltages gotten by

the immersion of the pH probe in the buffer solutions. The voltages to be gotten based

on the pH levels of unknown solutions are used as dependent variables in the pH

function to determine the appropriate pH of the solution it is immersed in.

𝑣𝑜𝑙𝑡𝑎𝑔𝑒 = 𝐴𝐷⁄4096 ∗ 5.0 (3.1)

34
where: AD = digital equivalent of the analogue sensor output voltage

Voltage readings from pH buffers 4 and 9.2 were used in developing the pH function

which the pH monitoring system will use.

𝑦 = 𝑚𝑥 + 𝑐 (3.2)

Where:

𝑥 = 𝑠𝑒𝑛𝑠𝑒𝑑 𝑎𝑛𝑎𝑙𝑜𝑔 𝑣𝑜𝑙𝑡𝑎𝑔𝑒 (𝑉)

𝑦 = 𝑐𝑜𝑟𝑟𝑒𝑠𝑝𝑜𝑛𝑑𝑖𝑛𝑔 𝑝𝐻 𝑣𝑎𝑙𝑢𝑒

𝑚 = 𝑔𝑟𝑎𝑑𝑖𝑒𝑛𝑡 𝑜𝑓 𝑠𝑙𝑜𝑝𝑒

The pH function is gotten by using a straight line equation:

∆𝑦 = 𝑚∆𝑥 (3.3)

(𝑦2 − 𝑦1 ) = 𝑚 ∗ (𝑥2 − 𝑥1 ) (2.4)

Table 3.5: The average voltage readings from Table 3.4 used to establish the straight
line equation

x (V) Y (pH)

1 4.446207583 4.0

2 3.69567875 7.0

Values from Table 3 were substituted into Eq. 3.4.

35
(7.0 − 4.0) = 𝑚 ∗ (3.69567875 − 4.446207583) (3.5)

𝑚 = −3.997 (3.6)

The slope of the graph has a value of -3.997 pH/mV units as seen in Eq. 3.6.

To finally get the pH function, the x-y component and the slope were as follows - (4.46,

4) and (m = -3.997).

(𝑦 − 𝑦1 ) = 𝑚(𝑥 − 𝑥1 ) (3.7)

(𝑦 − 4) = −3.997 ∗ (𝑥 − 4.46) (3.8)

𝑦 − 4 = −3.997𝑥 + 17.8266 (3.9)

𝑦 = −3.997𝑥 + 17.8266 + 4 (3.10)

𝑦 = −3.997𝑥 + 21.8266 (3.11)

The pH function gotten in Equation 4.11 was used in the development of the code used

by the microcontroller to establish pH readings of the measured solution.

3.4.3 Email Alert System Setup

Programming and configuration had to be done to provide the microcontroller with the

email sending capabilities in the event of excessive pH conditions. The use of Simple

Mail Transfer Protocol (SMTP) was employed for the delivery of emails to destination

email addresses. After which, the IP address of the destination email address is resolved

using Domain Name Services (DNS). This makes it possible for the email to find its

route to the destination email address over the internet.

Once there is an event of unwanted pH levels, an alert email is generated by the

microcontroller. The microcontroller repeatedly checks the value of the pH values read

at intervals, and then checks if it is within the acceptable pH range between 4 and 9. If

36
the pH value is not satisfactory, the system generates an email alert, as depicted in

Figure 3.6.

Figure 3.6: The email flowchart

3.4.4 Real life pH Sensing Unit testing

After calibrating the pH sensing unit, it was used to take measurements from the fish

tank of interest. Water samples were taken from the fish tank over a period of ten days

at random, once a day. The water samples had their pH levels measured using the pH

probe. The process was repeated for each sample and their pH values were recorded.

The pH probe was dipped into the water samples, and the pH level was observed on the

browser of the remote client.

3.4.5 Manual pH measurement of Test Samples

The water samples would be tested using the pH reagent. The pH reagent makes use of

a pH chart which uses a coded colour spectrum to aid in determining a solution’s pH

level. 4 drops of pH reagent were dropped into approximately 2 oz. of the fish tank

water sample. Introducing the pH reagent to the water sample, should the sample to

experience a colour change, and the new colour would be compared with the colour on

37
the pH chart from which the pH levels were determined. Appendix-G shows an image

of the chart in which the pH reagent uses to determine pH levels.

38
39
CHAPTER FOUR

RESULTS AND DISCUSSIONS

An electronic remote pH monitoring system with the ability to measure pH level of

solutions was designed with the ability to transmit the read pH levels to a remote device

on a web browser via an IEEE 802.11x link. The pH monitoring unit was achieved

using affordable components such as PHPoC microcontroller, pH measurement kit, and

802.11n Wi-Fi dongle. Unfavourable pH levels that were sensed triggered the creation

of an email alert which was sent able to be sent through the gateway on the WLAN to

the recipient inbox.

4.1 Results and Validation

The results of the proposed work are presented and validated in this chapter.

4.1.1 System Network

The proposed system operates in a WLAN which is made up of IP addressable devices

– microcontroller, remote monitoring device/gateway. The remote device

communicates with the pH monitoring system over the available LAN and locates it

via its IP address which was allocated by the DHCP service on the Access Point

(192.168.43.1). While the microcontroller had an IP address of 192.168.43.219. The

both IP address can be seen in the MCU’s network information interface in Figure 4.1.

The values generated by the pH sensing unit are transmitted to the remote user device

through the gateway device. The web browser is automatically updated with any need

for the page to be continuously refreshed to reflect new pH values. When am email alert

is generated, it is routed out of the WLAN to the internet. The WLAN is depicted in the

diagram shown in Figure 4.2.

40
Figure 4.1: IPv4 Network details of the microcontroller while on the WLAN

GATEWAY
DEVICE

Figure 4.2: A network diagram of the pH monitoring system

41
4.1.2 pH Measurement Subsystem

Once the pH sensing unit is powered on, pH readings starts being read from the pH

probe at intervals. The pH probe was immersed in three buffer solutions and readings

were gotten from them (buffers 4.0, 7.0, and 9.2). When sensing the buffer 7 and 9.2

solutions, the results were displayed on the serial output of the PHPoC debugger

console section. as seen in Figure 4.3 and Figure 4.4 respectively.

Figure 4.3: A serial output of the system when measuring from the buffer 7 solution

42
Figure 4.4: A serial output of the system when measuring from the buffer 9.2 solution

The console section shows the output of the intermittently measured pH values when it

is connected to the microcontroller using serial communication ports (COM port). Since

the console could display pH values, it means that the MCU is working properly with

the pH sensor, even before pH values are transmitted to the receiver device.

The remote client was then used to read pH levels from the MCU. pH readings were

generated by the microcontroller and transmitted over Wi-Fi to the remote monitoring

device.

Firstly, buffer 4 solution was measured. The microcontroller determined the pH level

based on the intermittent reading of voltage levels from the pH probe and streams each

reading to the remote monitoring device. In left half of Figure 4.5, an image of the pH

probe is immersed in the buffer 4 solution while the pH is sensed is displayed. On the

remote device, the web browser, real-time pH values that are read at intervals are

displayed and updated. At each interval the sensor reads the pH, it is transmitted and

43
the latest value is displayed. This is shown in the right half of Figure 4.5. From Figure

4.5, it is seen that a sequence of values such as the first ten pH values - 4.01, 4.05, 4.05,

4.09, 4.09, 4.09, 4.09, 4.10, 4.09, 4.09 – were displayed.

Figure 4.5: Real-time remote pH value display from the buffer 4 solution

After the pH level confirmation was done on the buffer 4 solution, the remote

monitoring system was further used to confirm the pH level of the buffer 7 solution.

The pH probe is immersed in the buffer 7 solution while the pH level is measured (as

shown in the left half of Figure 4.6). The pH level swiftly shifts from values around a

pH reading of 4 – as seen in Figure 4.5 - to a reading around pH 7 after the pH probe

was dipped into the buffer 7 solution. A sequence of values such as the first ten pH

values - 7.00, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00 – were displayed.

44
Figure 4.6: Real-time remote pH value display from the buffer 7 solution

For the last pH level confirmation, the pH probe was dipped into a buffer 9.2 solution

(Figure 4.7, to the left). Ten consecutive values of 9.19, 9.05, 9.14, 9.05, 9.10, 9.09,

9.09, 9.21, 9.04, 9.13 were displayed while the pH probe was in the buffer 9.2 solution.

45
Figure 4.7: Real-time remote pH value display from the buffer 9.2 solution

4.1.3 Email Alerting Subsystem

Whenever the MCU detects undesirable values in the received pH readings, an email is

generated and is then sent over the internet through the gateway device to the

destination mailbox. The email is sent using SMTP as the mail handling protocol of

choice. DNS ensures that the domain name of the receiving mailbox can be translated

from its human-friendly domain name to the mapped IP address of the recipient email

host. Figure 4.8 shows an email alert received from the pH monitoring system when the

pH sensing unit was exposed to an unwanted pH level.

46
Figure 4.8: An email alert received from the pH monitoring system

4.1.4 Result Validation

After the design of the pH monitoring system, the system had to be validated. This was

done by comparing the pH measurements from water samples which were taken over a

period of 10 days (two working weeks).

For each day’s water sample, three actions are carried out. Firstly, the proposed

(electronic) system was used to read the water’s pH level. Secondly, the pH reagent

(traditional means) was also used for testing the pH level of the solution. And lastly, a

comparison between the result of both approaches would be done to find the relative

error in their pH results. The process is repeated for the 10 water samples across the 10-

day period. The relative error is the difference in measurement between both

approaches to pH measurement, and is mathematically expressed in Eq. 4.1.

𝑅𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝐸𝑟𝑟𝑜𝑟 = 𝐸𝑙𝑒𝑐𝑡𝑟𝑜𝑛𝑖𝑐 𝑅𝑒𝑎𝑑𝑖𝑛𝑔 − 𝑇𝑟𝑎𝑑𝑖𝑡𝑖𝑜𝑛𝑎𝑙 𝑅𝑒𝑎𝑑𝑖𝑛𝑔 (4.1)

Table 4.1 shows a comparison between the pH values gotten from each water sample

by both approaches. Each row holds date information on each water sample, the pH
47
measurement gotten when using the proposed system, and then using a pH reagent, and

the relative difference between the both pH measurements. Furthermore, a graph in

Figure 4.9 expresses the relative error that exists between both measurement

approaches used. And it would be noticed that a relative error of ±0.2 was not exceeded.

Table 4.1: Comparison between electronic and traditional pH measurement


approaches
Sample Date pH Measurement
Day Electronic Traditional Relative Error
Approach Approach
1 08-10-2018 6.4 6.6 -0.2
2 09-10-2018 6.4 6.6 -0.2
3 10-10-2018 6.7 6.6 0.1
4 11-10-2018 6.4 6.6 -0.2
5 12-10-2018 6.4 6.6 -0.2
6 15-10-2018 6.5 6.6 -0.1
7 16-10-2018 6.4 6.6 -0.2
8 17-10-2018 6.4 6.6 -0.2
9 18-10-2018 6.5 6.6 -0.1
10 19-10-2018 6.4 6.6 -0.2

Relative error gotten from Table 4.2


0.15

0.1

0.05
Relative Error

-0.05

-0.1

-0.15

-0.2

-0.25
Date

Figure 4.9: The relative error of pH values of water samples taken on various days

48
4.1.5 Bill of Engineering Materials and Evaluation

A Bill of Engineering Materials and Evaluation (BEME) for this work is shows all the

materials and other forms of services purchased for this work. The costs are itemized

in Table 4.2.

Table 4.2: Bill of Engineering Materials and Evaluation for this work
Items/Materials Quantity Unit Cost(₦) Price(₦)
PHPoC Microcontroller 1 25,000 25,000
pH Measurement Kit 1 20,000 20,000
pH Buffer Tablets 3 500 1,500
pH Reagent 1 1,500 1,500
Distilled Water 1 Litre 200 200
Internet Subscription 2 Month 2,000 1,000
Total 50,200

49
CHAPTER FIVE

SUMMARY, CONCLUSIONS AND RECOMMENDATIONS

5.1 Summary

In the bid to ensure that the fish farm being studied can reach its peak potentials and

maximize profit, fundamental parameters have to be observed and monitored

constantly.

After studying various literature and observing activities at The University of Port

Harcourt fish farm, a microcontroller-based monitoring system was developed with the

inherent benefit of fish tank pH level sensing and remote relaying of pH information to

a browser interface within the LAN and emailing of alerts of unfavourable pH

conditions are sent.

5.2 Conclusions

The proposed system for remote pH monitoring founded on microcontroller-based

sensing for real-time situation access and report is achievable using IoT is workable.

A low-cost sensor (E-201-C) can be meticulously used to monitor aquaculture

environment’s pH level with a very good level of accuracy. pH was able to be measured

with an accuracy of ±0.2 pH as seen in Table 4.1.

Real-time pH levels were successfully shown on the browser of the remote monitoring

device when it connects to the microcontroller via its IP address. This makes it easy to

have access to the pH status as long as the remote device is connected within the range

of coverage of IEEE 802.11n access point.

The use of the WebSocket protocol and JavaScript as a frontend language prove to be

very effective, by eliminating the need for recurrent page refreshing to get instantaneous

pH values. Once the page is opened, the values are automatically updated on the
50
initially requested page. This improves data exchange and the PHPoC Blue’s

performance.

Emails are sent as alerts when pH of the aquaculture environment becomes less than 4

and greater than 9. The email alerts are sent to the destination email address using

SMTP protocol.

5.3 Recommendations

Below are some recommendations:

i. The proposed linear pH model can be put to test in the development WSNs of

pH sensing nodes with potentials for implementation in a small to large scale

industrial environment.

ii. Future works could add an extra layer of robustness by integrating Database

Management System (DBMS). This would increase the information access from

the overall system. With a DBMS, information could be shared amongst

farmers, government agencies and research communities. This would help to

improve life and further the growth of humanity’s well-being and create room

for better and more informed government policies towards agricultural

development.

5.4 Limitations of this Work

Below are some bottlenecks experienced while trying to accomplish this work:

i. Cost of equipment

The pH measurement kit used, though being relatively low-cost, was quite

expensive. Though it is susceptible to generating unreliable pH readings if left

operational for too long. Getting pH probes and measurement modules within

the country prove to be difficult.

51
ii. Difficulty in access to resource materials

The literature on and documentation of works done using PHPoC blue

microcontroller were very scanty. The literature on works using both a PHPoC

blue and an E-201-C was not available. This made it a prolonged challenge to

configure and use them.

iii. Unavailability of simulation tools

Considering that the microcontroller used relatively new, it was impossible to

find a software-based simulation tool which would have helped to reduce

completion time. There also were very few programming libraries for the

PHPoC programming language, for the same reason.

5.5 Contribution to Knowledge

Following the conclusion are made as a contribution to knowledge:

i. The proposed designed pH model can help to accurately detect pH levels and

monitor changes in substances’ pH levels. This surmounts the accuracy of pH

readings gotten using traditional means such as the addition of pH reagents to

water samples.

ii. The proposed system allows for remote monitoring in a WLAN and alerts using

email if unwanted conditions are experienced.

52
References

Abdelrahman, R., Mustafa, A., & Osman, A. (2015). A Comparison between IEEE
802.11 n and ac Standards. IOSR Journal of Computer Engineering, 17(5), 30-
34.
Adhao, P., & Mapari, R. (2017). The Internet of Things (IoT): New age. International
Journal of Engineering Development and Research, 5(2), 352-357.
doi:IJEDR1702061
Africa, A. D., Aguilar, J. C., Lim, C. M., Pacheco, P. A., & Rodrin, S. E. (2017).
Automated Aquaculture System that Regulates Ph, Temperature and Ammonia.
Conference: 2017 IEEE 9th International Conference on Humanoid,
Nanotechnology, Information Technology, Communication and Control,
Environment, and Management (HNICEM ). Manila: IEEE.
doi:10.1109/HNICEM.2017.8269494
Aggarwal, N., Gupta, R., & Saxena, P. (2014, November). Comparative Study of OSI
& TCP/IP Reference Model. nternational Journal for Research in Applied
Science & Engineering Technology (IJRASET), 2(6), 64-68. Retrieved February
2018
Beecham Research. (2014). Towards Smart Farming: Agriculture Embracing The IoT
Vision.
CAPIM. (2012). Live streaming for healthy waterways. Retrieved May 03, 2018, from
Science in Public: http://stories.scienceinpublic.com.au/2012/water-sampling-
003/
Cisco. (2005, August 10). Cisco IOS for S/390 User’s Guide. Cisco. Retrieved
December 15, 2017
Clark, J. (2013, November). pH (TITRATION) CURVES. Retrieved from chemguide:
https://www.chemguide.co.uk/physical/acidbaseeqia/phcurves.html
CMM. (2017, November 21). ADC and DAC. Retrieved March 2018, from Museu das
Comunicocoes:
http://macao.communications.museum/eng/Exhibition/secondfloor/moreinfo/
ADConverter.html#ADC
Cohen, D. (2016, 09 13). 5G and the IoT: 5 Trends and Implications. Retrieved 11 09,
2017, from Microwave Journal:
http://www.microwavejournal.com/articles/27058-g-and-the-iot-5-trends-and-
implications
Deal, R. (2008). Cisco Certified Network Associate Study Guide. McGraw Hill.
doi:10.1036/0071497285
DFrobot. (2016). Gravity: Analog pH Sensor / Meter Kit For Arduino. Retrieved
January 2018, from DFROBOT: https://www.dfrobot.com/product-1025.html

53
Digi-key. (2016). The Current and Future Advantages of Using Wi-Fi Modules in IoT
Designs. Retrieved 07 30, 2018, from Digi-Key Electronics:
https://www.digikey.com/en/articles/techzone/2016/apr/the-current-and-
future-advantages-of-using-wifi-modules-in-iot-designs
Down, R. D., & Lehr, J. H. (2005). Theory of pH Measurement. In R. D. Down, & J.
H. Lehr, Environmental Instrumentation and Analysis Handbook (p. 460). John
Wiley & Sons.
Faustine, A., Mvuma, A. N., Mongi, H. J., Gabriel, M. C., & Tenge, A. J. (2014).
Wireless Sensor Networks for Water Quality Monitoring and Control within
Lake Victoria Basin: Prototype Development. Scientific Research, 281-290.
Finesse, L. (2005). pH Measurement Definitions. Retrieved from www.finesse-
inc.com.
Gohil, A., Modi, H., & Patel, S. K. (2013). 5G Technology of Mobile Communication:
A Survey. International Conference on Intelligent Systems and Signal
Processing (ISSP). IEEE.
Hack_Company. (2010). What is pH and how is it measured.
Huan, J., Liu, X., Li, H., Wang, H., & Zhu, X. (2014). A Monitoring and Control
System for Aquaculture via Wireless Network and Android Platform. Sensors
and Transducers, 169(4), 250-256.
Hunt, C. (n.d.). TCP/IP Network Administration (3rd Edition ed.). O'Reilly.
Lopez_Research. (2013, November). An Introduction to the Internet of Things (IoT).
Retrieved from www.lopezresearch.com.
Microchip. (2017). PIC16F84A. Retrieved from www.microchip.com:
www.microchip.com/datasheet/PIC16F84A
Microcontroller Chip Technology. (2001). PIC16F84A Datasheet. Retrieved from
www.microchip.com
Mpiegbulam, O. (2017, May 12). In Port Harcourt, fresh fish market booms. Retrieved
from The Sun: http://sunnewsonline.com/in-port-harcourt-fresh-fish-market-
booms/
Mustapha, M. K., & Mohammed, Z. O. (2018). Effect of simulated acid rain on the
survival, mortality, behaviour and morphology of African mud catfish Clarias
gariepinus (Burchell, 1822). Acta Scientiarum. Animal Sciences, 40(1).
doi:10.4025/actascianimsci.v40i1.36900
Okechi, J. K. (2004). Profitability assessment: a case study of african catfish (clarias
gariepinus) farming in the lake victoria basin, kenya. Kenya Marine and
Fisheries Research Institute (KMFRI), Kenya.
Omega. (2013). www.omega.com/ph/. Retrieved from www.omega.com.
Oracle. (2010). System Administration Guide: IP Services. Retrieved from Oracle:
https://docs.oracle.com/cd/E19683-01/806-4075/ipov-10/

54
Parziale, L., Britt, D., Davis, C., Forrester, J., Liu, W., Matthews, C., & Rosselot, N.
(2006, December). TCP/IP Tutorial and Technical Overview. Retrieved
February 2018, from IBM Corp.: www.ibm.com/redbooks
Rahim, A., Ali, Z., Bharti, R., Sabeel, S., & Ramya, B. K. (2016). International Journal
of Scientific Research Engineering & Technology. 5(5), 307-309.
Raj, A. (2018, Sptember 14). What is ADC - Analog to Digital Converters. Retrieved
from Circuit Digest: https://circuitdigest.com/tutorial/what-is-adc-analog-to-
digital-converters
Ramya, V., Balaji, V., & Akilan, T. (2015). A Web based Observance and Alerting for
Underground and Fish Pond Water Quality. International Journal of Computer
Applications, 110(5). doi:0975 – 8887
Rao, A. S., Marshall, S., Gubbi, J., Palaniswani, M., Sinnott, R., & Peltigrove, V.
(2013). Design of low-cost water quality monitoring system., (pp. 22-25).
Retrieved July 31, 2018
Rao, A. S., Marshally, S., Gubbi, J., Palaniswami, M., Sinnottz, R., & Pettigrove, V.
(2013). Design of Low-cost Autonomous Water Quality Monitoring System.
2013 International Conference on Advances in Computing, Communications
and Informatics (ICACCI). Mysore, India: IEEE.
doi:10.1109/ICACCI.2013.6637139
Reza, S. M., Tariq, S. A., & Reza, S. M. (2010). Microcontroller Based Automated
Water Level Sensing and Controlling: Design and Implementation Issue. World
Congress on Engineering and Computer Science, 1.
Riabov, V. (2007, December). SMTP (Simple Mail Transfer Protocol).
doi:10.1002/9781118256114.ch26
Rose, K., Eldridge, S., & Chapin, L. (2015, October). Internet of Things. (C. Marsan,
Ed.) Retrieved February 9, 2018, from Internet Society:
https://www.internetsociety.org/iot
Sharpe, S. (2018, April 16). Aquarium Water pH Maintenance. Retrieved from the
spruce: https://www.thespruce.com/aquarium-water-ph-1378801
Sollae Systems. (2017). PHPoC Blue l P4S-342. Retrieved March 2018, from PHPoC:
https://www.phpoc.com/phpoc_blue.php
Sutar, K., & Patil, R. T. (2013). Wireless Sensor Network System to Monitor the Fish
Farm. International Journal of Engineering Research and Applications.
Tesfahun, A. (2018). Feeding biology of the African catfish Clarias gariepinus
(Burchell) in some of Ethiopian Lakes: A review. International Journal of
Fauna and Biological Studies, 5(1), 19-23.
Towers, L. (2014, June 23). Water Quality Monitoring and Management for Catfish
Ponds. Retrieved from The Fish Site: https://thefishsite.com/articles/water-
quality-monitoring-and-management-for-catfish-ponds

55
Tucker, C. S., & D'Abramo, L. R. (2008). Managing High pH in Freshwater Ponds.
Mississippi: SRAC Publication.
Verma, S. (2006). Impact of Agricultural Mechanization on Production Productivity,
Cropping Intensity Income Generation and Employment of Labour. Punjab
Agricultural University: Ludhiana, India. Retrieved May 17, 2017
Wellborn, T. L. (1987). Catfish Farmer's Handbook. Cooperate Extension Services -
Mississippi State University.
Yadav, N., & Yadav, S. K. (2014). Implementation of Wire Sensor Network using
MATLAB Simulator. International Journal of Recent Development in
Engineering and Technology, 3(2). Retrieved from www.ijrdet.com
Zhang, M., Li, D., Wang, L., & MaQishe, D. (2011). Design and Development of Water
Quality Monitoring System Based on Wireless Sensor Network in Aquaculture.
CCTA 2010. 347, pp. 629-641. Springer, Berlin, Heidelberg.
doi:https://doi.org/10.1007/978-3-642-18369-0_76

56
APPENDIX - A

SOURCE CODE FOR THE BACK END

<?php

if(_SERVER("REQUEST_METHOD"))
exit; // avoid php execution via http request

include "/lib/sd_340.php";
include "/lib/sn_tcp_ws.php";
include_once "/lib/sn_dns.php";
include_once "/lib/sn_smtp.php";
include_once "pH_alert.php";

define("ADC_MIN", 1000);
// define("ADC_MIN", 2859);
define("ADC_MAX", 5265);

adc_setup(0, 0); // adc0, channel 0


ws_setup(0, "WebConsole", "text.phpoc");

$last_adc_in = 0;
$pH_voltage = 0.00;
$pH_last = 0.0;
while(1)
{

$adc_in = adc_in(0, 30);

if($adc_in > ADC_MAX)


$adc_in = ADC_MAX;
elseif($adc_in < ADC_MIN)

57
$adc_in = ADC_MIN;

$adc_out = $adc_in*1.0;
$pH_voltage = $adc_out * 5 / 4096;
$pH = -3.999 * $pH_voltage + 21.8266;

if (abs($pH - $pH_last) > 0.3){


if ($pH < 3.8 || $pH > 9.0) {
$subject = "pH Level Alert";
$message = "There is an abnormality in the fish tank.\r\nPlease
visit fish tank and inspect.\r\n";

$msg = smtp_send("fishtankstatus1@gmail.com", "chimdi",


$subject, $message);

if($msg == "221")
echo "send email successful\r\n";
else
echo "send email failed\r\n";
}
}
printf("ADC : %d\tpH Voltage: %f\tpH Level: %.1f\r\n", $adc_in,
$pH_voltage, $pH);

function send_email(){
$subject = "pH Level Alert";
$message = "There is an abnormality in the fish tank.\r\nPlease visit
fish tank and inspect.\r\n";

$msg = smtp_send("fishtankstatus1@gmail.com", "chimdi", $subject,


$message);

if($msg == "221")

58
echo "send email successful\r\n";
else
echo "send email failed\r\n";
}

if($pH < 3.8 || $pH > 9.0){


send_email();
}

if(ws_state(0) == TCP_CONNECTED)
{
ws_write(0, sprintf("pH Level: %.1f\r\n", $adc_in, $pH_voltage,
$pH));

$last_adc_in = $adc_in;

sleep(1);

}
sleep(2);
}

?>

59
APPENDIX – B

SOURCE CODE FOR THE FRONTEND


<html>
<head>
<title>PHPoC / <?echo system("uname -i")?></title>
<meta name="viewport" content="width=device-width, initial-scale=0.7">
<style>
body { text-align:center; }
textarea { width:400px; height:400px; padding:10px; font-family:courier; font-
size:14px; }
</style>
<script>
var ws;
var wc_max_len = 32768;
function ws_onopen()
{
document.getElementById("ws_state").innerHTML = "OPEN";
document.getElementById("wc_conn").innerHTML = "Disconnect";
}
function ws_onclose()
{
document.getElementById("ws_state").innerHTML = "CLOSED";
document.getElementById("wc_conn").innerHTML = "Connect";

ws.onopen = null;
ws.onclose = null;
ws.onmessage = null;
ws = null;
}
function wc_onclick()
{
if(ws == null)

60
{
ws = new WebSocket("ws://<?echo
_SERVER("HTTP_HOST")?>/WebConsole", "text.phpoc");
document.getElementById("ws_state").innerHTML =
"CONNECTING";

ws.onopen = ws_onopen;
ws.onclose = ws_onclose;
ws.onmessage = ws_onmessage;
}
else
ws.close();
}
function ws_onmessage(e_msg)
{
e_msg = e_msg || window.event; // MessageEvent

var wc_text = document.getElementById("wc_text");


var len = wc_text.value.length;

if(len > (wc_max_len + wc_max_len / 10))


wc_text.innerHTML = wc_text.value.substring(wc_max_len / 10);

wc_text.scrollTop = wc_text.scrollHeight;
wc_text.innerHTML += e_msg.data;
}
function wc_clear()
{
document.getElementById("wc_text").innerHTML = "";
}
</script>
</head>
<body>

61
<h2>
<p>
Web Console : <span id="ws_state">CLOSED</span><br>
</p>
<textarea id="wc_text" readonly="readonly">
</textarea><br>
<button id="wc_conn" type="button" onclick="wc_onclick();">Connect</button>
<button id="wc_clear" type="button" onclick="wc_clear();">Clear</button>
</h2>

</body>
</html>

62
APPENDIX - C
TCP WEBSOCKET SOURCE CODE
<?php
$sn_tcp_ws_pid = array( 0, 0, 0, 0, 0 );
function ws_setup($tcp_id, $path, $proto, $port = 0)
{
global $sn_tcp_ws_pid;

if(($tcp_id < 0) || ($tcp_id > 4))


exit("ws_setup: tcp_id out of range $tcp_id\r\n");

$pid = $sn_tcp_ws_pid[$tcp_id];

if($pid)
pid_close($pid);

$pid = pid_open("/mmap/tcp$tcp_id");

pid_ioctl($pid, "set api ws");


pid_ioctl($pid, "set ws path $path");
pid_ioctl($pid, "set ws proto $proto");

pid_bind($pid, "", $port);

pid_listen($pid);

$sn_tcp_ws_pid[$tcp_id] = $pid;
}

function ws_check_get_pid($tcp_id, $from)


{
global $sn_tcp_ws_pid;

63
if(($tcp_id < 0) || ($tcp_id > 4))
exit("$from: tcp_id out of range $tcp_id\r\n");

$pid = $sn_tcp_ws_pid[$tcp_id];

if(!$pid)
exit("$from: tcp$tcp_id not initialized\r\n");

return $pid;
}

function ws_read($tcp_id, &$rbuf, $rlen = MAX_STRING_LEN)


{
$pid = ws_check_get_pid($tcp_id, "ws_read");

if(pid_ioctl($pid, "get rxlen"))


return pid_recv($pid, $rbuf, $rlen);

if(pid_ioctl($pid, "get state") == TCP_CLOSED)


pid_listen($pid);

return 0;
}

function ws_readn($tcp_id, &$rbuf, $rlen)


{
$pid = ws_check_get_pid($tcp_id, "ws_readn");

$len = pid_ioctl($pid, "get rxlen");

if($len && ($len >= $rlen))


return pid_recv($pid, $rbuf, $rlen);

64
if(pid_ioctl($pid, "get state") == TCP_CLOSED)
pid_listen($pid);

return 0;
}

// read line terminated by CRLF


function ws_read_line($tcp_id, &$rbuf)
{
$pid = ws_check_get_pid($tcp_id, "ws_read_line");

$len = pid_ioctl($pid, "get rxlen \r\n");

if($len)
return pid_recv($pid, $rbuf, $len);

if(pid_ioctl($pid, "get state") == TCP_CLOSED)


pid_listen($pid);

return 0;
}

function ws_write($tcp_id, $wbuf, $wlen = MAX_STRING_LEN)


{
$pid = ws_check_get_pid($tcp_id, "ws_write");

$state = pid_ioctl($pid, "get state");

if($state == TCP_CONNECTED)
{
if($wlen > strlen($wbuf))

65
$wlen = strlen($wbuf);

if($wlen && (pid_ioctl($pid, "get txfree") >= $wlen))


return pid_send($pid, $wbuf, $wlen);
}
else
if($state == TCP_CLOSED)
pid_listen($pid);

return 0;
}

function ws_txfree($tcp_id)
{
$pid = ws_check_get_pid($tcp_id, "ws_txfree");

$state = pid_ioctl($pid, "get state");

if($state == TCP_CONNECTED)
return pid_ioctl($pid, "get txfree");
else
if($state == TCP_CLOSED)
pid_listen($pid);

return 0;
}

function ws_state($tcp_id)
{
$pid = ws_check_get_pid($tcp_id, "ws_state");

$state = pid_ioctl($pid, "get state");

66
if($state == TCP_CLOSED)
pid_listen($pid);

return $state;
}

?>

67
APPENDIX - D
SIMPLE MAIL TRANSMISSION PROTOCOL SOURCE CODE
<?php
include_once "/lib/sn_dns.php";
define("SMTP_STATE_IDLE", 0);
define("SMTP_STATE_RR_MX", 1);
define("SMTP_STATE_RR_A", 2);
define("SMTP_STATE_CONNECT", 3);
define("SMTP_STATE_220", 4);
define("SMTP_STATE_HELO", 5);
define("SMTP_STATE_FROM", 6);
define("SMTP_STATE_RCPT", 7);
define("SMTP_STATE_DATA", 8);
define("SMTP_STATE_BODY", 9);
define("SMTP_STATE_QUIT", 10);

$sn_smtp_state = 0;
$sn_smtp_tcp_id = 0;
$sn_smtp_tcp_pid = 0;
$sn_smtp_ip6 = false;
$sn_smtp_next_tick = 0;
$sn_smtp_hostname = "";
$sn_smtp_helo_host = "";
$sn_smtp_query_name = "";
$sn_smtp_query_count = 0;
$sn_smtp_from_email = "";
$sn_smtp_from_name = "";
$sn_smtp_rcpt_email = "";
$sn_smtp_rcpt_name = "";
$sn_smtp_subject = "";
$sn_smtp_body = "";

68
function sn_smtp_get_tick()
{
while(($pid = pid_open("/mmap/st9", O_NODIE)) == -EBUSY)
usleep(500);

if(!pid_ioctl($pid, "get state"))


pid_ioctl($pid, "start");

$tick = pid_ioctl($pid, "get count");


pid_close($pid);

return $tick;
}

function sn_smtp_cleanup()
{
global $sn_smtp_state, $sn_smtp_tcp_pid;

if($sn_smtp_tcp_pid)
{
pid_close($sn_smtp_tcp_pid);
$sn_smtp_tcp_pid = 0;
}

$sn_smtp_state = SMTP_STATE_IDLE;
}

function sn_smtp_update_helo_host()
{
global $sn_smtp_ip6;

69
global $sn_smtp_hostname, $sn_smtp_helo_host;

if($sn_smtp_hostname)
return;

if((int)ini_get("init_net0"))
$pid_net = pid_open("/mmap/net0");
else
$pid_net = pid_open("/mmap/net1");

if($sn_smtp_ip6)
$sn_smtp_helo_host = pid_ioctl($pid_net, "get ipaddr6");
else
$sn_smtp_helo_host = pid_ioctl($pid_net, "get ipaddr");

pid_close($pid_net);
}

function smtp_setup($udp_id, $tcp_id, $dns_server = "", $ip6 = false)


{
global $sn_smtp_tcp_id, $sn_smtp_ip6;

sn_smtp_cleanup();

$sn_smtp_tcp_id = $tcp_id;
$sn_smtp_ip6 = $ip6;

dns_setup($udp_id, $dns_server, $sn_smtp_ip6);


}

function smtp_hostname($hostname)

70
{
global $sn_smtp_hostname, $sn_smtp_helo_host;

if($hostname)
{
$sn_smtp_hostname = $hostname;
$sn_smtp_helo_host = $hostname;
}
}

function smtp_account($email, $name)


{
global $sn_smtp_hostname, $sn_smtp_helo_host;
global $sn_smtp_from_email, $sn_smtp_from_name;

if($sn_smtp_hostname == "")
sn_smtp_update_helo_host();

if($email == "")
{
if(inet_pton($sn_smtp_helo_host) === false)
$sn_smtp_from_email = "PHPoC@$sn_smtp_helo_host";
else
$sn_smtp_from_email = "PHPoC@[$sn_smtp_helo_host]";
}
else
$sn_smtp_from_email = $email;

if($name == "")
$sn_smtp_from_name = "PHPoC";
else

71
$sn_smtp_from_name = $name;
}

function sn_smtp_loop_rr()
{
global $sn_smtp_state, $sn_smtp_tcp_id, $sn_smtp_tcp_pid;
global $sn_smtp_ip6;
global $sn_smtp_query_name, $sn_smtp_query_count;

$rr = dns_loop();

if($rr === false)


return false;

if($rr == "")
{
if($sn_smtp_query_count)
{
echo "sn_smtp: retry lookup $sn_smtp_query_name\r\n";

if($sn_smtp_state == SMTP_STATE_RR_MX)
dns_send_query($sn_smtp_query_name, RR_MX,
1000);
else
{
if($sn_smtp_ip6)
dns_send_query($sn_smtp_query_name,
RR_AAAA, 1000);
else
dns_send_query($sn_smtp_query_name, RR_A,
1000);
}

72
$sn_smtp_query_count--;
return false;
}
else
{
echo "sn_smtp: lookup failed\r\n";
return "";
}
}

if($sn_smtp_state == SMTP_STATE_RR_MX)
{
echo "sn_smtp: MX $rr\r\n";

if($sn_smtp_ip6)
dns_send_query($rr, RR_AAAA, 500);
else
dns_send_query($rr, RR_A, 500);

$sn_smtp_query_name = $rr;
$sn_smtp_query_count = 1;

$sn_smtp_state = SMTP_STATE_RR_A;
}
else
{
$sn_smtp_tcp_pid = pid_open("/mmap/tcp$sn_smtp_tcp_id");

echo "sn_smtp: connect to $rr:25...";


pid_connect($sn_smtp_tcp_pid, $rr, 25);

73
$sn_smtp_state = SMTP_STATE_CONNECT;
}

return false;
}

function smtp_loop()
{
global $sn_smtp_state, $sn_smtp_tcp_pid, $sn_smtp_next_tick;
global $sn_smtp_helo_host;
global $sn_smtp_from_email, $sn_smtp_from_name;
global $sn_smtp_rcpt_email, $sn_smtp_rcpt_name;
global $sn_smtp_subject, $sn_smtp_body;

if($sn_smtp_state == SMTP_STATE_IDLE)
return "";

$rbuf = "";

if($sn_smtp_state > SMTP_STATE_CONNECT)


{
$len = pid_ioctl($sn_smtp_tcp_pid, "get rxlen \x0d\x0a");

if(!$len)
{
$state = pid_ioctl($sn_smtp_tcp_pid, "get state");

if($state != TCP_CONNECTED)
{
echo "sn_smtp: connection closed\r\n";

74
if($sn_smtp_state == SMTP_STATE_QUIT)
$rbuf = "221";
else
$rbuf = "";

sn_smtp_cleanup();
return $rbuf;
}

if(sn_smtp_get_tick() >= $sn_smtp_next_tick)


{
echo "sn_smtp: sending email timed out\r\n";
sn_smtp_cleanup();
return "";
}

return false;
}

pid_recv($sn_smtp_tcp_pid, $rbuf, $len);


echo "<< ", $rbuf;

if((substr($rbuf, 0, 1) == "4") || (substr($rbuf, 0, 1) == "5"))


{
for(;;)
{
$len = pid_ioctl($sn_smtp_tcp_pid, "get rxlen
\x0d\x0a");
if(!$len)
break;
pid_recv($sn_smtp_tcp_pid, $rbuf, $len);

75
echo "<< ", $rbuf;
}

sn_smtp_cleanup();
return substr($rbuf, 0, 3);
}
}

switch($sn_smtp_state)
{
case SMTP_STATE_RR_MX:
case SMTP_STATE_RR_A:
if(sn_smtp_loop_rr() === "")
{
sn_smtp_cleanup();
return "";
}
break;

case SMTP_STATE_CONNECT:
$state = pid_ioctl($sn_smtp_tcp_pid, "get state");

if($state == TCP_CONNECTED)
{
echo "ok\r\n";
$sn_smtp_next_tick = sn_smtp_get_tick() + 30000; //
30 seconds
$sn_smtp_state = SMTP_STATE_220;
}
else
if($state == TCP_CLOSED)

76
{
echo "failed\r\n";
sn_smtp_cleanup();
return "";
}
break;

case SMTP_STATE_220:
if(substr($rbuf, 0, 3) == "220")
{
$msg = "HELO $sn_smtp_helo_host\r\n";
pid_send($sn_smtp_tcp_pid, $msg);
echo ">> ", $msg;

$sn_smtp_state = SMTP_STATE_HELO;
}
break;

case SMTP_STATE_HELO:
if(substr($rbuf, 0, 3) == "250")
{
$msg = "MAIL FROM:<$sn_smtp_from_email>\r\n";
pid_send($sn_smtp_tcp_pid, $msg);
echo ">> ", $msg;

$sn_smtp_state = SMTP_STATE_FROM;
}
break;

case SMTP_STATE_FROM:
if(substr($rbuf, 0, 3) == "250")

77
{
$msg = "RCPT TO:<$sn_smtp_rcpt_email>\r\n";
pid_send($sn_smtp_tcp_pid, $msg);
echo ">> ", $msg;

$sn_smtp_state = SMTP_STATE_RCPT;
}
break;

case SMTP_STATE_RCPT:
if(substr($rbuf, 0, 3) == "250")
{
$msg = "DATA\r\n";
pid_send($sn_smtp_tcp_pid, $msg);
echo ">> ", $msg;

$sn_smtp_state = SMTP_STATE_DATA;
}
break;

case SMTP_STATE_DATA:
if(substr($rbuf, 0, 3) == "354")
{
$msg = "From: \"$sn_smtp_from_name\"
<$sn_smtp_from_email>\r\n";
$msg .= "To: \"$sn_smtp_rcpt_name\"
<$sn_smtp_rcpt_email>\r\n";
$msg .= "Subject: $sn_smtp_subject\r\n\r\n";

if(strlen($msg) + strlen($sn_smtp_body) + 5 >=


MAX_STRING_LEN)
{

78
echo "sn_smtp: body too long\r\n";
sn_smtp_cleanup();
return "";
}

$msg .= $sn_smtp_body;
$msg .= "\r\n.\r\n";

pid_send($sn_smtp_tcp_pid, $msg);
echo ">> $msg";

$sn_smtp_state = SMTP_STATE_BODY;
}
break;

case SMTP_STATE_BODY:
if(substr($rbuf, 0, 3) == "250")
{
$msg = "QUIT\r\n";
pid_send($sn_smtp_tcp_pid, $msg);
echo ">> ", $msg;

$sn_smtp_state = SMTP_STATE_QUIT;
}
break;

case SMTP_STATE_QUIT:
sn_smtp_cleanup();
return substr($rbuf, 0, 3);
}

79
return false;
}

function smtp_start($rcpt_email, $rcpt_name, $subject, $body)


{
global $sn_smtp_state, $sn_smtp_tcp_pid;
global $sn_smtp_hostname;
global $sn_smtp_query_name, $sn_smtp_query_count;
global $sn_smtp_from_email, $sn_smtp_from_name;
global $sn_smtp_rcpt_email, $sn_smtp_rcpt_name;
global $sn_smtp_subject, $sn_smtp_body;

if($sn_smtp_from_email == "")
smtp_account("", "");

if($sn_smtp_hostname == "")
sn_smtp_update_helo_host();

$sn_smtp_rcpt_email = $rcpt_email;
$sn_smtp_rcpt_name = $rcpt_name;
$sn_smtp_subject = $subject;

$term_pos = strpos($body, "\r\n.\r\n");

if($term_pos === false)


$sn_smtp_body = $body;
else
{
echo "sn_smtp: message body truncated\r\n";
$sn_smtp_body = substr($body, 0, $term_pos + 2);
}

80
$offset = strpos($rcpt_email, "@");

if($offset === false)


echo "sn_smtp: invalid email address\r\n";
else
{
$domain = substr($rcpt_email, $offset + 1);
dns_send_query($domain, RR_MX, 500);

$sn_smtp_query_name = $domain;
$sn_smtp_query_count = 2;

$sn_smtp_state = SMTP_STATE_RR_MX;
}
}

function smtp_send($rcpt_email, $rcpt_name, $subject, $body)


{
smtp_start($rcpt_email, $rcpt_name, $subject, $body);

while(1)
{
$msg = smtp_loop();

if($msg === false)


usleep(1000);
else
return $msg;
}
}

81
?>

82
APPENDIX - E
DOMAIN NAME SERVICES CODES
<?php
define("RR_A", 1); // Address record
define("RR_NS", 2); // Name Server record
define("RR_CNAME", 5); // Canonical name record
define("RR_SOA", 6); // Start Of Authority record
define("RR_MX", 15); // Mail eXchange record
define("RR_AAAA", 28); // IPv6 Address record
define("DNS_CACHE_TIMEOUT", 30);

$sn_dns_id = 0;
$sn_dns_pid = 0;
$sn_dns_tid = 0;
$sn_dns_ip6 = false;
$sn_dns_server = "";
$sn_dns_cache_host = "";
$sn_dns_cache_type = 0;
$sn_dns_cache_addr = "";
$sn_dns_query_name = "";
$sn_dns_query_type = 0;
$sn_dns_timeout_query = 0;
$sn_dns_timeout_cache = 0;
function sn_dns_get_tick()
{
while(($pid = pid_open("/mmap/st9", O_NODIE)) == -EBUSY)
usleep(500);
if(!pid_ioctl($pid, "get state"))
pid_ioctl($pid, "start");
$tick = pid_ioctl($pid, "get count");
pid_close($pid);

return $tick;
83
}
function sn_dns_cleanup()
{
global $sn_dns_timeout_query;
global $sn_dns_pid;
pid_close($sn_dns_pid);
$sn_dns_pid = 0;
$sn_dns_timeout_query = 0;
}

function sn_dns_update_cache($name, $type, $addr)


{
global $sn_dns_cache_host, $sn_dns_cache_type, $sn_dns_cache_addr;
global $sn_dns_timeout_cache;
$sn_dns_cache_host = $name;
$sn_dns_cache_type = $type;
$sn_dns_cache_addr = $addr;

$sn_dns_timeout_cache = sn_dns_get_tick() + DNS_CACHE_TIMEOUT *


1000;
}

function sn_dns_find_cache($name, $type)


{
global $sn_dns_cache_host, $sn_dns_cache_type, $sn_dns_cache_addr;
global $sn_dns_timeout_cache;
if(sn_dns_get_tick() >= $sn_dns_timeout_cache)
return "";
if(($name == $sn_dns_cache_host) && ($type == $sn_dns_cache_type))
return $sn_dns_cache_addr;
else
return "";
}
84
function sn_dns_encode_name($name)
{
$enc = "";
while($name)
{
$len = strpos($name, ".");
if($len === false)
{
$enc .= int2bin(strlen($name), 1);
$enc .= $name;
break;
}
else
if($len > 0)
{
$enc .= int2bin($len, 1);
$enc .= substr($name, 0, $len);
$name = substr($name, $len + 1);
}
else
{
echo "sn_dns: invalid RR name $name\r\n";
return "";
}
}

$enc .= "\x00";

return $enc;
}

85
function sn_dns_decode_name($name, &$rbuf)
{
$dec = "";
for(;;)
{
$len = bin2int($name, 0, 1);
if($len & 0xc0)
{
$len = bin2int($name, 0, 2, true) & 0x3fff;
$name = substr($rbuf, $len);
continue;
}
$dec .= substr($name, 1, $len);
$name = substr($name, 1 + $len);
if(bin2int($name, 0, 1))
$dec .= ".";
else
return $dec;
}
}

function sn_dns_skip_name(&$name)
{
do
{
$len = bin2int($name, 0, 1);

if($len & 0xc0)


{
$name = substr($name, 2);
return;
}

86
if((1 + $len) > strlen($name))
$len = strlen($name) - 1;

$name = substr($name, $len + 1);


}while($len && $name);
}
function dns_setup($udp_id, $server_addr = "", $ip6 = false)
{
global $sn_dns_id, $sn_dns_tid;
global $sn_dns_ip6, $sn_dns_server;
$sn_dns_id = $udp_id;
$sn_dns_ip6 = $ip6;
if($server_addr && ($server_addr != "0.0.0.0") && ($server_addr != "::0"))
$sn_dns_server = $server_addr;
else
$sn_dns_server = "";

if(!$sn_dns_tid)
$sn_dns_tid = rand(0, 65536);
}
function sn_dns_setup_pid()
{
global $sn_dns_id, $sn_dns_pid;
global $sn_dns_ip6, $sn_dns_server;

if($sn_dns_pid)
pid_close($sn_dns_pid);
$sn_dns_pid = pid_open("/mmap/udp$sn_dns_id");
pid_ioctl($sn_dns_pid, "set dstport 53");
if($sn_dns_server)
{

87
pid_ioctl($sn_dns_pid, "set dstaddr $sn_dns_server");
return true;
}
if((int)ini_get("init_net0"))
$pid_net = pid_open("/mmap/net0");
else
$pid_net = pid_open("/mmap/net1");
if($sn_dns_ip6)
{
$nsaddr6 = pid_ioctl($pid_net, "get nsaddr6");
pid_close($pid_net);

if($nsaddr6 == "::0")
return false;

pid_ioctl($sn_dns_pid, "set dstaddr $nsaddr6");


}
else
{
$nsaddr = pid_ioctl($pid_net, "get nsaddr");
pid_close($pid_net);
if($nsaddr == "0.0.0.0")
return false;
pid_ioctl($sn_dns_pid, "set dstaddr $nsaddr");
}
return true;
}
function dns_send_query($name, $type, $timeout = 2000)
{
global $sn_dns_pid, $sn_dns_tid;
global $sn_dns_query_name, $sn_dns_query_type;
global $sn_dns_timeout_query;

88
if(!$sn_dns_tid)
dns_setup(0, "");
if(!sn_dns_setup_pid())
{
echo "sn_dns: destination unreachable\r\n";
return 0;
}
$sn_dns_query_name = $name;
$sn_dns_query_type = $type;
$sn_dns_tid++;
$query = int2bin($sn_dns_tid, 2, true);
$query .= hex2bin("0100"); // QR(0), OPCODE(0), AA(0), TC(0), RD(1),
RA(0), Z(0), RCODE(0)
$query .= hex2bin("0001"); // question count 1
$query .= hex2bin("0000"); // answer count 0
$query .= hex2bin("0000"); // name server count 0
$query .= hex2bin("0000"); // additional count 0
$query .= sn_dns_encode_name($name);
$query .= int2bin($type, 2, true); // qtype
$query .= hex2bin("0001"); // class : IN
$len = pid_sendto($sn_dns_pid, $query);
if(!$len)
echo "sn_dns: sendto failed\r\n";
$sn_dns_timeout_query = sn_dns_get_tick() + $timeout;
return strlen($query);
}
function sn_dns_find_answer(&$response)
{
global $sn_dns_query_type;

$questions = bin2int($response, 4, 2, true);


$answers = bin2int($response, 6, 2, true);
89
if(!$answers)
{
echo "sn_dns: query failed\r\n";
return "";
}
$pbuf = substr($response, 12); // skip dns header
for($i = 0; $i < $questions; $i++)
{
sn_dns_skip_name($pbuf); // skip QNAME
$pbuf = substr($pbuf, 4); // skip QTYPE/QCLASS
}

for($i = 0; $i <= $answers; $i++)


{
sn_dns_skip_name($pbuf); // skip NAME
$rr_type = bin2int($pbuf, 0, 2, true);
$pbuf = substr($pbuf, 4); // skip TYPE/CLASS
$pbuf = substr($pbuf, 4); // skip TTL
$rd_len = bin2int($pbuf, 0, 2, true);
$pbuf = substr($pbuf, 2); // skip RDLENGTH
if($rr_type == $sn_dns_query_type)
{
switch($sn_dns_query_type)
{
case RR_A:
return inet_ntop(substr($pbuf, 0, 4));
case RR_NS:
return sn_dns_decode_name($pbuf, $response);
case RR_MX:
$pbuf = substr($pbuf, 2); // skip PREFERENCE
return sn_dns_decode_name($pbuf, $response);

90
case RR_AAAA:
return inet_ntop(substr($pbuf, 0, 16));
}
}
$pbuf = substr($pbuf, $rd_len); // skip RDATA
}
echo "sn_dns: expected answer not found\r\n";
return "";
}
function dns_loop()
{
global $sn_dns_pid;
global $sn_dns_query_name, $sn_dns_query_type;
global $sn_dns_timeout_query;
if(!$sn_dns_timeout_query) // query not sent or timed out
return "";
if(sn_dns_get_tick() >= $sn_dns_timeout_query)
{
echo "sn_dns: lookup timeout\r\n";
sn_dns_cleanup(); // close pid & reset $sn_dns_timeout_query
return "";
}
if(!pid_ioctl($sn_dns_pid, "get rxlen"))
return false;
$rbuf = "";
pid_recvfrom($sn_dns_pid, $rbuf);
sn_dns_cleanup(); // close pid & reset $sn_dns_timeout_query
$addr = sn_dns_find_answer($rbuf);
if($addr)
sn_dns_update_cache($sn_dns_query_name, $sn_dns_query_type,
$addr);
return $addr;
}
91
function dns_lookup($name, $type, $timeout = 2000)
{
if($addr = sn_dns_find_cache($name, $type))
return $addr;
dns_send_query($name, $type, $timeout);
while(1)
{
$rr = dns_loop();
if($rr === false)
usleep(1000);
else
{
if($rr == "")
return $name;
else
return $rr;
}
}
}

?>

92
APPENDIX - F

Plate F.1: An image of a typical African Catfish (Okechi, 2004)

Plate F.2: An Image of the Fish Farm Premises

93
Plate F.3: An Image of the Fish Fingerlings Tank

94
APPENDIX - G
MATERIALS USED

Plate G.1: A labelled diagram of the PHPoC Blue Microcontroller (Soalle Systems,
2018) that was used.

Plate G.2: pH Sensing Unit represented by the pH sensor module and P4S-342

95
Plate G.3: A comparative scale describing the conversion ADC readings by the P4S-
342 to the corresponding voltages

Plate G.4: The Personal Computer used for programming the P4S-342 microcontroller
and monitoring serial outputs

96
Plate G.5: An image of the remote monitoring device used (an android smartphone)

Plate G.6: pH reagent with its pH colour chart.

97
Plate G.7: pH reagent colour chart

Plate G-8: Buffer solution 4, 7, and 9.2 which were used in this work

98
Table G.1: 802.11n specification (Abdelrahman, Mustafa, & Osman, 2015)

802.11 Release Frequency Bandwidth Stream Allowable Modulation Approx. Approx.


protocol date (GHz) (MHz) Data MIMO Antenna In (m) Out (m)
Rate streams Tech.
(Min-
Max)
n Oct-09 2.4/5 20 7.2 - 4 OFDM 70 250
72.2 (MIMO)
(6.5-
65)
40 15 - 70 250
150
(13.5 -
135)

99

You might also like