From e2804cabc08c0be04ba345a94d7f886a7f66bdef Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 4 Jul 2019 22:58:33 +0200 Subject: [PATCH] added option to enable serial on new installations --- lib/MyESP/MyESP.cpp | 85 ++++++++++++++++++++---------------------- lib/MyESP/MyESP.h | 3 +- platformio.ini-example | 5 ++- 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/lib/MyESP/MyESP.cpp b/lib/MyESP/MyESP.cpp index 8eb3d00c2..22354bd4a 100644 --- a/lib/MyESP/MyESP.cpp +++ b/lib/MyESP/MyESP.cpp @@ -47,7 +47,9 @@ MyESP::MyESP() { _helpProjectCmds = NULL; _helpProjectCmds_count = 0; - _serial = false; + _serial = false; + _serial_default = false; + _heartbeat = false; _mqtt_host = NULL; _mqtt_password = NULL; @@ -198,7 +200,7 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) { // finally if we don't want Serial anymore, turn it off if (!_serial) { - myDebug_P(PSTR("Disabling serial port communication.")); + myDebug_P(PSTR("[SYSTEM] Disabling serial port communication.")); SerialAndTelnet.flush(); // flush so all buffer is printed to serial SerialAndTelnet.setSerial(NULL); } @@ -837,16 +839,9 @@ bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value) } // force the serial on/off -void MyESP::setUseSerial(bool toggle) { - //(void)fs_saveConfig(); // save the setting for next reboot - - if (toggle) { - SerialAndTelnet.setSerial(&Serial); - _serial = true; - } else { - SerialAndTelnet.setSerial(NULL); - _serial = false; - } +void MyESP::setUseSerial(bool b) { + _serial_default = _serial = b; + SerialAndTelnet.setSerial(b ? &Serial : NULL); } void MyESP::_telnetCommand(char * commandLine) { @@ -1604,9 +1599,7 @@ bool MyESP::_fs_loadConfig() { value = json["mqtt_password"]; _mqtt_password = (value) ? strdup(value) : NULL; - _serial = (bool)json["serial"]; // defaults to off - - // _serial = true; // uncomment for debugging everything to serial + _serial = json["serial"] | _serial_default; _heartbeat = (bool)json["heartbeat"]; // defaults to off @@ -2122,6 +2115,38 @@ void MyESP::_webserver_setup() { webServer.on("/resetall", [this]() { _webResetAllPage(); }); webServer.begin(); + + myDebug_P(PSTR("[WEB] Web server started.")); +} + +// bootup sequence +// quickly flash LED until we get a Wifi connection, or AP established +// fast way is to use WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + (state ? 4 : 8), (1 << EMSESP_Status.led_gpio)); // 4 is on, 8 is off +void MyESP::_bootupSequence() { + uint8_t boot_status = getSystemBootStatus(); + + if ((boot_status == MYESP_BOOTSTATUS_BOOTED) || (millis() <= MYESP_BOOTUP_DELAY)) { + return; // already booted, or still starting up + } + + // only kick in after a few seconds + if (boot_status == MYESP_BOOTSTATUS_POWERON) { + _setSystemBootStatus(MYESP_BOOTSTATUS_BOOTING); + } + + static uint32_t last_bootupflash = 0; + + // flash LED quickly + if ((millis() - last_bootupflash > MYESP_BOOTUP_FLASHDELAY)) { + last_bootupflash = millis(); + int state = digitalRead(LED_BUILTIN); + digitalWrite(LED_BUILTIN, !state); + } + + if (isWifiConnected()) { + _setSystemBootStatus(MYESP_BOOTSTATUS_BOOTED); // completed, reset flag + digitalWrite(LED_BUILTIN, LOW); // turn off LED + } } // setup MyESP @@ -2158,36 +2183,6 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char * _heartbeatCheck(true); // force heartbeat } -// bootup sequence -// quickly flash LED until we get a Wifi connection, or AP established -// fast way is to use WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + (state ? 4 : 8), (1 << EMSESP_Status.led_gpio)); // 4 is on, 8 is off -void MyESP::_bootupSequence() { - uint8_t boot_status = getSystemBootStatus(); - - if ((boot_status == MYESP_BOOTSTATUS_BOOTED) || (millis() <= MYESP_BOOTUP_DELAY)) { - return; // already booted, or still starting up - } - - // only kick in after a few seconds - if (boot_status == MYESP_BOOTSTATUS_POWERON) { - _setSystemBootStatus(MYESP_BOOTSTATUS_BOOTING); - } - - static uint32_t last_bootupflash = 0; - - // flash LED quickly - if ((millis() - last_bootupflash > MYESP_BOOTUP_FLASHDELAY)) { - last_bootupflash = millis(); - int state = digitalRead(LED_BUILTIN); - digitalWrite(LED_BUILTIN, !state); - } - - if (isWifiConnected()) { - _setSystemBootStatus(MYESP_BOOTSTATUS_BOOTED); // completed, reset flag - digitalWrite(LED_BUILTIN, LOW); // turn off LED - } -} - /* * Loop. This is called as often as possible and it handles wifi, telnet, mqtt etc */ diff --git a/lib/MyESP/MyESP.h b/lib/MyESP/MyESP.h index 4ed582196..330a3b7f2 100644 --- a/lib/MyESP/MyESP.h +++ b/lib/MyESP/MyESP.h @@ -9,7 +9,7 @@ #ifndef MyEMS_h #define MyEMS_h -#define MYESP_VERSION "1.1.20" +#define MYESP_VERSION "1.1.21" #include #include @@ -377,6 +377,7 @@ class MyESP { char * _boottime; bool _suspendOutput; bool _serial; + bool _serial_default; bool _heartbeat; unsigned long _getUptime(); String _buildTime(); diff --git a/platformio.ini-example b/platformio.ini-example index 4a816c41e..bc05a1bea 100644 --- a/platformio.ini-example +++ b/platformio.ini-example @@ -8,10 +8,11 @@ default_envs = debug [common] -; -DMYESP_TIMESTAMP -DTESTS -DCRASH +; -DMYESP_TIMESTAMP -DTESTS -DCRASH -DNO_SERIAL +; -DNO_SERIAL if you want a fresh install to use the Serial port debug_flags = -Wall -DCRASH release_flags = -w -general_flags = -g -DNO_GLOBAL_EEPROM +general_flags = -g -DNO_GLOBAL_EEPROM -DDNO_SERIAL arduino_core_2_3_0 = espressif8266@1.5.0 arduino_core_2_4_0 = espressif8266@1.6.0