Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoT Project Code
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louie.bridges
IoT Project Code
Commits
0db1b7df
Commit
0db1b7df
authored
Jan 05, 2021
by
louie.bridges
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
db8f1fd1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
Iot-Project.ino
Iot-Project.ino
+71
-0
No files found.
Iot-Project.ino
0 → 100644
View file @
0db1b7df
//Internet of Things Project Code
//This code will be used to connect the ESP8266 microcontroller to the internet
//and then gather the humidity and temperature data from the DHT11 sensor
//and display it on the cloud service ThingSpeak
//Libraries
#include <ESP8266WiFi.h>
#include <DHT.h>
//Network access SSID and password
WiFiClient
client
;
const
char
*
ssid
=
"BTHub6-FHZM"
;
const
char
*
password
=
"exQ4EDgfVT7R"
;
//ThingSpeak API key and server address
const
char
*
server
=
"api.thingspeak.com"
;
String
thinkspeakAPIKey
=
"QC30MAFXUWR6V8IH"
;
//Define what pin the DHT11 is connected on the microcontroller
#define DHTPIN 3
DHT
dht11
(
DHTPIN
,
DHT11
);
void
setup
()
{
// put your setup code here, to run once:
//Connecting the ESP8266 to the internet
Serial
.
begin
(
115200
);
dht11
.
begin
();
WiFi
.
begin
(
ssid
,
password
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
delay
(
1000
);
}
Serial
.
println
(
"WiFi connected"
);
}
void
loop
()
{
// put your main code here, to run repeatedly:
// Read humidity and temperature
float
temp
=
dht11
.
readTemperature
();
float
humidity
=
dht11
.
readHumidity
();
if
(
client
.
connect
(
server
,
80
))
{
//Posts humidity and temperature to fields 1 and 2 on thingspeak
String
postData
=
thinkspeakAPIKey
;
postData
+=
"&field1="
;
postData
+=
String
(
temp
);
postData
+=
"&field2="
;
postData
+=
String
(
humidity
);
postData
+=
"
\r\n\r\n
"
;
//Connect to thingspeak and send data via the API key
client
.
print
(
"POST /update HTTP/1.1
\n
"
);
client
.
print
(
"Host: api.thingspeak.com
\n
"
);
client
.
print
(
"Connection: close
\n
"
);
client
.
print
(
"X-THINGSPEAKAPIKEY: "
+
thinkspeakAPIKey
+
"
\n
"
);
client
.
print
(
"Content-Type: application/x-www-form-urlencoded
\n
"
);
client
.
print
(
"Content-Length: "
);
client
.
print
(
postData
.
length
());
client
.
print
(
"
\n\n
"
);
client
.
print
(
postData
);
// Prints temperature and humitity to the serial monitor.
Serial
.
print
(
"Temperature: "
);
Serial
.
print
(
temp
);
Serial
.
print
(
"Humidity: "
);
Serial
.
print
(
humidity
);
}
client
.
stop
();
// Thingspeak needs 15 seconds to update so I have set a delay for 30 seconds.
delay
(
10000
);
}
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