Update 'DHT11toMYSQL.ino'

This commit is contained in:
2022-04-05 12:48:22 +02:00
parent 7d765eadca
commit 5c629da05a

View File

@@ -18,24 +18,18 @@ String PATH_NAME = "/search";
WiFiClient client; WiFiClient client;
void setup() { void setup() {
//Initialize serial and wait for port to open: //Initialize serial and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
dht.begin(); dht.begin();
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: "); Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID); Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network: // Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
} }
// print the SSID of the network you're attached to: // print the SSID of the network you're attached to:
Serial.print("SSID: "); Serial.print("SSID: ");
Serial.println(WiFi.SSID()); Serial.println(WiFi.SSID());
// print your WiFi shield's IP address: // print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP(); IPAddress ip = WiFi.localIP();
Serial.print("IP Address: "); Serial.print("IP Address: ");
@@ -43,7 +37,8 @@ void setup() {
} }
void loop(){ void loop(){
delay(30000); // 30sec measurement interval // 30sec measurement interval
delay(30000);
float h = dht.readHumidity(); float h = dht.readHumidity();
float t = dht.readTemperature(); float t = dht.readTemperature();
@@ -56,13 +51,11 @@ delay(30000); // 30sec measurement interval
} else { } else {
Serial.println("connection failed"); Serial.println("connection failed");
} }
// send HTTP request header // send HTTP request header
client.println("GET "+ PATH_NAME + queryString + " HTTP/1.1"); client.println("GET "+ PATH_NAME + queryString + " HTTP/1.1");
client.println("Host: google.com"); client.println("Host: google.com");
client.println("Connection: close"); client.println("Connection: close");
client.println(); // end HTTP request header client.println(); // end HTTP request header
//send HTTP body //send HTTP body
client.println(queryString); client.println(queryString);
@@ -72,7 +65,6 @@ client.println(); // end HTTP request header
char c = client.read(); char c = client.read();
Serial.print(c); Serial.print(c);
} }
if(!client.connected()) if(!client.connected())
{ {
// if the server's disconnected, stop the client: // if the server's disconnected, stop the client: