Professional Documents
Culture Documents
Progress Report
Submitted By:
Muhammad Umair 170401022
Abdullah Waraitch 170401020
Submitted to:
Sir Bilal khan
Sir Ghayas Udin
Section: EE-16-B
BE-Electrical Engineering.
IoT Based Agriculture Monitoring System
Objective:
• To take Sensors data from nodes
• Reduction of power consumption of Nodemcu
• Measurement of Current rating of different components
• Coding on Arduino IDE Software
• observe data collected by the nodemcu ESP 8266 over the internet
Procedure:
Data from nodes:
We have connected Dht11 and Soil Moisture Sensor to NodeMcu-Esp8266
module. We powered the module by connecting it to 5v supply. Then we write
code for Dht11 and Soil moisture in Arduino IDE Software.We upload this code to
Nodemcu module by using this software.When we power the module we able to
see sensors data on serial monitor.
Reduction of power consumption
The ESP8266 power consumption is between 15μA and 400mA depending on
different cases. In idle state with powered Wi-Fi the current consumption around
70mA.With an operating voltage of 3.3V a NodeMCU V2 needs the following
power in idle state:
W = U * I = 3.3V * 70mA = 231mW
If we buy a battery with 1000mAh (Operation voltage: 3.7V), how long will it take
until we must change the battery pack?
T = 1000mAh / 70mA = 14.3h
So we must change the battery every day. That does not make sense.
We have two options to extend the time to charge the battery pack.
• Buy a battery with a higher capacity.
• Reduce the power consumption of the ESP8266 microcontroller.
Deep sleep Mode:
To enable the deep-sleep mode we only must use the following line of code:
// ESP.deepSleep(uint32 time_in_us);
where we define a time, when the ESP8266 will wake up from the deep-sleep
mode. The maximum time in deep-sleep is 4,294,967,295 μs, which is about ~71
minutes.
In this mode, the chip will turn off Wi-Fi connectivity and data connection; only
the RTC module is still working, responsible for periodic wake-ups.
Experimental Measurement:
NodeMcu esp8266
DHT11 Sensor
Conclusion:
By using deep sleep mode we have extended the time to charge battery. By normal
working of nodemcu, we must recharge battery after 14 hours but by using deep
sleep mode we can charge it after a week if we have 1000mAh of battery.If we
have a battery with high capacity then it can work for months or a year.
Software Part
To observe data collected by the node mcu ESP 8266 over the internet and on the
mobile application as well.
Procedure:
First, we used the usb to connect the node mcu with laptop to power the node mcu
and insert the code so it could identify the sensors attached to the node mcu. Code
is as follows:
#include <ESP8266WiFi.h>
#include "DHT.h"
#define DHTPIN D1
#define DHTTYPE DHT11
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
}
void loop() {
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
delay(3000);
}
In this code we directed the node mcu to send the data to the webhosting site where
we will the save the data and further we will use this data to display on the mobile
application as well. Currently the node mcu collects data after 3 secs we will
change this to single reading per hour.
This is our web host where we are saving the data collected.
Link to the website is
“https://www.000webhost.com/members/website/mabw17/dashboar
d”
Further these are screenshots of where and how it collects the data and
saves it. Ill add codes as well.
These are the APIS where all the codes that were requires by the node mcu in order
to connect to this web hosting server and after connecting sending data to it. These
are coded in the way like if any needs the passwords it will the file named
db_config.php. separate files are doing separate work and interconnecting through
function calling wherever one needs another.
Here are the codes of each file shown above in the Snapshot.
db_connect.php
“
<?php
class DB_CONNECT {
// Constructor
function __construct() {
// Trying to connect to the database
$this->connect();
}
// Destructor
function __destruct() {
// Closing the connection to database
$this->close();
}
require_once($filepath."/dbconfig.php");
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or
die(mysql_error());
?>
“
db_config.php
“
<?php
?>
“
delete.php
“
<?php
// Connecting to database
$db = new DB_CONNECT();
$temp = $_GET['temp'];
$hum = $_GET['hum'];
// Connecting to database
$db = new DB_CONNECT();
$response["success"] = 1;
$response["weather"] = array();
<head>
<meta charset="UTF-8">
<title>GFG User Details</title>
<!-- CSS FOR STYLING THE PAGE -->
<style>
table {
margin: 0 auto;
font-size: large;
border: 1px solid black;
}
h1 {
text-align: center;
color: #006600;
font-size: xx-large;
font-family: 'Gill Sans', 'Gill Sans MT',
' Calibri', 'Trebuchet MS', 'sans-serif';
}
td {
background-color: #E4F5D4;
border: 1px solid black;
}
th,
td {
font-weight: bold;
border: 1px solid black;
padding: 10px;
text-align: center;
}
td {
font-weight: lighter;
}
</style>
</head>
<body>
<section>
<h1>mabw17</h1>
<!-- TABLE CONSTRUCTION-->
<table>
<tr>
<th>id</th>
<th>temp</th>
<th>hum</th>
</tr>
<!-- PHP CODE TO FETCH DATA FROM ROWS-->
<?php // LOOP TILL END OF DATA
while($rows=$result->fetch_assoc())
{
?>
<tr>
<!--FETCHING DATA FROM EACH
ROW OF EVERY COLUMN-->
<td><?php echo $rows['Id'];?></td>
<td><?php echo $rows['temp'];?></td>
<td><?php echo $rows['hum'];?></td>
</tr>
<?php
}
?>
</table>
</section>
</body>
</html>
“
update.php
“
<
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
//Creating Array for JSON response
$response = array();
}
} else {
// If required parameter is missing
$response["success"] = 0;
$response["message"] = "Parameter(s) are missing. Please check the request";
Conclusion
Basically we had covered the objective in which we had to collect and showcase
the data collected over the internet. Now, the part in which in which we have to
showcase the data in the mobile application in the progress and we are facing
problems. First one is we were unable to make connection between the app and our
database. We have found few solutions over the internet and we are working on
them to eradicate this issue and complete our project.