just some reformatting - no code changes

This commit is contained in:
Joe Tretter
2022-07-05 14:18:19 -05:00
parent c372dcd95d
commit 22783a6e58

View File

@@ -1,13 +1,13 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESPmDNS.h>
#include <PubSubClient.h>
#include <SPIFFS.h>
#include <Update.h>
#include <WebServer.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
#include <SPIFFS.h>
#include <ArduinoJson.h>
#include <PubSubClient.h>
const char* host = "esp32gragedoor";
const char* ssid = "JoNelsDarlings";
@@ -75,8 +75,11 @@ const char* loginIndex =
*/
const char* serverIndex =
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
"<script "
"src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></"
"script>"
"<form method='POST' action='#' enctype='multipart/form-data' "
"id='upload_form'>"
"<input type='file' name='update'>"
"<input type='submit' value='Update'>"
"</form>"
@@ -111,7 +114,6 @@ const char* serverIndex =
"});"
"</script>";
void send_notification(String subject) {
// return;
Serial.println("Sending Notification.");
@@ -127,12 +129,9 @@ void send_notification(String subject){
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");
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");
}
void send_mqtt(String value) {
@@ -172,7 +171,6 @@ void reconnect() {
}
}
/*
* setup function
*/
@@ -200,7 +198,8 @@ void setup(void) {
delay(500);
Serial.print(".");
if (wifiConnAttements++ > 120) {
Serial.println("<Wifi not connecting after 120 attmepts (1 min.) - rebooting>");
Serial.println(
"<Wifi not connecting after 120 attmepts (1 min.) - rebooting>");
ESP.restart();
}
}
@@ -252,7 +251,8 @@ void setup(void) {
server.on("/status", HTTP_GET, []() {
server.sendHeader("Connection", "close");
boolean isOpen = digitalRead(buttonPin) == HIGH;
server.send(200, "application/json", "{ \"isOpen\": " + String(isOpen?"true":"false") + " }");
server.send(200, "application/json",
"{ \"isOpen\": " + String(isOpen ? "true" : "false") + " }");
// send_mqtt("statusquery");
});
@@ -267,25 +267,32 @@ void setup(void) {
server.send(200, "text/html", serverIndex);
});
/*handling uploading firmware file */
server.on("/update", HTTP_POST, []() {
server.on(
"/update", HTTP_POST,
[]() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
},
[]() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
if (!Update.begin(
UPDATE_SIZE_UNKNOWN)) { // start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
/* flashing firmware to ESP*/
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
if (Update.write(upload.buf, upload.currentSize) !=
upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
if (Update.end(
true)) { // true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n",
upload.totalSize);
} else {
Update.printError(Serial);
}