diff --git a/src/main.cpp b/src/main.cpp index 13bad7a..828609f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,9 @@ interface the file .pio/build/esp32doit-devkit-v1/firmware.bin #include #include #include +#include -const char* host = "esp32ota"; +const char* host = "esp32deeptest"; const char* ssid = "JoNelsDarlings"; const char* password = "Paris2016"; @@ -40,7 +41,8 @@ const char* loginIndex = "" "" "" "
" @@ -84,6 +86,7 @@ const char* serverIndex = ""; +void send_notification(String subject) { + // return; + Serial.println("Sending Notification."); + WiFiClientSecure client; + client.setInsecure(); // NOT RECOMMENDED + const char* host = "deadswitch.kawomi.com"; + const int port = 443; + if (!client.connect(host, port)) { + Serial.println("connection failed"); + return; + } + + String url = "/api/v1?topic=" + subject + "&secs=0&email=none"; + Serial.print("Requesting URL: "); + Serial.println(url); + client.print(String("POST ") + url + " HTTP/1.1\r\n" + "Host: " + host + + "\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + + "Content-Length: 14\r\n\r\n" + "platform=esp32\r\n"); +} + /* * setup function */ void setup(void) { pinMode(led, OUTPUT); + pinMode(4, INPUT); // GPIO4 - Pin 24 Serial.begin(9600); // Connect to WiFi network + Serial.println("Begin wifi"); WiFi.begin(ssid, password); - Serial.println(""); // Wait for connection or reboot if it doesn't connect for too long uint32_t wifiConnAttements = 0; @@ -150,6 +174,17 @@ void setup(void) { Serial.print("IP address: "); Serial.println(WiFi.localIP()); + if (digitalRead(4) == HIGH) { + send_notification("tmp.deepSleepEnduranceTest"); + Serial.println("Going to sleep now"); + esp_sleep_enable_timer_wakeup(60 * 1000000); + + Serial.println("Setup ESP32 to sleep "); + delay(1000); + Serial.flush(); + esp_deep_sleep_start(); + } + /*use mdns for host name resolution*/ if (!MDNS.begin(host)) { // http://esp32ota.local Serial.println("Error setting up MDNS responder!"); @@ -217,6 +252,6 @@ void loop(void) { ledState = not(ledState); // set the LED with the ledState of the variable: - digitalWrite(led, ledState); + // digitalWrite(led, ledState); } } \ No newline at end of file
" - "
ESP32 Login Page
" + "
ESP32 Login Page DEEP SLEEP " + "TEST
" "
" "