Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-104
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-104
2022-104
Commits
67f8fbc1
Commit
67f8fbc1
authored
Oct 10, 2022
by
D.L.Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated version of Spreadsheet_data
parent
2d735eaf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
194 additions
and
0 deletions
+194
-0
spreadsheet_data_latest.ino
spreadsheet_data_latest.ino
+194
-0
No files found.
spreadsheet_data_latest.ino
0 → 100644
View file @
67f8fbc1
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include "DHT.h"
#define DHTTYPE DHT22 //--> Defines the type of DHT sensor used,in this project the sensor used is DHT2.
const
int
DHTPin
=
4
;
//--> Pin D1 = GPIO4
DHT
dht
(
DHTPin
,
DHTTYPE
);
#define ON_Board_LED 2
int
relayInput
=
12
;
//----------------------------------------SSID and Password of your WiFi router.
const
char
*
ssid
=
"derick2"
;
const
char
*
password
=
"derickgeroutereka1"
;
//----------------------------------------Google spreadsheet host & httpsPort
const
char
*
host
=
"script.google.com"
;
const
int
httpsPort
=
443
;
//----------------------------------------
WiFiClientSecure
client
;
//--> Create a WiFiClientSecure object.
String
GAS_ID
=
"AKfycbwETCQ_Kz6KOTWnQj5y1_xczrK6FVbYuhko9UZMM_kHUblLl-lddju9wz30J5p7EkHfpg"
;
//--> Google spreadsheet script ID
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int
servoPin
=
13
;
// Create a servo object
Servo
Servo1
;
//==============================================================================
void
setup
()
{
Servo1
.
attach
(
servoPin
);
//-----Pin define for the moisture sensor
pinMode
(
A0
,
INPUT
);
Serial
.
begin
(
115200
);
delay
(
500
);
dht
.
begin
();
//--> Start reading DHT22 sensors
delay
(
500
);
WiFi
.
begin
(
ssid
,
password
);
//--> Connect to your WiFi router
Serial
.
println
(
""
);
pinMode
(
ON_Board_LED
,
OUTPUT
);
//--> On Board LED on for board testing
digitalWrite
(
ON_Board_LED
,
HIGH
);
//--> Turn off Led On Board
//------------Wait for connection
Serial
.
print
(
"Connecting"
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
Serial
.
print
(
"."
);
//----------------------------------------Make the On Board Flashing LED on the process of connecting to the wifi router.
digitalWrite
(
ON_Board_LED
,
LOW
);
delay
(
250
);
digitalWrite
(
ON_Board_LED
,
HIGH
);
delay
(
250
);
digitalWrite
(
ON_Board_LED
,
LOW
);
delay
(
250
);
}
//----------------------------------------
digitalWrite
(
ON_Board_LED
,
HIGH
);
//--> Turn off the On Board LED when it is connected to the wifi router.
//----------------------------------------If successfully connected to the wifi router, the IP Address will display
Serial
.
println
(
""
);
Serial
.
print
(
"Successfully connected to : "
);
Serial
.
println
(
ssid
);
Serial
.
print
(
"IP address: "
);
Serial
.
println
(
WiFi
.
localIP
());
Serial
.
println
();
client
.
setInsecure
();
// We need to attach the servo to the used pin number
Servo1
.
attach
(
servoPin
);
// Make servo go to 90 degrees
Servo1
.
write
(
90
);
delay
(
1000
);
Servo1
.
write
(
0
);
delay
(
1000
);
pinMode
(
relayInput
,
OUTPUT
);
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
int
moisture
=
analogRead
(
A0
);
// Make servo go to 0 degrees
Serial
.
println
(
moisture
);
delay
(
1000
);
if
(
moisture
>
700
)
{
digitalWrite
(
relayInput
,
HIGH
);
// turn relay on
delay
(
1000
);
}
}
digitalWrite
(
relayInput
,
LOW
);
// turn relay off
// delay(1000);
Servo1
.
write
(
90
);
delay
(
1000
);
}
//==============================================================================
void
loop
()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int
h
=
dht
.
readHumidity
();
// Read temperature as Celsius
float
t
=
dht
.
readTemperature
();
//Read moisture level
int
m
=
analogRead
(
A0
);
digitalWrite
(
relayInput
,
LOW
);
// Check if any reads failed and exit
if
(
isnan
(
h
)
||
isnan
(
t
)
||
isnan
(
m
))
{
Serial
.
println
(
"Failed to read from DHT sensor !"
);
delay
(
500
);
return
;
}
String
Temp
=
"Temperature : "
+
String
(
t
)
+
" °C"
;
String
Humi
=
"Humidity : "
+
String
(
h
)
+
" %"
;
String
mois
=
"Humidity : "
+
String
(
m
)
+
" %"
;
Serial
.
println
(
Temp
);
Serial
.
println
(
Humi
);
Serial
.
println
(
mois
);
sendData
(
t
,
h
,
m
);
//--> Calls the sendData Subroutine
digitalWrite
(
relayInput
,
LOW
);
}
//==============================================================================
// Sending data to Google Sheets
void
sendData
(
float
tem
,
int
hum
,
int
mois
)
{
Serial
.
println
(
"=========="
);
Serial
.
print
(
"connecting to "
);
Serial
.
println
(
host
);
//----------------------------------------Connect to Google host
if
(
!
client
.
connect
(
host
,
httpsPort
))
{
Serial
.
println
(
"connection failed"
);
return
;
}
//----------------------------------------Processing data and sending data
String
string_temperature
=
String
(
tem
);
String
string_humidity
=
String
(
hum
,
DEC
);
String
string_moisture
=
String
(
mois
,
DEC
);
String
url
=
"/macros/s/"
+
GAS_ID
+
"/exec?temperature="
+
string_temperature
+
"&humidity="
+
string_humidity
+
"&moisture="
+
string_moisture
;
Serial
.
print
(
"requesting URL: "
);
Serial
.
println
(
url
);
client
.
print
(
String
(
"GET "
)
+
url
+
" HTTP/1.1
\r\n
"
+
"Host: "
+
host
+
"
\r\n
"
+
"User-Agent: BuildFailureDetectorESP8266
\r\n
"
+
"Connection: close
\r\n\r\n
"
);
Serial
.
println
(
"request sent"
);
//----------------------------------------Checking whether the data was sent successfully or not
while
(
client
.
connected
())
{
String
line
=
client
.
readStringUntil
(
'\n'
);
if
(
line
==
"
\r
"
)
{
Serial
.
println
(
"headers received"
);
break
;
}
}
String
line
=
client
.
readStringUntil
(
'\n'
);
if
(
line
.
startsWith
(
"{
\"
state
\"
:
\"
success
\"
"
))
{
Serial
.
println
(
"esp8266/Arduino CI successfull!"
);
}
else
{
Serial
.
println
(
"esp8266/Arduino CI has failed"
);
}
Serial
.
print
(
"reply was : "
);
Serial
.
println
(
line
);
Serial
.
println
(
"closing connection"
);
Serial
.
println
(
"=========="
);
Serial
.
println
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment