#include #include #include #include RTC_DATA_ATTR int bootCount = 0; // Number of boot const char* ssid = "hogehoge123"; //SSID const char* password = "fugafuga456"; //PASSWORD const char* token = "piyopiyo789"; //LINE TOKEN //Send LINE Norify Function void sendLineNotify(String message) { const char* host = "notify-api.line.me"; WiFiClientSecure client; Serial.println("Try"); //Connect LINE API Serv. if (!client.connect(host, 443)) { Serial.println("Connection failed"); return; } Serial.println("Connected"); //Send request. String query = String("message=") + String(message); String request = String("") + "POST /api/notify HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Authorization: Bearer " + token + "\r\n" + "Content-Length: " + String(query.length()) + "\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n\r\n" + query + "\r\n"; client.print(request); //Wait for the receive complete. while (client.connected()) { String line = client.readStringUntil('\n'); if (line == "\r") { break; } } String line = client.readStringUntil('\n'); Serial.println(line); } //Connect Wi-Fi Function void wifiConnect() { WiFi.disconnect(); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(100); Serial.printf("."); } Serial.println("Wi-Fi connect OK\n"); } //setup Function void setup() { // put your setup code here, to run once: //GPIO27 INPUT pinMode(GPIO_NUM_27, INPUT); // Init Serial Serial.begin(115200); if ( bootCount == 0 ) { delay(1000); } Serial.printf("ESP32 Rain Alarm\n"); // Wi-Fi Connection wifiConnect(); // Number of boot bootCount++; Serial.printf("Number of boot: %d ", bootCount); // Notifies LINE when waking up from Deep Sleep. esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT0) { Serial.printf("WAKEUP EXT0\n"); sendLineNotify(u8"\U001000AA\r\n雨が降ってきました。"); } //GPIO27 returns from deep sleep at LOW esp_sleep_enable_ext0_wakeup(GPIO_NUM_27, LOW); } //loop Function void loop() { // put your main code here, to run repeatedly: // GPIO_NUM_27 is HIGH -> go to Deep Sleep if (digitalRead(GPIO_NUM_27) == HIGH ) { Serial.printf("Go to Deep Sleep\n"); esp_deep_sleep_start(); delay(1000); } }