Update 'DHT11toMYSQL.ino'

This commit is contained in:
2022-04-04 13:39:02 +02:00
parent ba186c59e1
commit b1c39b89bf
2 changed files with 80 additions and 0 deletions

80
DHT11toMYSQL.ino Normal file
View File

@@ -0,0 +1,80 @@
#include <SPI.h>
#include <WiFiNINA.h>
#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();
}
}

View File