Browse Source

Serial debug working out of configuration

v2
Xose Pérez 6 years ago
parent
commit
126471e2e0
8 changed files with 103 additions and 65 deletions
  1. +3
    -3
      code/espurna/config/general.h
  2. +58
    -8
      code/espurna/debug.ino
  3. +11
    -8
      code/espurna/espurna.ino
  4. +21
    -1
      code/espurna/hardware.ino
  5. +3
    -9
      code/espurna/ota.ino
  6. +3
    -6
      code/espurna/settings.ino
  7. +1
    -21
      code/espurna/system.ino
  8. +3
    -9
      code/espurna/web.ino

+ 3
- 3
code/espurna/config/general.h View File

@ -34,11 +34,11 @@
#endif #endif
#ifndef DEBUG_PORT #ifndef DEBUG_PORT
#define DEBUG_PORT Serial // Default debugging port
#define DEBUG_PORT Serial // Enable serial debug log
#endif #endif
#ifndef SERIAL_BAUDRATE
#define SERIAL_BAUDRATE 115200 // Default baudrate
#ifndef DEBUG_SERIAL_SPEED
#define DEBUG_SERIAL_SPEED 115200 // Default baudrate
#endif #endif
#ifndef DEBUG_ADD_TIMESTAMP #ifndef DEBUG_ADD_TIMESTAMP


+ 58
- 8
code/espurna/debug.ino View File

