Compare commits
No commits in common. "bcb5208e4dcf5502746a0c4a9c5ba343ba46c784" and "49a9b45ab9b4b0761a8c2c6ae7bff9af75b10fc7" have entirely different histories.
bcb5208e4d
...
49a9b45ab9
|
@ -13,9 +13,6 @@ platform = espressif32
|
|||
board = esp32doit-devkit-v1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.2.232
|
||||
lib_compat_mode = strict
|
||||
lib_deps =
|
||||
tzapu/WiFiManager@^2.0.17
|
||||
lostincompilation/PrettyOTA@^1.1.2
|
||||
lib_deps = tzapu/WiFiManager@^2.0.17
|
||||
;upload_protocol = espota
|
||||
;upload_port = 192.168.2.233
|
||||
|
|
63
src/main.cpp
63
src/main.cpp
|
@ -2,9 +2,9 @@
|
|||
#include <WiFiManager.h>
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <PrettyOTA.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
#define BOARDFIRMWARE "2.2"
|
||||
#define FIRMWARE "2.0"
|
||||
|
||||
#define BUTTONPIN 23
|
||||
#define DEBOUNCEMS 15
|
||||
|
@ -17,9 +17,6 @@ String statusURL = "http://moon.basement.lan/l/boardstatus.php";
|
|||
unsigned short buttonState = HIGH, lastButtonState = HIGH;
|
||||
unsigned long lastStatusTime = 0;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
PrettyOTA OTAUpdates;
|
||||
|
||||
void sendToggleMessage(bool state) {
|
||||
Serial.println("Action button triggered");
|
||||
char webMsg[255] = "";
|
||||
|
@ -37,37 +34,12 @@ unsigned long sendDeviceStatus() {
|
|||
HTTPClient http;
|
||||
http.begin(client, statusURL.c_str());
|
||||
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);
|
||||
http.end();
|
||||
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() {
|
||||
Serial.begin(115200);
|
||||
pinMode(BUTTONPIN, INPUT_PULLUP);
|
||||
|
@ -75,14 +47,26 @@ void setup() {
|
|||
WiFiManager wifiManager;
|
||||
wifiManager.autoConnect("LEDsActionButton");
|
||||
lastStatusTime = sendDeviceStatus();
|
||||
OTAUpdates.Begin(&server);
|
||||
OTAUpdates.SetHardwareID(SERVICE);
|
||||
OTAUpdates.OverwriteAppVersion(BOARDFIRMWARE);
|
||||
PRETTY_OTA_SET_CURRENT_BUILD_TIME_AND_DATE();
|
||||
OTAUpdates.OnStart(OnOTAStart);
|
||||
OTAUpdates.OnProgress(OnOTAProgress);
|
||||
OTAUpdates.OnEnd(OnOTAEnd);
|
||||
server.begin();
|
||||
ArduinoOTA.onStart([]() {
|
||||
String type;
|
||||
if ( ArduinoOTA.getCommand() == U_FLASH )
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
Serial.println("Start OTA updating " + type);
|
||||
});
|
||||
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;
|
||||
|
@ -111,4 +95,5 @@ void loop() {
|
|||
}
|
||||
}
|
||||
lastButtonState = buttonCheck;
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user