-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.txt
More file actions
76 lines (62 loc) · 1.7 KB
/
Copy pathcode.txt
File metadata and controls
76 lines (62 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//#include "DHT.h"
#define DHTTYPE DHT11
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#define dht_dpin 0
//DHT dht(dht_dpin, DHTTYPE);
const char* ssid = "Arun_4G";
const char* pass = "arun1234";
//String serverName = "https://forestfirealarm.000webhostapp.com/insert";
WiFiClient client;
void setup(void)
{
// dht.begin();
Serial.begin(115200);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("Humidity and temperature\n\n");
delay(700);
}
void loop() {
// float h = dht.readHumidity();
// float t = dht.readTemperature();
// Serial.print("Current humidity = ");
// Serial.print(h);
// Serial.print("% ");
// Serial.print("temperature = ");
// Serial.print(t);
// Serial.println("C ");
float t=33;
float h=20;
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
String serverPath = "http://forestfirealarm.000webhostapp.com/insert.php?temperature="+String(t)+"&humidity="+String(h);
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
delay(5000);
}