#include <WiFi.h>
#include <WiFiMulti.h>
#include <WiFiClient.h>
#include <HTTPClient.h>
WiFiMulti WiFiMulti;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("ics-ap", "jikkenics");
// wait for WiFi connection
Serial.print("Waiting for WiFi to connect...");
while ((WiFiMulti.run() != WL_CONNECTED)) {
Serial.print(".");
delay(50);
}
Serial.println(" connected");
}
void loop(){
//ここでif文を打つ
sendLineNotify();
}
int sendLineNotify() {
HTTPClient http;
if (http.begin("https://notify-api.line.me/api/notify")) {
http.addHeader("Authorization", "Bearer ssJzyHVJE5pELzp0BdX5aieaovE33Md0gcmugu1A6qv");
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // format of postdata
String postdata = "message=換気をしてください";
int httpCode = http.POST(postdata);
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.printf("[HTTP] Unable to connect\n");
}
return 0;
}