diff --git a/otaflash.sh b/otaflash.sh index 54f51fd..b7fd481 100644 --- a/otaflash.sh +++ b/otaflash.sh @@ -14,5 +14,5 @@ do printf "%c" "." done printf "\n%s\n" "Device is online" -pio run -t upload --upload-port $1 +pio run -t upload -e d1_mini-ota --upload-port $1 diff --git a/platformio.ini b/platformio.ini index 4cf4ef1..b92e5ad 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,6 +8,7 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html + [env:lolin32] platform = espressif32 board = lolin32 @@ -15,5 +16,47 @@ framework = arduino monitor_speed = 115200 upload_speed = 921600 + +build_flags = + -D ESP32 + +[env:lolin32-ota] +platform = espressif32 +board = lolin32 +framework = arduino +monitor_speed = 115200 +upload_speed = 921600 +upload_protocol = espota + +build_flags = + -D ESP32 + +upload_flags = + --auth=MCH2022OTA + + + +[env:d1_mini] +platform = espressif8266 +board = d1_mini +framework = arduino +monitor_speed = 115200 +upload_speed = 921600 + +build_flags = + -D ESP8266 + +[env:d1_mini-ota] +platform = espressif8266 +board = d1_mini +framework = arduino +monitor_speed = 115200 +upload_speed = 921600 +upload_protocol = espota + + +build_flags = + -D ESP8266 + upload_flags = --auth=MCH2022OTA \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ce27c5a..54708e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,13 +19,16 @@ void setup() { void loop() { if (loopOTA()) { +#ifndef OTA_CONTINUOUS return; //just wait for ota +#endif } static unsigned long last_print=0; if (millis()-last_print>1000) { last_print=millis(); - Serial.println("Loop"); + Serial.print("Loop "); + Serial.println(last_print); } } diff --git a/src/simpleota.cpp b/src/simpleota.cpp index a71e93a..4a62583 100644 --- a/src/simpleota.cpp +++ b/src/simpleota.cpp @@ -36,8 +36,7 @@ bool initOTA() { ArduinoOTA.setPassword((const char *)OTA_PASSWORD); - ArduinoOTA - .onStart([]() { + ArduinoOTA.onStart([]() { otaMode = UPDATING; String type; if (ArduinoOTA.getCommand() == U_FLASH) @@ -47,16 +46,16 @@ bool initOTA() { // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() Serial.println("Start updating " + type); - }) - .onEnd([]() { + }); + ArduinoOTA.onEnd([]() { Serial.println("\nEnd"); - }) - .onProgress([](unsigned int progress, unsigned int total) { + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { int prog = (progress / (total / 100)); Serial.printf("Progress: %u%%\r", prog); - }) - .onError([](ota_error_t error) { + }); + ArduinoOTA.onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); @@ -77,6 +76,8 @@ bool loopOTA() { if (otaMode != NONE) { ArduinoOTA.handle(); + +#ifndef OTA_CONTINUOUS if(otaMode == WAITING) { static long mil = millis(); static boolean huehott = false; @@ -92,6 +93,7 @@ bool loopOTA() { } } } +#endif return true; } else { diff --git a/src/simpleota.h b/src/simpleota.h index f2ee904..b8892d1 100644 --- a/src/simpleota.h +++ b/src/simpleota.h @@ -2,14 +2,24 @@ #define simpleota_h #include +#ifdef ESP32 #include #include +#endif +#ifdef ESP8266 +#include +#include +#include +#include +#endif -#define OTA_WIFI_SSID "Chaos-West temp alternative" -#define OTA_WIFI_PASSWORD "" -#define OTA_WAIT_TIMEOUT 20 // in 0.1s increments -> 10s -#define OTA_PASSWORD "MCH2022OTA" //password needed for ota flashing +#define OTA_WIFI_SSID "ssid" +#define OTA_WIFI_PASSWORD "password" +#define OTA_WAIT_TIMEOUT 100 +#define OTA_PASSWORD "MCH2022OTA" + +#define OTA_CONTINUOUS void checkOTA(); bool initOTA();