@ -26,6 +26,11 @@ char _udp_syslog_header[40] = {0};
#endif #endif
#endif #endif
#if DEBUG_SERIAL_SUPPORT
HardwareSerial & _dbg_port = DEBUG_PORT;
bool _dbg_serial_enabled = true;
#endif
void _debugSend(char * message) { void _debugSend(char * message) {
bool pause = false; bool pause = false;
@ -38,10 +43,12 @@ void _debugSend(char * message) {
#endif #endif
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
#if DEBUG_ADD_TIMESTAMP
DEBUG_PORT.printf(timestamp);
#endif
DEBUG_PORT.printf(message);
if (_dbg_serial_enabled) {
#if DEBUG_ADD_TIMESTAMP
_dbg_port.printf(timestamp);
#endif
_dbg_port.printf(message);
}
#endif #endif
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
@ -161,13 +168,56 @@ bool _debugKeyCheck(const char * key) {
return (strncmp(key, "dbg", 3) == 0); return (strncmp(key, "dbg", 3) == 0);
} }
int debugSerialAvailable() {
#if DEBUG_SERIAL_SUPPORT
if (_dbg_serial_enabled) {
return _dbg_port.available();
}
#endif
return 0;
}
int debugSerialRead() {
#if DEBUG_SERIAL_SUPPORT
if (_dbg_serial_enabled) {
return _dbg_port.read();
}
#endif
return 0;
}
void debugSerialWrite(uint8_t ch) {
#if DEBUG_SERIAL_SUPPORT
if (_dbg_serial_enabled) {
_dbg_port.write(ch);
}
#endif
}
void debugSetup() { void debugSetup() {
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.begin(SERIAL_BAUDRATE);
#if DEBUG_ESP_WIFI
DEBUG_PORT.setDebugOutput(true);
#endif
_dbg_serial_enabled = getSetting("dbgSerial", 1).toInt() == 1;
if (_dbg_serial_enabled) {
unsigned char port = getSetting("dbgPort", 0).toInt();
if (0 == port) {
_dbg_port = Serial;
} else {
_dbg_port = Serial1;
}
unsigned long speed = getSetting("dbgSpeed", DEBUG_SERIAL_SPEED).toInt();
_dbg_port.begin(speed);
#if DEBUG_ESP_WIFI
_dbg_port.setDebugOutput(true);
#endif
}
#endif #endif
settingsRegisterKeyCheck(_debugKeyCheck); settingsRegisterKeyCheck(_debugKeyCheck);


+ 11
- 8
code/espurna/espurna.ino View File

@ -44,23 +44,26 @@ void setup() {
// Basic modules, will always run // Basic modules, will always run
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Serial debug
#if DEBUG_SUPPORT
debugSetup();
#endif
// Init EEPROM // Init EEPROM
eepromSetup(); eepromSetup();
// Init Serial, SPIFFS and system check
systemSetup();
// Init persistance and terminal features // Init persistance and terminal features
settingsSetup(); settingsSetup();
// Serial debug
// Requires SETTINGS
#if DEBUG_SUPPORT
debugSetup();
#endif
// Load board data // Load board data
// Requires SETTINGS
hardwareSetup(); hardwareSetup();
// Init Serial, SPIFFS and system check
// Requires EEPROM and DEBUG
systemSetup();
// Show welcome message and system configuration // Show welcome message and system configuration
info(); info();


+ 21
- 1
code/espurna/hardware.ino View File

@ -133,9 +133,12 @@ void _hardwareLoad() {
setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH);
setSetting("btnRelay", 0, 0); setSetting("btnRelay", 0, 0);
setSetting("dsGPIO", 0, 14);
setSetting("dhtEnabled", 1);
setSetting("dhtGPIO", 0, 14); setSetting("dhtGPIO", 0, 14);
setSetting("dsEnabled", 1);
setSetting("dsGPIO", 0, 14);
setSetting("ledGPIO", 0, 13); setSetting("ledGPIO", 0, 13);
setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE);
@ -856,6 +859,11 @@ void _hardwareLoad() {
setSetting("btnRelay", 0, 0); setSetting("btnRelay", 0, 0);
setSetting("btnRelay", 1, 1); setSetting("btnRelay", 1, 1);
// The ESPLive has an ADC MUX which needs to be enabled
setSetting("ledGPIO", 0, 16);
setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT);
setSetting("ledMode", LED_MODE_ON);
setSetting("rlyGPIO", 0, 12); setSetting("rlyGPIO", 0, 12);
setSetting("rlyGPIO", 1, 13); setSetting("rlyGPIO", 1, 13);
setSetting("rlyType", 0, RELAY_TYPE_NORMAL); setSetting("rlyType", 0, RELAY_TYPE_NORMAL);
@ -1814,9 +1822,21 @@ void _hardwareLoad() {
} }
void _hardwareSpecific() {
// These devices use the hardware UART
// to communicate to secondary microcontrollers
#if defined(ITEAD_SONOFF_RFBRIDGE) || defined(ITEAD_SONOFF_DUAL) || defined(STM_RELAY)
Serial.begin(DEBUG_SERIAL_SPEED);
#endif
}
void hardwareSetup() { void hardwareSetup() {
_hardwareMigrate(); _hardwareMigrate();
if (getSetting("board", 1).toInt() != 1) { if (getSetting("board", 1).toInt() != 1) {
_hardwareLoad(); _hardwareLoad();
} }
_hardwareSpecific();
} }

+ 3
- 9
code/espurna/ota.ino View File

@ -69,9 +69,7 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
DEBUG_MSG_P(PSTR("[OTA] Success: %u bytes\n"), _ota_size); DEBUG_MSG_P(PSTR("[OTA] Success: %u bytes\n"), _ota_size);
deferredReset(100, CUSTOM_RESET_OTA); deferredReset(100, CUSTOM_RESET_OTA);
} else { } else {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
#endif
DEBUG_MSG_P(PSTR("[OTA] Error #%u\n"), Update.getError());
eepromRotate(true); eepromRotate(true);
} }
@ -99,9 +97,7 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
Update.runAsync(true); Update.runAsync(true);
if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)) { if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)) {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
#endif
DEBUG_MSG_P(PSTR("[OTA] Error #%u\n"), Update.getError());
} }
p = strstr((char *)data, "\r\n\r\n") + 4; p = strstr((char *)data, "\r\n\r\n") + 4;
@ -111,9 +107,7 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
if (!Update.hasError()) { if (!Update.hasError()) {
if (Update.write((uint8_t *) p, len) != len) { if (Update.write((uint8_t *) p, len) != len) {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
#endif
DEBUG_MSG_P(PSTR("[OTA] Error #%u\n"), Update.getError());
} }
} }


