Professional Documents
Culture Documents
Submitted in
partial fulfillment of the requirements
for the award of the
INTERNSHIP
in
INTERNET OF THINGS
by
ALBYN BABU
July 2018
Abstract
1 Introduction 5
2 Literature Survey 8
3 Proposed Method 9
3.1 Hardware and Things Network . . . . . . . . . . . . . . . . . . 10
3.1.1 Node For Water Quality Measurement . . . . . . . . . 10
3.2 Data-Base Management . . . . . . . . . . . . . . . . . . . . . 12
3.3 API Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.1 D3.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.2 Data representation using Chart . . . . . . . . . . . . . 17
3.4.3 Dashboard . . . . . . . . . . . . . . . . . . . . . . . . . 17
References 21
2
List of Figures
3
Listings
4
Chapter 1
Introduction
Water bodies such as rivers, canals are being polluted by various indus-
trial as well as domestic activities to an extent that aquatic beings can’t
even survive. Over the years, number of industries increased, that finding
the source and extent of pollution became more difficult. Research says that
the unchecked urban waste pollution has severely affected the natural ecol-
ogy of major freshwater sources in the city. This happens due to the source
of the pollution is unknown.
At the present, water quality in canal is measured by gathering a sam-
ple of canals water, which is done at a selected location on canals surface.
The sample will be examined in laboratories to get the result of water qual-
ity, which is used as the parameter to decide if the water is polluted. This
process, which is taken numerous times for effective measurement, takes rel-
atively long time, also cost a considerable amount of money. To minimize
sampling time and cost, the measurement process has to be done by imple-
menting computer and information technology
So we introduce a way to identify the source of pollution by the use of
IoT Technology. This can be done by measuring pH, Turbidity as well as the
5
Identifying the Sources of Water Pollution using Open IoT
oxygen level of water. This data can be processed and transmitted to cloud
using LoRa Technology and visualized using D3.js
Water quality is identified by using different parameters such as pH, Dis-
solved Oxygen , Turbidity, Air Temperature and Air Humidity.
pH holds an important part of determining whether aquatic life can use
it or not. They greatly influence the availability and solubility of all chemical
forms in the lake and may aggravate nutrient problems, the high pH level
may be affected from the high algae and water plant growth. The pH scales
from 0 to 14, and the normal lake waters hovers between 6.5 to 8.5.
High levels of nutrients fuel algae blooms, which can initially boost dis-
solved oxygen levels. But more algae mean more plant respiration, drawing
on DO, and when the algae die, bacterial decomposition spikes, using up most
or all of the dissolved oxygen available. This creates an anoxic, or oxygen-
depleted, environment where fish and other organisms cannot survive. Such
nutrient levels can occur naturally, but are more often caused by pollution
from fertilizer runoff or poorly treated waste water, the DO level of a shallow
water in the lake supposed to be around 4-15 mg/L, the higher the better
for freshwater fish to survive.
Turbidity is caused by particles suspended or dissolved in water that scat-
ter light making the water appear cloudy or murky. Particulate matter can
include sediment - especially clay and silt, fine organic and inorganic mat-
ter. High turbidity can significantly reduce the aesthetic quality of lakes and
streams, having a harmful impact on recreation and tourism. It can increase
the cost of water treatment for drinking and food processing. It can harm
fish and other aquatic life .
Temperature is also important because of its influence in water chemistry.
An important example of the effects of temperature on water chemistry is its
6
Identifying the Sources of Water Pollution using Open IoT
impact on oxygen. Warm water holds less oxygen than cool water, so it may
be saturated with oxygen but still not contain enough for survival of aquatic
life.
The proposed method help to analyze the source of pollution through an
effective way.
7
Chapter 2
Literature Survey
8
Chapter 3
Proposed Method
• Casing
• API Creation
• Data-Base Management
• Visualization
9
Identifying the Sources of Water Pollution using Open IoT
• LoRa Gateway
• Things Network
The Node basically consist of water quality measurement sensors such as Dis-
solved oxygen sensor, turbidity sensor, and a temperature/humidity sensor
which are interfaced with an MCU with Embedded LoRa module. We used
LoRa32u4 by BsFrance Inc as the MCU.
LoRa
10
Identifying the Sources of Water Pollution using Open IoT
Sensors
11
Identifying the Sources of Water Pollution using Open IoT
12
Identifying the Sources of Water Pollution using Open IoT
that pushes the data to and fetches data from database using Python that
is discussed later.
1 #C o n f i g u r e DB s e t t i n g s
2 app . c o n f i g [ ’MONGODBNAME’ ] = ” w a t e r p o l l u t i o n ”
3 app . c o n f i g [ ’MONGO URI ’ ] =
4 ”mongodb : / / 1 6 7 . 9 9 . 1 9 8 . 1 4 5 : 2 7 0 1 7 / w a t e r p o l l u t i o n ”
13
Identifying the Sources of Water Pollution using Open IoT
• POST Request
• GET Request
POST Request is used to store the data from the Things Network to
the Database. In the POST method we assigned the values from TTN to
specific variables and pushed it to the database as shown in the following
code snippet.
1 def post ( s e l f ) :
2 request = dataParser . parse args ()
3 payload = p a y l o a d P a r s e r . p a r s e a r g s ( r e q=r e q u e s t )
4 metaData = metadataPars er . p a r s e a r g s ( r e q=r e q u e s t )
5 dateTimeStr = metaData [ ’ time ’ ]
6 dateTime = dateTimeStr . s p l i t ( ”T” )
7 d a t e = dateTime [ 0 ]
8 time = dateTime [ 1 ] . s p l i t ( ” . ” ) [ 0 ]
9 new data = {
10 ’ dev id ’ : request [ ’ dev id ’ ] ,
11 ’DO ’ : payload [ ’DO ’ ] ,
12 ’hum ’ : payload [ ’hum ’ ] ,
13 ’ temp ’ : payload [ ’ temp ’ ] ,
14 ’ t u r b i d i t y ’ : payload [ ’ t u r b i d i t y ’ ] ,
15 ’ d a t e ’ : date ,
16 ’ time ’ : time
14
Identifying the Sources of Water Pollution using Open IoT
17 }
18 data = mongo . db . data
19 p o s t i d = data . i n s e r t ( new data )
20 p o s t i n s e r t e d = data . f i n d o n e ( { ’ i d ’ : p o s t i d } )
21 new data = {
22 ’ dev id ’ : post inserted [ ’ dev id ’ ] ,
23 ’DO ’ : p o s t i n s e r t e d [ ’DO ’ ] ,
24 ’hum ’ : p o s t i n s e r t e d [ ’hum ’ ] ,
25 ’ temp ’ : p o s t i n s e r t e d [ ’ temp ’ ] ,
26 ’ turbidity ’ : post inserted [ ’ turbidity ’ ] ,
27 ’ date ’ : p o s t i n s e r t e d [ ’ date ’ ] ,
28 ’ time ’ : p o s t i n s e r t e d [ ’ time ’ ]
29 }
30 r e t u r n { ” s u c c e s s ” : True , ” data ” : new data } , 201
GET Request is used to retrieve the data from the Database and given to
the visualization part. For that we took the required fields from the document
inside the database using the following code snippet.
1 #C r e a t e Resource f o r data
2 c l a s s waterData ( Resource ) :
3 def get ( s e l f ) :
4 data = mongo . db . data
5 output = [ ]
6 f o r q i n data . f i n d ( ) . s o r t ( ” i d ” , −1) . l i m i t ( 1 5 ) :
7 output . append ( {
8 ’ date ’ : q [ ’ date ’ ] ,
9 ’ time ’ : q [ ’ time ’ ] ,
10 ’hum ’ : q [ ’hum ’ ] ,
11 ’ temp ’ : q [ ’ temp ’ ] ,
12 ’ turbidity ’ : q [ ’ turbidity ’ ] ,
13 ’DO ’ : q [ ’DO ’ ]
15
Identifying the Sources of Water Pollution using Open IoT
14 })
15 r e t u r n output
3.4 Visualization
All the data will be useless when it cant represent in a proper way and that
cannot understand by the user. Data visualization helps to represent our
data to the right people, at the right time, enables to gain knowledge in
an effective way. Currently visualization solutions have evolved as rapidly.
Charts, videos, info graphics and at the cutting edge even virtual reality
and augmented reality (VR & AR) presentations offer increasingly engaging
and intuitive channels of communication[1]. There are so many tools such
as chart.js, Tableau, Qlikview, FusionChart, Highcharts etc. For our project
we use d3.js visualization tool.
3.4.1 D3.js
16
Identifying the Sources of Water Pollution using Open IoT
json from the api mentioned and the drawing function that describes how
the data has to be represented before users like line or bar or bubble chart
is called.
1 // Get t h e data from API
2 d3 . j s o n ( ” h t t p : / / 1 6 7 . 9 9 . 1 9 8 . 1 4 5 / a p i / data ” , f u n c t i o n ( e r r o r , data )
{
3 i f ( e r r o r ) throw e r r o r ;
4 // C a l l f u n c t i o n from p l o t t i n g
5 draw ( data ) ;
6 }) ;
Here we are using bar chart and line chart for representation of data. Data
is stored in the database(MongoDB). From MongoDB data is taken to the
api using python flask. In the api data are in json format. D3.js call the json
file in api for chart drawing. PH,humidity,dissolved oxygen,temperature are
the data from the sensors. As aim of our project is to find the source of the
water get polluted, we plot four chart respected to the time and date. Real
time data are represented using line chart and historical data are represented
using bar chart.
3.4.3 Dashboard
The dashboard the appealing look for the presentation is designed using boot-
strap available over the internet. The bootstrap template was downloaded
and was carefully edited in order it could accommodate our JavaScript code
that are used for graph creation. Required JavaScript codes and CSS files
17
Identifying the Sources of Water Pollution using Open IoT
were attached along with using cdn itself. The scripts were embedded inside
the div of the card that we see and an auto refresh of 10 seconds is set using
meta in HTML head, which will refreshes the graphs and thus helps in plot-
ting the real time data from the database which is automatically updated
when the TTN sends data. The dashboard screenshots and the graphs are
plotted herewith in following pages.
18
Identifying the Sources of Water Pollution using Open IoT
19
Chapter 4
The focus on our project is to measure the water quality parameters and
identify the source for water pollution in canals. We implemented an IoT
solution for this. Sensors continuously monitor water polluting factors and
it is passed to The Things Network using LoRa, the comparison values can
be displayed using D3.js.
The future of our project is vast as it is very economic and is relevant
to the society. The casing designed is inefficient for releasing it to the open
market and hence has to redesigned. As well as the wiring could be removed
and implement it to a PCB board. More features like time range facility to
view and analyze the graph could be incorporated. The dashboard could be
redesigned to fit for responsive features.
20
References
[5] Real Time Monitoring System for Water Pollution in Lake Toba Romi
Fadillah Rahmat, Athmanathan, Mohammad Fadly Syahputra, Maya
Silvi Lydia Real Time Monitoring System for Water Pollution in Lake
Toba Romi Fadillah Rahmat, Athmanathan, Mohammad Fadly Syahpu-
tra, Maya Silvi Lydia
[6] Water Quality Monitoring and Waste Management using IoT Maneesha
V Ramesh, Nibi K V
21
Identifying the Sources of Water Pollution using Open IoT
22