diff --git a/platformio.ini b/platformio.ini index c7c89b4..95c530f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -48,3 +48,9 @@ monitor_filters = lib_deps = fastled/FastLED@^3.7.0 knolleary/PubSubClient@^2.8 + + +[env:esp32c3_supermini_network] +extends = env:esp32c3_supermini +upload_protocol = espota +upload_port = 10.206.0.101 \ No newline at end of file diff --git a/src/Hanglamp.cpp b/src/Hanglamp.cpp index e4b1330..5e24faa 100644 --- a/src/Hanglamp.cpp +++ b/src/Hanglamp.cpp @@ -179,6 +179,10 @@ bool Hanglamp::isOn(){ void Hanglamp::turnOn(){ if(!this->on){ + + this->colorIndex = 1; + setColor(colorTable[1]); + FastLED.setBrightness(this->brightness); FastLED.show(); this->setOn(true); diff --git a/src/MQTT.cpp b/src/MQTT.cpp index 6e177bc..7808a1b 100644 --- a/src/MQTT.cpp +++ b/src/MQTT.cpp @@ -10,7 +10,7 @@ PubSubClient client(espClient); std::vector * channels = new std::vector(); -char mqtt_server[40] = "manus"; +char mqtt_server[40] = "10.206.0.175"; char mqtt_port[6] = "1883"; diff --git a/src/OTA.cpp b/src/OTA.cpp new file mode 100644 index 0000000..c1f87ae --- /dev/null +++ b/src/OTA.cpp @@ -0,0 +1,44 @@ +#include "OTA.h" + +#include + +void OTA_setup(){ + ArduinoOTA + .onStart([]() { + String type; + if (ArduinoOTA.getCommand() == U_FLASH) { + type = "sketch"; + } else { // U_SPIFFS + type = "filesystem"; + } + + // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() + Serial.println("Start updating " + type); + }) + .onEnd([]() { + Serial.println("\nEnd"); + }) + .onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }) + .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"); + } 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(); +} + +void OTA_loop(){ + ArduinoOTA.handle(); +} \ No newline at end of file diff --git a/src/OTA.h b/src/OTA.h new file mode 100644 index 0000000..a6a1972 --- /dev/null +++ b/src/OTA.h @@ -0,0 +1,2 @@ +void OTA_loop(); +void OTA_setup(); \ No newline at end of file diff --git a/src/config.h b/src/config.h index 70982f1..d568ab3 100644 --- a/src/config.h +++ b/src/config.h @@ -2,7 +2,7 @@ #define INCLUDE_LED #define ENABLE_MQTT -// #define ENABLE_OTA +#define ENABLE_OTA #define ENABLE_WIFI // #define ENABLE_FS // #define ENABLE_PINFINDER diff --git a/src/main.cpp b/src/main.cpp index 849a4bc..0a3a983 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,11 @@ #include "Wifi.h" #endif + +#ifdef ENABLE_OTA +#include "OTA.h" +#endif + #ifdef ENABLE_MQTT #include "MQTT.h" #endif