#include “DHT.h”
#include <TridentTD_LineNotify.h>
#define SSID “admin” //Name WIFI
#define PASSWORD “xxxxx” //Password WiFi
#define LINE_TOKEN “IZdRDpY04bt3KUZnrWYahtDc1hyHxxxxxxxxxx” // Token Line Notify
#define DHTPIN D1
#define DHTTYPE DHT11
WiFiClientSecure client;
DHT dht(DHTPIN, DHTTYPE);
int state = 0;
const char* host = “script.google.com”;
const int httpsPort = 443;
void setup() {
Serial.begin(115200); Serial.println();
Serial.println(LINE.getVersion());
WiFi.begin(SSID, PASSWORD);
Serial.printf(“WiFi connecting to %s\n”, SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“.”);
const char* host = “script.google.com”;
const int httpsPort = 443;
delay(400);
}
Serial.printf(“\nWiFi connected\nIP : “);
Serial.println(WiFi.localIP());
LINE.setToken(LINE_TOKEN);
}
void loop() {
const char* host = “script.google.com”;
const int httpsPort = 443;
int Water = analogRead(A0);
Serial.println(Water);
String val = “”;
float h = dht.readHumidity(); // ความชื้น
float t = dht.readTemperature(); // อุณหภูมิ
val = val + h;
val = val + “% “;
val = val + t;
val = val + “C”;
Serial.println(val);
LINE.notify(val);
if (state == 0) {
if (Water < 900 ) {
LINE.notify(“เตือน!! น้ำขึ้นสูงถึงระดับเซ็นเซอร์แล้ว”);
state = 1;
}
}
else if (state == 1) {
delay(6000);
state = 0;
}
// Serial.println(host);
// //—————————————-Connect to Google host
// client.connect(host, httpsPort);
// float string_temp = dht.readTemperature();
// float string_humi = dht.readHumidity();
// String url = “/macros/s/” + GAS_ID + “/exec?temperature=” + string_temp + “&humidity=”+string_humi; // 2 variables
// Serial.print(“requesting URL: “);
// Serial.println(url);
// client.print(String(“GET “) + url + ” HTTP/1.1\r\n” +
// “Host: ” + host + “\r\n” +
// “User-Agent: BuildFailureDetectorESP8266\r\n” +
// “Connection: close\r\n\r\n”);
// Serial.println(“request sent”);
// delay(1000); }
Leave a Reply