Professional Documents
Culture Documents
Chimdi - Project Def - Copy Through
Chimdi - Project Def - Copy Through
FACULTY OF ENGINEERING,
FACULTY OF ENGINEERING,
i
DECLARATION
_________________________ _____________________
SIGNATURE DATE
ii
CERTIFICATION
This is to certify that the thesis presented by Chukwu, Chimdi Ogbonnaya with the matriculation
meets the requirements of thesis report for the award of Masters of Engineering degree in the Faculty
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
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
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.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
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.7 Real-time remote pH value display from the buffer 9.2 solution 45
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.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
x
LIST OF ACRONYMS
IP Internet Protocol
PC Personal Computer
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
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
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
1
Dissolved Oxygen (DO)
pH
Temperature
Ammonia (NH4+)
Nitrates (N2O-)
Salinity
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
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.
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
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
3
approach for the production environment. This is of concern as there exists the tendency
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
The work done by (Africa et. al., 2017) has plausible features such as a database, and a
comes with subscription costs which will constitute an extra financial strain that can be
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
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
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
4
standard with the ability to send alerts using email. The system will be developed with
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
The objectives to be accomplished in the course of designing and validating this system
are:
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
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 -
The result from both approaches would be compared for the sake of validating the
developed system.
levels
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
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.
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,
The second chapter has reviews of various literature that were studied. Other works
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.
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
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
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
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
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
Relating the reference voltage to the maximum discrete value provides a platform for
9
Figure 2-1 A Picture of a PIC16F84A Microcontroller (Microchip, 2017)
10
2.3 TCP/IP
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
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 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
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.,
Table 2.1: The table shows the TCP/IP protocol layers with examples protocols
(Oracle, 2010)
12
2.6 Wireless Sensor Network
in space to observe physical parameters, such as pressure, Light, vibration, etc. and to
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
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
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+]
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
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
14
Figure 2.2 A pH-acid volume relationship graph showing increasing Acidity
(Clark, 2013)
(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
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
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.
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
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
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
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
18
Table 2.2: Water quality parameters and their standard values (Banrie, 2012),
(Towers, 2014)
pH 7.5-8.5
Hardness 40 – 400ppm
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
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
(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
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
demonstrated by (Rao, et al., 2013) for the purpose of continuous pH, light,
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
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
obtain parameter information on DO, water level, salinity, pH, turbidity and nitrite,
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
22
CHAPTER THREE
RESEARCH METHODOLOGY
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
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
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
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
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
24
Figure 3.1 Workflow of the research
25
3.3 Materials
chemical materials. The following subsection itemizes the items used in the course of
this work.
The hardware components that were used are as follows (images can be seen in
Appendix - B):
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.
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
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.
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
27
Table 3.1: Specification of the pH sensor according to (DFrobot, 2016)
28
Figure 3.2: Flowchart showing how the P4S-342 executes its actions
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
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
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
iv. WebSocket: The WebSocket protocol was used to ensure a steady stream of pH
WebSocket also eliminates the need for page refreshes to get the last read pH
value.
The Operating System used was the MS Windows 8.1. It served as a platform to run
31
3.3.2.3 PHPoC Debugger IDE
The PHPoC debugger Integrated Development Environment (IDE) is the tool used for
i. PHPoC: The backend language which is used to control web server, read from
ii. JavaScript and Hypertext Markup Language: These are frontend languages
on the receiver device. They also used to make requests for sensor values and
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.
Some chemical materials were used while carrying out this work, and they are:
ii. pH Reagent
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
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
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
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
Table 3.4: Buffers 4, 7, and 9.2 solutions voltage reading during pH meter insertion
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
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
𝑦 = 𝑚𝑥 + 𝑐 (3.2)
Where:
𝑦 = 𝑐𝑜𝑟𝑟𝑒𝑠𝑝𝑜𝑛𝑑𝑖𝑛𝑔 𝑝𝐻 𝑣𝑎𝑙𝑢𝑒
𝑚 = 𝑔𝑟𝑎𝑑𝑖𝑒𝑛𝑡 𝑜𝑓 𝑠𝑙𝑜𝑝𝑒
∆𝑦 = 𝑚∆𝑥 (3.3)
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
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)
The pH function gotten in Equation 4.11 was used in the development of the code used
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
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.
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
The water samples would be tested using the pH reagent. The pH reagent makes use of
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
38
39
CHAPTER FOUR
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
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 results of the proposed work are presented and validated in this chapter.
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
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
40
Figure 4.1: IPv4 Network details of the microcontroller while on the WLAN
GATEWAY
DEVICE
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
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,
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
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
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
46
Figure 4.8: An email alert received from the pH monitoring system
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
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
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
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.
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
5.1 Summary
In the bid to ensure that the fish farm being studied can reach its peak potentials and
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
5.2 Conclusions
sensing for real-time situation access and report is achievable using IoT is workable.
environment’s pH level with a very good level of accuracy. pH was able to be measured
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
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
i. The proposed linear pH model can be put to test in the development WSNs of
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
improve life and further the growth of humanity’s well-being and create room
development.
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
operational for too long. Getting pH probes and measurement modules within
51
ii. Difficulty in access to resource materials
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
completion time. There also were very few programming libraries for the
i. The proposed designed pH model can help to accurately detect pH levels and
water samples.
ii. The proposed system allows for remote monitoring in a WLAN and alerts using
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
<?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);
$last_adc_in = 0;
$pH_voltage = 0.00;
$pH_last = 0.0;
while(1)
{
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($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";
if($msg == "221")
58
echo "send email successful\r\n";
else
echo "send email failed\r\n";
}
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
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
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;
$pid = $sn_tcp_ws_pid[$tcp_id];
if($pid)
pid_close($pid);
$pid = pid_open("/mmap/tcp$tcp_id");
pid_listen($pid);
$sn_tcp_ws_pid[$tcp_id] = $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;
}
return 0;
}
64
if(pid_ioctl($pid, "get state") == TCP_CLOSED)
pid_listen($pid);
return 0;
}
if($len)
return pid_recv($pid, $rbuf, $len);
return 0;
}
if($state == TCP_CONNECTED)
{
if($wlen > strlen($wbuf))
65
$wlen = strlen($wbuf);
return 0;
}
function ws_txfree($tcp_id)
{
$pid = ws_check_get_pid($tcp_id, "ws_txfree");
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");
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);
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);
}
sn_smtp_cleanup();
$sn_smtp_tcp_id = $tcp_id;
$sn_smtp_ip6 = $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;
}
}
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 == "")
{
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");
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(!$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;
}
return false;
}
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";
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;
}
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;
80
$offset = strpos($rcpt_email, "@");
$sn_smtp_query_name = $domain;
$sn_smtp_query_count = 2;
$sn_smtp_state = SMTP_STATE_RR_MX;
}
}
while(1)
{
$msg = smtp_loop();
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;
}
$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);
86
if((1 + $len) > strlen($name))
$len = strlen($name) - 1;
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;
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;
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
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)
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)
99