#include "DHTesp.h"
#include <WiFi.h>
#include <HTTPClient.h>
const int DHT_PIN = 15;
DHTesp dhtSensor;
long power = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
randomSeed(analogRead(0));
// WiFi
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
// TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("---");
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify");
http.addHeader("Authorization", "Bearer 1Lx4UDYanFCFShNJQXowBZVCliqXzV9Wbl3OXli5qEq");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData="";
long l =random(100);
Serial.println(l);
power += l;
Serial.println(power);
if(power >500)
{
httpRequestData = "message=電量超額";
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
}
// Free resources
http.end();
// put your main code here, to run repeatedly:
delay(5000); // this speeds up the simulation
}