Implement OTA updating

This commit is contained in:
Junior 2025-03-09 19:25:17 -04:00
parent bf39499cdb
commit b6c04fad6b
2 changed files with 27 additions and 5 deletions

View File

@ -25,5 +25,5 @@ framework = arduino
lib_deps = tzapu/WiFiManager@^0.16.0
upload_speed = 115200
monitor_speed = 115200
upload_port = COM5
monitor_port = COM5
;upload_protocol = espota
;upload_port = 192.168.2.238

View File

@ -2,6 +2,7 @@
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <stdlib.h>
#include <ArduinoOTA.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
@ -16,7 +17,8 @@
// Commands sent to target ID 0 (zero) will be executed by ALL targets
#define TARGET_ID_FIXED 1
// If a 4-position dip switch is present and tied to 4 GPIO pins, set ID_SWITCHED to true and put the pin numbers in the ID_BIT_? settings
// If a 4-position dip switch is present and tied to 4 GPIO pins,
// set ID_SWITCHED to true and put the pin numbers in the ID_BIT_? settings
#define ID_SWITCHED true
#define ID_BIT_0 16
#define ID_BIT_1 14
@ -153,6 +155,26 @@ void setup() {
timer0_write(ESP.getCycleCount() + 1000);
interrupts();
wifiManager.autoConnect("JaJLEDController");
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();
// Show our ID!
Serial.println();
@ -215,7 +237,7 @@ bool processMessage() {
if ( DEBUG ) Serial.println("Got UDP packet!");
// Clear out the global autoColors[] array
memset(autoColors, 0, sizeof(autoColors));
memset((void *)&autoColors, 0, sizeof(autoColors));
// If we get a CMD_SETLEVELS then disable autoMode, set the new static values and ramp to that color
if ( command == CMD_SETLEVELS ) {
@ -466,7 +488,7 @@ void loop() {
}
nextDIPSample = nowMillis + 10000; // Sample the DIP switches every 10 seconds
}
ArduinoOTA.handle();
yield();
}