#include <WiFi.h>
#include "DHT.h"
#include <HTTPClient.h>
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
String MACRO = "https://script.google.com/macros/s/";
String GOOGLE_ID = "AKfycbzyG3optJahLkEAoqHgKDlAxc3Me-worKrELED6gJQ";
void setup() {
Serial.begin(9600);
Serial.println("Conectando-se ao Wi-Fi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Conectado!");
dht.begin();
}
void loop() {
if (WiFi.status() == WL_CONNECTED){
float t = dht.readTemperature();
float h = dht.readHumidity();
String link = MACRO + GOOGLE_ID + "/exec?coluna1=" + String(t) + "&coluna2=" + String(h);
Serial.print(t);
Serial.print(" ");
Serial.println(h);
Serial.println(link);
delay(1000);
HTTPClient http;
http.begin(link);
float httpResponseCode = http.GET();
Serial.println(httpResponseCode);
String payload = "...";
if (httpResponseCode > 0){
Serial.print ("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else{
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("ERRO!");
}
}