+ 3
- 6
code/espurna/settings.ino View File

@ -530,14 +530,12 @@ void settingsRegisterKeyCheck(setting_key_check_callback_f callback) {
void settingsSetup() { void settingsSetup() {
EEPROMr.begin(SPI_FLASH_SEC_SIZE);
_serial.callback([](uint8_t ch) { _serial.callback([](uint8_t ch) {
#if TELNET_SUPPORT #if TELNET_SUPPORT
telnetWrite(ch); telnetWrite(ch);
#endif #endif
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.write(ch);
debugSerialWrite(ch);
#endif #endif
}); });
@ -575,12 +573,11 @@ void settingsLoop() {
_settings_save = false; _settings_save = false;
} }
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT
while (DEBUG_PORT.available()) {
_serial.inject(DEBUG_PORT.read());
while (debugSerialAvailable()) {
_serial.inject(debugSerialRead());
} }
#endif #endif


+ 1
- 21
code/espurna/system.ino View File

@ -60,7 +60,7 @@ void systemCheckLoop() {
} }
} }
#endif
#endif //SYSTEM_CHECK_ENABLED
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -72,7 +72,6 @@ unsigned long systemLoopDelay() {
return _loop_delay; return _loop_delay;
} }
unsigned long systemLoadAverage() { unsigned long systemLoadAverage() {
return _load_average; return _load_average;
} }
@ -132,22 +131,6 @@ void systemLoop() {
} }
void _systemSetupSpecificHardware() {
//The ESPLive has an ADC MUX which needs to be configured.
#if defined(MANCAVEMADE_ESPLIVE)
pinMode(16, OUTPUT);
digitalWrite(16, HIGH); //Defualt CT input (pin B, solder jumper B)
#endif
// These devices use the hardware UART
// to communicate to secondary microcontrollers
#if defined(ITEAD_SONOFF_RFBRIDGE) || defined(ITEAD_SONOFF_DUAL) || defined(STM_RELAY)
Serial.begin(SERIAL_BAUDRATE);
#endif
}
void systemSetup() { void systemSetup() {
#if SPIFFS_SUPPORT #if SPIFFS_SUPPORT
@ -159,9 +142,6 @@ void systemSetup() {
systemCheck(false); systemCheck(false);
#endif #endif
// Init device-specific hardware
_systemSetupSpecificHardware();
// Cache loop delay value to speed things (recommended max 250ms) // Cache loop delay value to speed things (recommended max 250ms)
_loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); _loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str());
_loop_delay = constrain(_loop_delay, 0, 300); _loop_delay = constrain(_loop_delay, 0, 300);


+ 3
- 9
code/espurna/web.ino View File

@ -300,18 +300,14 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
DEBUG_MSG_P(PSTR("[UPGRADE] Start: %s\n"), filename.c_str()); DEBUG_MSG_P(PSTR("[UPGRADE] Start: %s\n"), filename.c_str());
Update.runAsync(true); Update.runAsync(true);
if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)) { if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)) {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
#endif
DEBUG_MSG_P(PSTR("[UPGRADE] Error #%u\n"), Update.getError());
} }
} }
if (!Update.hasError()) { if (!Update.hasError()) {
if (Update.write(data, len) != len) { if (Update.write(data, len) != len) {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
#endif
DEBUG_MSG_P(PSTR("[UPGRADE] Error #%u\n"), Update.getError());
} }
} }
@ -319,9 +315,7 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
if (Update.end(true)){ if (Update.end(true)){
DEBUG_MSG_P(PSTR("[UPGRADE] Success: %u bytes\n"), index + len); DEBUG_MSG_P(PSTR("[UPGRADE] Success: %u bytes\n"), index + len);
} else { } else {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
#endif
DEBUG_MSG_P(PSTR("[UPGRADE] Error #%u\n"), Update.getError());
} }
} else { } else {
DEBUG_MSG_P(PSTR("[UPGRADE] Progress: %u bytes\r"), index + len); DEBUG_MSG_P(PSTR("[UPGRADE] Progress: %u bytes\r"), index + len);


Loading…
Cancel
Save