Add sending of deadswitch message on every wakeup
This commit is contained in:
43
src/main.cpp
43
src/main.cpp
@@ -18,8 +18,9 @@ interface the file .pio/build/esp32doit-devkit-v1/firmware.bin
|
||||
#include <WebServer.h>
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
|
||||
const char* host = "esp32ota";
|
||||
const char* host = "esp32deeptest";
|
||||
const char* ssid = "JoNelsDarlings";
|
||||
const char* password = "Paris2016";
|
||||
|
||||
@@ -40,7 +41,8 @@ const char* loginIndex =
|
||||
"<table width='20%' bgcolor='A09F9F' align='center'>"
|
||||
"<tr>"
|
||||
"<td colspan=2>"
|
||||
"<center><font size=4><b>ESP32 Login Page</b></font></center>"
|
||||
"<center><font size=4><b>ESP32 Login Page DEEP SLEEP "
|
||||
"TEST</b></font></center>"
|
||||
"<br>"
|
||||
"</td>"
|
||||
"<br>"
|
||||
@@ -84,6 +86,7 @@ const char* serverIndex =
|
||||
"<script "
|
||||
"src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></"
|
||||
"script>"
|
||||
"<h1>DeepSleepTest</h1>"
|
||||
"<form method='POST' action='#' enctype='multipart/form-data' "
|
||||
"id='upload_form'>"
|
||||
"<input type='file' name='update'>"
|
||||
@@ -120,17 +123,38 @@ const char* serverIndex =
|
||||
"});"
|
||||
"</script>";
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user