From b1c39b89bfcac209a0235e07cf30fe369adf25c4 Mon Sep 17 00:00:00 2001 From: Fabian Daume Date: Mon, 4 Apr 2022 13:39:02 +0200 Subject: [PATCH] Update 'DHT11toMYSQL.ino' --- DHT11toMYSQL.ino | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 0 2 files changed, 80 insertions(+) create mode 100644 DHT11toMYSQL.ino delete mode 100644 README.md diff --git a/DHT11toMYSQL.ino b/DHT11toMYSQL.ino new file mode 100644 index 0000000..8673b1c --- /dev/null +++ b/DHT11toMYSQL.ino @@ -0,0 +1,80 @@ +#include +#include +#include "DHT.h" + +#define DHTPIN 7 +#define DHTTYPE DHT11 +DHT dht(DHTPIN, DHTTYPE); + +char ssid[] = ""; // your network SSID (name) +char pass[] = ""; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0 // your network key index number (needed only for WEP) +int status = WL_IDLE_STATUS; + +IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +//char server = "www.google.com"; // name address for Google (using DNS) +String PATH_NAME = "/search"; + +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + + dht.begin(); + + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop(){ +delay(30000); // 30sec measurement interval + + float h = dht.readHumidity(); + float t = dht.readTemperature(); + + String queryString = String("?humidity=") + String(h) + String("&temperature=") + String(t); + + if (client.connect(server, 80)) { + Serial.println("MAKE A HTTP REQUEST"); + Serial.println(queryString); +} else { + Serial.println("connection failed"); +} + +// send HTTP request header +client.println("GET "+ PATH_NAME + queryString + " HTTP/1.1"); +client.println("Host: google.com"); +client.println("Connection: close"); +client.println(); // end HTTP request header + +//send HTTP body + client.println(queryString); + + while(client.available()) +{ + // read an incoming byte from the server and print them to serial monitor: + char c = client.read(); + Serial.print(c); +} + +if(!client.connected()) +{ + // if the server's disconnected, stop the client: + Serial.println("disconnected"); + client.stop(); +} +} \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index e69de29..0000000