diff --git a/arduino_bootstrapper b/arduino_bootstrapper index 43d01f42..9529938e 160000 --- a/arduino_bootstrapper +++ b/arduino_bootstrapper @@ -1 +1 @@ -Subproject commit 43d01f423ed19dd8cb5c17e9a4d3bb39ebae5cca +Subproject commit 9529938e7485f8f0948f404cdcc9c2968bcc1f20 diff --git a/include/Globals.h b/include/Globals.h index 07bf21ae..a96a68ad 100644 --- a/include/Globals.h +++ b/include/Globals.h @@ -32,7 +32,7 @@ #if defined(ARDUINO_ARCH_ESP32) #define LDR_DIVIDER 4096 #endif -#define SERIAL_SIZE_RX 1500 +#define SERIAL_SIZE_RX 2048 #define CONFIG_NUM_PARAMS 20 #define CONFIG_PREFIX_LENGTH 6 // This value must meet the one in Firefly Luciferin @@ -105,6 +105,8 @@ extern unsigned long previousMillisLDR; extern unsigned long lastUdpMsgReceived; extern unsigned long disconnectionTime; extern bool disconnectionResetEnable; +extern bool builtInLedStatus; +extern bool resetLedStatus; extern unsigned long secondsBeforeReset; extern unsigned long currentMillisCheckConn; diff --git a/include/LedManager.h b/include/LedManager.h index b060b0a9..35c00c43 100644 --- a/include/LedManager.h +++ b/include/LedManager.h @@ -113,6 +113,8 @@ class LedManager { static void setColor(uint8_t inR, uint8_t inG, uint8_t inB); + static void setColorNoSolid(uint8_t inR, uint8_t inG, uint8_t inB); + static void setColorLoop(uint8_t inR, uint8_t inG, uint8_t inB); static void setNumLed(int numLedFromLuciferin); @@ -127,6 +129,8 @@ class LedManager { void flushSerial(); + static void manageBuiltInLed(uint8_t r, uint8_t g, uint8_t b); + }; #endif //GLOW_WORM_LUCIFERIN_LEDMANAGER_H diff --git a/include/Version.h b/include/Version.h index b9f76ff2..793fc296 100644 --- a/include/Version.h +++ b/include/Version.h @@ -1,9 +1,9 @@ // AUTO GENERATED FILE, DO NOT EDIT #ifndef VERSION - #define VERSION "5.15.4" + #define VERSION "5.16.33" #endif #ifndef BUILD_TIMESTAMP - #define BUILD_TIMESTAMP "2024-08-02 13:34:16.324757" + #define BUILD_TIMESTAMP "2024-09-19 13:54:35.159175" #endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index a29696fe..59c60b8c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,8 +24,8 @@ extra_scripts = pre:platformio_version_increment/version_increment_pre.py post:platformio_version_increment/version_increment_post.py lib_deps = - makuna/NeoPixelBus@2.8.0 - bblanchon/ArduinoJson@7.1.0 + makuna/NeoPixelBus@2.8.2 + bblanchon/ArduinoJson@7.2.0 knolleary/PubSubClient@2.8.0 ;https://github.com/Makuna/NeoPixelBus.git#master lib_extra_dirs = arduino_bootstrapper @@ -91,8 +91,8 @@ board_build.filesystem = ${common_env_data.filesystem} monitor_filters = ${common_env_data.monitor_filters_esp8266} board_build.f_cpu = ${common_env_data.f_cpu_esp8266} ;build_type = debug -monitor_port = COM4 -upload_port = COM4 +monitor_port = COM3 +upload_port = COM3 ;upload_protocol = espota ;upload_port = 192.168.1.52 ;upload_flags = diff --git a/src/Globals.cpp b/src/Globals.cpp index 0265b03a..3bb20ae8 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -100,6 +100,8 @@ unsigned long previousMillisLDR = 0; unsigned long lastUdpMsgReceived; unsigned long disconnectionTime; bool disconnectionResetEnable; +bool builtInLedStatus; +bool resetLedStatus; // after three minutes, start device reset unsigned long secondsBeforeReset = 180000; bool apFileRead; diff --git a/src/GlowWormLuciferin.cpp b/src/GlowWormLuciferin.cpp index 57ad4427..7428824c 100644 --- a/src/GlowWormLuciferin.cpp +++ b/src/GlowWormLuciferin.cpp @@ -21,10 +21,12 @@ #include //this needs to be first, or it all crashes and burns... #include "GlowWormLuciferin.h" + /** * Setup function */ void setup() { + LedManager::manageBuiltInLed(0, 0, 255); firmwareVersion = VERSION; // if fastDisconnectionManagement we need to execute the disconnection callback immediately fastDisconnectionManagement = true; @@ -38,10 +40,7 @@ void setup() { // Increase the RX Buffer size allows to send bigger messages via Serial in one chunk, increase performance. Serial.setRxBufferSize(SERIAL_SIZE_RX); #endif - Serial.begin(baudRateToUse); -//#if defined(ESP8266) -// Serial.setTimeout(10); -//#endif + Serial.begin(baudRateToUse); Serial.setTimeout(10); Serial.setDebugOutput(false); // switch off kernel messages when using USBCDC @@ -82,14 +81,17 @@ void setup() { if (!ap.isEmpty() && ap != ERROR && ap.toInt() == 10) { setApState(11); LedManager::setColorLoop(0, 255, 0); + LedManager::manageBuiltInLed(0, 255, 0); } else if (!ap.isEmpty() && ap != ERROR && ap.toInt() == 11) { setApState(12); LedManager::setColorLoop(0, 0, 255); + LedManager::manageBuiltInLed(0, 0, 255); } else if (!ap.isEmpty() && ap != ERROR && ap.toInt() == 12) { bootstrapManager.littleFsInit(); BootstrapManager::isWifiConfigured(); setApState(13); LedManager::setColorLoop(255, 75, 0); + LedManager::manageBuiltInLed(255, 75, 0); bootstrapManager.launchWebServerCustom(false, manageApRoot); } else if (!ap.isEmpty() && ap != ERROR && ap.toInt() == 13) { setApState(0); @@ -168,7 +170,6 @@ void setup() { if (!as.isEmpty() && r != ERROR && as.toInt() != -1) { autoSave = bootstrapManager.readValueFromFile(AUTO_SAVE_FILENAME, F("autosave")).toInt(); } - pinMode(relayPin, OUTPUT); digitalWrite(relayPin, LOW); @@ -198,6 +199,7 @@ void setup() { } } #endif + LedManager::manageBuiltInLed(0, 0, 0); } /** @@ -280,6 +282,7 @@ void mainLoop() { #endif if (!ledManager.led_state) ledManager.led_state = true; int i = 0; + yield(); int prefixLength = Serial.readBytes((byte *) pre, CONFIG_PREFIX_LENGTH); bool prefixOk = false; if (prefixLength == CONFIG_PREFIX_LENGTH) { @@ -289,6 +292,7 @@ void mainLoop() { } } if (prefixOk) { + yield(); int configLen = Serial.readBytes((byte *) config, CONFIG_NUM_PARAMS); if (configLen == CONFIG_NUM_PARAMS) { hi = config[i++]; @@ -438,6 +442,7 @@ void mainLoop() { rlenChunk = LED_BUFF; } // Serial buffer is read with a single block using Serial.readBytes() + yield(); int rlen = Serial.readBytes((byte *) ledBuffer, rlenChunk); if (rlenChunk == rlen) { i = 0; @@ -631,7 +636,15 @@ void loop() { } } } - + if ((builtInLedStatus || resetLedStatus) && wifiReconnectAttemp == 0 && mqttReconnectAttemp == 0) { + builtInLedStatus = false; + resetLedStatus = false; + LedManager::setColorNoSolid(0, 0, 0); + disconnectionTime = currentMillisMainLoop; +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + LedManager::manageBuiltInLed(0, 0, 0); +#endif + } } diff --git a/src/LedManager.cpp b/src/LedManager.cpp index 89f4314d..3300eee0 100644 --- a/src/LedManager.cpp +++ b/src/LedManager.cpp @@ -754,6 +754,16 @@ void LedManager::setColor(uint8_t inR, uint8_t inG, uint8_t inB) { if (inR == 0 && inG == 0 && inB == 0) { effect = Effect::solid; } + setColorNoSolid(inR, inG, inB); +} + +/** + * Set led strip color + * @param inR red color + * @param inG green color + * @param inB blu color + */ +void LedManager::setColorNoSolid(uint8_t inR, uint8_t inG, uint8_t inB) { if (effect != Effect::GlowWorm && effect != Effect::GlowWormWifi) { for (int i = 0; i < ledManager.dynamicLedNum; i++) { ledManager.setPixelColor(i, inR, inG, inB); @@ -814,3 +824,15 @@ void LedManager::setWhiteTemp(int wt) { BootstrapManager::writeToLittleFS(whiteTempDoc, WHITE_TEMP_FILENAME); delay(20); } + +/** + * Manage built in LED in GRB color order + * @param r red + * @param g green + * @param b blu + */ +void LedManager::manageBuiltInLed(uint8_t r, uint8_t g, uint8_t b) { +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + neopixelWrite(LED_BUILTIN, r, g, b); +#endif +} \ No newline at end of file diff --git a/src/NetManager.cpp b/src/NetManager.cpp index 26f7b1f0..f9149867 100644 --- a/src/NetManager.cpp +++ b/src/NetManager.cpp @@ -159,6 +159,10 @@ void NetManager::manageDisconnections() { disconnectionTime = millis(); disconnectionResetEnable = true; } + if (disconnectionResetEnable && !builtInLedStatus) { + builtInLedStatus = true; + LedManager::manageBuiltInLed(0, 125, 255); + } if (millis() - disconnectionTime > (secondsBeforeReset * 2)) { disconnectionTime = millis(); ledManager.stateOn = true; @@ -169,8 +173,10 @@ void NetManager::manageDisconnections() { asDoc[AP_PARAM] = 0; BootstrapManager::writeToLittleFS(asDoc, AP_FILENAME); } + LedManager::manageBuiltInLed(0, 0, 0); LedManager::setColor(0, 0, 0); } else if ((millis() - disconnectionTime > secondsBeforeReset) && disconnectionResetEnable) { + resetLedStatus = true; disconnectionResetEnable = false; ledManager.stateOn = true; effect = Effect::solid; @@ -180,6 +186,7 @@ void NetManager::manageDisconnections() { asDoc[AP_PARAM] = 10; BootstrapManager::writeToLittleFS(asDoc, AP_FILENAME); } + LedManager::manageBuiltInLed(255, 0, 0); LedManager::setColorLoop(255, 0, 0); } } @@ -712,12 +719,12 @@ bool NetManager::processFirmwareConfigWithReboot() { */ bool NetManager::processFirmwareConfig() { boolean espRestart = false; - if (bootstrapManager.jsonDoc.containsKey("MAC")) { + if (bootstrapManager.jsonDoc["MAC"].is()) { String macToUpdate = bootstrapManager.jsonDoc["MAC"]; Serial.println(macToUpdate); if (macToUpdate == MAC) { // GPIO - if (bootstrapManager.jsonDoc.containsKey(GPIO_PARAM)) { + if (bootstrapManager.jsonDoc[GPIO_PARAM].is()) { int gpioFromConfig = (int) bootstrapManager.jsonDoc[GPIO_PARAM]; if (gpioFromConfig != 0 && gpioInUse != gpioFromConfig) { Globals::setGpio(gpioFromConfig); @@ -725,7 +732,7 @@ bool NetManager::processFirmwareConfig() { } } // GPIO CLOCK - if (bootstrapManager.jsonDoc.containsKey(GPIO_CLOCK_PARAM)) { + if (bootstrapManager.jsonDoc[GPIO_CLOCK_PARAM].is()) { int gpioClockFromConfig = (int) bootstrapManager.jsonDoc[GPIO_CLOCK_PARAM]; if (gpioClockFromConfig != 0 && gpioClockInUse != gpioClockFromConfig) { Globals::setGpioClock(gpioClockFromConfig); @@ -733,7 +740,7 @@ bool NetManager::processFirmwareConfig() { } } // COLOR_MODE - if (bootstrapManager.jsonDoc.containsKey(ledManager.COLOR_MODE_PARAM)) { + if (bootstrapManager.jsonDoc[ledManager.COLOR_MODE_PARAM].is()) { int colorModeParam = (int) bootstrapManager.jsonDoc[ledManager.COLOR_MODE_PARAM]; if (colorMode != colorModeParam) { colorMode = colorModeParam; @@ -742,7 +749,7 @@ bool NetManager::processFirmwareConfig() { } } // COLOR_ORDER - if (bootstrapManager.jsonDoc.containsKey(ledManager.COLOR_ORDER_PARAM)) { + if (bootstrapManager.jsonDoc[ledManager.COLOR_ORDER_PARAM].is()) { int colorOrderParam = (int) bootstrapManager.jsonDoc[ledManager.COLOR_ORDER_PARAM]; if (colorOrder != colorOrderParam) { colorOrder = colorOrderParam; @@ -751,7 +758,7 @@ bool NetManager::processFirmwareConfig() { } } // LDR_PIN_PARAM - if (bootstrapManager.jsonDoc.containsKey(ledManager.LDR_PIN_PARAM)) { + if (bootstrapManager.jsonDoc[ledManager.LDR_PIN_PARAM].is()) { int ldrPinParam = (int) bootstrapManager.jsonDoc[ledManager.LDR_PIN_PARAM]; if (ldrPin != ldrPinParam) { ldrPin = ldrPinParam; @@ -760,7 +767,7 @@ bool NetManager::processFirmwareConfig() { } } // RELAY_PIN_PARAM - if (bootstrapManager.jsonDoc.containsKey(ledManager.RELAY_PIN_PARAM)) { + if (bootstrapManager.jsonDoc[ledManager.RELAY_PIN_PARAM].is()) { int relayPinParam = (int) bootstrapManager.jsonDoc[ledManager.RELAY_PIN_PARAM]; if (relayPin != relayPinParam) { relayPin = relayPinParam; @@ -769,7 +776,7 @@ bool NetManager::processFirmwareConfig() { } } // SB_PIN_PARAM - if (bootstrapManager.jsonDoc.containsKey(ledManager.SB_PIN_PARAM)) { + if (bootstrapManager.jsonDoc[ledManager.SB_PIN_PARAM].is()) { int sbrPinParam = (int) bootstrapManager.jsonDoc[ledManager.SB_PIN_PARAM]; if (sbPin != sbrPinParam) { sbPin = sbrPinParam; @@ -800,7 +807,7 @@ bool NetManager::processFirmwareConfig() { * @return true if message is correctly processed */ bool NetManager::processUnSubscribeStream() { - if (bootstrapManager.jsonDoc.containsKey("instance")) { + if (bootstrapManager.jsonDoc["instance"].is()) { String instance = bootstrapManager.jsonDoc["instance"]; String manager = bootstrapManager.jsonDoc["manager"]; if (manager.equals(deviceName)) { @@ -822,10 +829,10 @@ bool NetManager::processUnSubscribeStream() { */ bool NetManager::processJson() { ledManager.lastLedUpdate = millis(); - boolean skipMacCheck = ((bootstrapManager.jsonDoc.containsKey("MAC") && bootstrapManager.jsonDoc["MAC"] == MAC) - || bootstrapManager.jsonDoc.containsKey("allInstances")); - if (!bootstrapManager.jsonDoc.containsKey("MAC") || skipMacCheck) { - if (bootstrapManager.jsonDoc.containsKey("state")) { + boolean skipMacCheck = ((bootstrapManager.jsonDoc["MAC"].is() && bootstrapManager.jsonDoc["MAC"] == MAC) + || bootstrapManager.jsonDoc["allInstances"].is()); + if (!bootstrapManager.jsonDoc["MAC"].is() || skipMacCheck) { + if (bootstrapManager.jsonDoc["state"].is()) { String state = bootstrapManager.jsonDoc["state"]; if (state == ON_CMD) { Globals::turnOnRelay(); @@ -834,12 +841,12 @@ bool NetManager::processJson() { ledManager.stateOn = false; } } - if (bootstrapManager.jsonDoc.containsKey("color")) { + if (bootstrapManager.jsonDoc["color"].is()) { ledManager.red = bootstrapManager.jsonDoc["color"]["r"]; ledManager.green = bootstrapManager.jsonDoc["color"]["g"]; ledManager.blue = bootstrapManager.jsonDoc["color"]["b"]; } - if (bootstrapManager.jsonDoc.containsKey("brightness")) { + if (bootstrapManager.jsonDoc["brightness"].is()) { brightness = bootstrapManager.jsonDoc["brightness"]; } if (autoSave && (ledManager.red != rStored || ledManager.green != gStored || ledManager.blue != bStored || @@ -847,17 +854,17 @@ bool NetManager::processJson() { Globals::saveColorBrightnessInfo(ledManager.red, ledManager.green, ledManager.blue, brightness); } if (skipMacCheck) { - if (bootstrapManager.jsonDoc.containsKey("whitetemp")) { + if (bootstrapManager.jsonDoc["whitetemp"].is()) { uint8_t wt = bootstrapManager.jsonDoc["whitetemp"]; if (wt != 0 && whiteTempInUse != wt) { LedManager::setWhiteTemp(wt); } } } - if (bootstrapManager.jsonDoc.containsKey("ffeffect")) { + if (bootstrapManager.jsonDoc["ffeffect"].is()) { ffeffect = bootstrapManager.jsonDoc["ffeffect"].as(); } - if (bootstrapManager.jsonDoc.containsKey("effect")) { + if (bootstrapManager.jsonDoc["effect"].is()) { boolean effectIsDifferent = (effect != Effect::GlowWorm && effect != Effect::GlowWormWifi); JsonVariant requestedEffect = bootstrapManager.jsonDoc["effect"]; if (requestedEffect == "Bpm") effect = Effect::bpm; @@ -1007,7 +1014,7 @@ void NetManager::sendStatus() { * @return true if message is correctly processed */ bool NetManager::processMqttUpdate() { - if (bootstrapManager.jsonDoc.containsKey(F("update"))) { + if (bootstrapManager.jsonDoc[F("update")].is()) { return processUpdate(); } return true; @@ -1100,7 +1107,7 @@ bool NetManager::processGlowWormLuciferinRebootCmnd() { * @return true if message is correctly processed */ bool NetManager::processLDR() { - if (bootstrapManager.jsonDoc.containsKey(F("ldrEnabled"))) { + if (bootstrapManager.jsonDoc[F("ldrEnabled")].is()) { stopUDP(); String ldrEnabledMqtt = bootstrapManager.jsonDoc[F("ldrEnabled")]; String ldrTurnOffMqtt = bootstrapManager.jsonDoc[F("ldrTurnOff")]; @@ -1184,6 +1191,7 @@ void NetManager::checkConnection() { NetManager::sendStatus(); } #elif TARGET_GLOWWORMLUCIFERINLIGHT + currentMillisCheckConn = millis(); if (currentMillisCheckConn - prevMillisCheckConn2 > 15000) { prevMillisCheckConn2 = currentMillisCheckConn; // No updates since 15 seconds, turn off LEDs