Compare commits

..

No commits in common. "bcb5208e4dcf5502746a0c4a9c5ba343ba46c784" and "49a9b45ab9b4b0761a8c2c6ae7bff9af75b10fc7" have entirely different histories.

2 changed files with 27 additions and 45 deletions

View File

@ -13,9 +13,6 @@ platform = espressif32
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
upload_protocol = espota lib_deps = tzapu/WiFiManager@^2.0.17
upload_port = 192.168.2.232 ;upload_protocol = espota
lib_compat_mode = strict ;upload_port = 192.168.2.233
lib_deps =
tzapu/WiFiManager@^2.0.17
lostincompilation/PrettyOTA@^1.1.2

View File

@ -2,9 +2,9 @@
#include <WiFiManager.h> #include <WiFiManager.h>
#include <WiFi.h> #include <WiFi.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <PrettyOTA.h> #include <ArduinoOTA.h>
#define BOARDFIRMWARE "2.2" #define FIRMWARE "2.0"
#define BUTTONPIN 23 #define BUTTONPIN 23
#define DEBOUNCEMS 15 #define DEBOUNCEMS 15
@ -17,9 +17,6 @@ String statusURL = "http://moon.basement.lan/l/boardstatus.php";
unsigned short buttonState = HIGH, lastButtonState = HIGH; unsigned short buttonState = HIGH, lastButtonState = HIGH;
unsigned long lastStatusTime = 0; unsigned long lastStatusTime = 0;
AsyncWebServer server(80);
PrettyOTA OTAUpdates;
void sendToggleMessage(bool state) { void sendToggleMessage(bool state) {
Serial.println("Action button triggered"); Serial.println("Action button triggered");
char webMsg[255] = ""; char webMsg[255] = "";
@ -37,37 +34,12 @@ unsigned long sendDeviceStatus() {
HTTPClient http; HTTPClient http;
http.begin(client, statusURL.c_str()); http.begin(client, statusURL.c_str());
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpData = "mac=" + WiFi.macAddress() + "&board=" + BOARD + "&firmware=" + BOARDFIRMWARE + "&service=" + SERVICE; String httpData = "mac=" + WiFi.macAddress() + "&board=" + BOARD + "&firmware=" + FIRMWARE + "&service=" + SERVICE;
int httpResponseCode = http.POST(httpData); int httpResponseCode = http.POST(httpData);
http.end(); http.end();
return millis(); return millis();
} }
// Gets called when update starts
// updateMode can be FILESYSTEM or FIRMWARE
void OnOTAStart(NSPrettyOTA::UPDATE_MODE updateMode) {
Serial.println("OTA update started");
if(updateMode == NSPrettyOTA::UPDATE_MODE::FIRMWARE)
Serial.println("Mode: Firmware");
else if(updateMode == NSPrettyOTA::UPDATE_MODE::FILESYSTEM)
Serial.println("Mode: Filesystem");
}
// Gets called while update is running
// currentSize: Number of bytes already processed
// totalSize: Total size of new firmware in bytes
void OnOTAProgress(uint32_t currentSize, uint32_t totalSize) {
Serial.printf("OTA Progress Current: %u bytes, Total: %u bytes\n", currentSize, totalSize);
}
// Gets called when update finishes
void OnOTAEnd(bool successful) {
if (successful)
Serial.println("OTA update finished successfully");
else
Serial.println("OTA update failed");
}
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
pinMode(BUTTONPIN, INPUT_PULLUP); pinMode(BUTTONPIN, INPUT_PULLUP);
@ -75,14 +47,26 @@ void setup() {
WiFiManager wifiManager; WiFiManager wifiManager;
wifiManager.autoConnect("LEDsActionButton"); wifiManager.autoConnect("LEDsActionButton");
lastStatusTime = sendDeviceStatus(); lastStatusTime = sendDeviceStatus();
OTAUpdates.Begin(&server); ArduinoOTA.onStart([]() {
OTAUpdates.SetHardwareID(SERVICE); String type;
OTAUpdates.OverwriteAppVersion(BOARDFIRMWARE); if ( ArduinoOTA.getCommand() == U_FLASH )
PRETTY_OTA_SET_CURRENT_BUILD_TIME_AND_DATE(); type = "sketch";
OTAUpdates.OnStart(OnOTAStart); else // U_SPIFFS
OTAUpdates.OnProgress(OnOTAProgress); type = "filesystem";
OTAUpdates.OnEnd(OnOTAEnd); Serial.println("Start OTA updating " + type);
server.begin(); });
ArduinoOTA.onEnd([]() {
Serial.println("\nOTA Update Completed");
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("OTA Update Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
} }
unsigned long lastDebounceTime = 0; unsigned long lastDebounceTime = 0;
@ -111,4 +95,5 @@ void loop() {
} }
} }
lastButtonState = buttonCheck; lastButtonState = buttonCheck;
ArduinoOTA.handle();
} }