diff --git a/D4han.ino b/D4han.ino index c9f147b..45d4095 100644 --- a/D4han.ino +++ b/D4han.ino @@ -48,6 +48,35 @@ } +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=二酸化炭素濃度が1000を超えました。換気をしてください。"; + 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; +} + void loop() { static int i = 3; while (i > 0) { @@ -163,34 +192,5 @@ if (M5.Axp.GetBtnPress() == 2) { M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); // Power Off } - delay(1000); -} - -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; + delay(500); }