diff --git a/D4han.ino b/D4han.ino index c2b9ed7..c9f147b 100644 --- a/D4han.ino +++ b/D4han.ino @@ -1,21 +1,13 @@ -/* -******************************************************************************* -* Copyright (c) 2023 by M5Stack -* Equipped with M5Core sample source code -* 配套 M5Core 示例源代码 -* Visit for more information: https://docs.m5stack.com/en/unit/tvoc -* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/tvoc -* -* Describe: TVOC/eCO2. -* Date: 2021/8/26 -******************************************************************************* -Description: The screen will display TVOC and CO2. 屏幕将显示TVOC和CO2。 -Note: SGP30 needs 15 seconds to initialize calibration after power on. -*/ - #include #include "Adafruit_SGP30.h" +#include +#include +#include +#include + +WiFiMulti WiFiMulti; + Adafruit_SGP30 sgp; TFT_eSprite spu = TFT_eSprite(&M5.Lcd); // Sprite object @@ -42,7 +34,18 @@ delay(5000); } // M5.Lcd.println("Initialization..."); + 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() { @@ -152,6 +155,7 @@ // eCO2が1000を超えたら音を鳴らす if (sgp.eCO2 > 1000) { M5.Beep.setBeep(523, 500); M5.Beep.beep(); + sendLineNotify(); } M5.update(); @@ -162,9 +166,31 @@ 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); - -void loop() { + // 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; }