diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 650b80eb..126f93d5 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -1,10 +1,6 @@ #ifndef HASP_CONF_H #define HASP_CONF_H -#define HASP_VERSION_MAJOR 0 -#define HASP_VERSION_MINOR 2 -#define HASP_VERSION_REVISION 1108 - #define HASP_USE_APP 1 /* Network Services */ diff --git a/lib/ArduinoLog/ArduinoLog.h b/lib/ArduinoLog/ArduinoLog.h index d0f9f3d9..fb5a66c9 100644 --- a/lib/ArduinoLog/ArduinoLog.h +++ b/lib/ArduinoLog/ArduinoLog.h @@ -22,7 +22,7 @@ Licensed under the MIT License . #include "WProgram.h" #endif #include "StringStream.h" -typedef void (*printfunction)(int level, Print *); +typedef void (*printfunction)(uint8_t tag, int level, Print *); //#include //#include @@ -31,13 +31,18 @@ typedef void (*printfunction)(int level, Print *); // ************************************************************************ //#define DISABLE_LOGGING -#define LOG_LEVEL_SILENT 0 -#define LOG_LEVEL_FATAL 1 -#define LOG_LEVEL_ERROR 2 -#define LOG_LEVEL_WARNING 3 -#define LOG_LEVEL_NOTICE 4 -#define LOG_LEVEL_TRACE 5 -#define LOG_LEVEL_VERBOSE 6 +#define LOG_LEVEL_SILENT -1 + +#define LOG_LEVEL_FATAL 0 +#define LOG_LEVEL_ALERT 1 +#define LOG_LEVEL_CRITICAL 2 +#define LOG_LEVEL_ERROR 3 +#define LOG_LEVEL_WARNING 4 +#define LOG_LEVEL_NOTICE 5 +#define LOG_LEVEL_INFO 6 +#define LOG_LEVEL_TRACE 6 +#define LOG_LEVEL_VERBOSE 7 +#define LOG_LEVEL_DEBUG 7 #define CR "\n" #define LOGGING_VERSION 1_0_3 @@ -85,7 +90,7 @@ class Logging { */ Logging() #ifndef DISABLE_LOGGING - // : _level(LOG_LEVEL_SILENT), _showLevel(true) + // : _level(LOG_LEVEL_SILENT), _showLevel(true) #endif {} @@ -126,7 +131,7 @@ class Logging { * \param level - The new log level. * \return void */ - void setLevel(uint8_t slot,int level); + void setLevel(uint8_t slot, int level); /** * Get the log level. @@ -142,7 +147,7 @@ class Logging { * false otherwise. * \return void */ - void setShowLevel(uint8_t slot,bool showLevel); + void setShowLevel(uint8_t slot, bool showLevel); /** * Get whether the log level is shown during logging @@ -178,10 +183,10 @@ class Logging { * \param ... any number of variables * \return void */ - template void fatal(T msg, Args... args) + template void fatal(uint8_t tag, T msg, Args... args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_FATAL, msg, args...); + printLevel(tag, LOG_LEVEL_FATAL, msg, args...); #endif } @@ -195,10 +200,10 @@ class Logging { * \param ... any number of variables * \return void */ - template void error(T msg, Args... args) + template void error(uint8_t tag, T msg, Args... args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_ERROR, msg, args...); + printLevel(tag, LOG_LEVEL_ERROR, msg, args...); #endif } @@ -212,10 +217,10 @@ class Logging { * \param ... any number of variables * \return void */ - template void warning(T msg, Args... args) + template void warning(uint8_t tag, T msg, Args... args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_WARNING, msg, args...); + printLevel(tag, LOG_LEVEL_WARNING, msg, args...); #endif } @@ -229,10 +234,10 @@ class Logging { * \param ... any number of variables * \return void */ - template void notice(T msg, Args... args) + template void notice(uint8_t tag, T msg, Args... args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_NOTICE, msg, args...); + printLevel(tag, LOG_LEVEL_NOTICE, msg, args...); #endif } @@ -246,10 +251,10 @@ class Logging { * \param ... any number of variables * \return void */ - template void trace(T msg, Args... args) + template void trace(uint8_t tag, T msg, Args... args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_TRACE, msg, args...); + printLevel(tag, LOG_LEVEL_TRACE, msg, args...); #endif } @@ -263,10 +268,10 @@ class Logging { * \param ... any number of variables * \return void */ - template void verbose(T msg, Args... args) + template void verbose(uint8_t tag, T msg, Args... args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_VERBOSE, msg, args...); + printLevel(tag, LOG_LEVEL_VERBOSE, msg, args...); #endif } @@ -277,23 +282,23 @@ class Logging { void printFormat(Print * logOutput, const char format, va_list * args); - template void printLevel(int level, T msg, ...) + template void printLevel(uint8_t tag, int level, T msg, ...) { #ifndef DISABLE_LOGGING for(uint8_t i = 0; i < 3; i++) { - if(_logOutput[i] == NULL || level>_level[i]) continue; + if(_logOutput[i] == NULL || level > _level[i]) continue; if(_prefix != NULL) { - _prefix(level, _logOutput[i]); + _prefix(tag, level, _logOutput[i]); } va_list args; va_start(args, msg); print(_logOutput[i], msg, args); - + if(_suffix != NULL) { - _suffix(level, _logOutput[i]); + _suffix(tag, level, _logOutput[i]); } } diff --git a/lib/lv_fs_if/lv_fs_spiffs.cpp b/lib/lv_fs_if/lv_fs_spiffs.cpp index aad335bd..1a1a1082 100644 --- a/lib/lv_fs_if/lv_fs_spiffs.cpp +++ b/lib/lv_fs_if/lv_fs_spiffs.cpp @@ -19,6 +19,8 @@ #endif #include "FS.h" // Include the SPIFFS library +#define TAG_LVFS 91 + /********************* * DEFINES *********************/ @@ -134,10 +136,10 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, char filename[32]; snprintf_P(filename, sizeof(filename), PSTR("/%s"), path); - Log.verbose(F("LVFS: Opening %s"), filename); + Log.verbose(TAG_LVFS, F("Opening %s"), filename); File file = SPIFFS.open(filename, mode == LV_FS_MODE_WR ? FILE_WRITE : FILE_READ); - Log.verbose(F("LVFS: %d"), __LINE__); + Log.verbose(TAG_LVFS, F("%d"), __LINE__); if(!file) { return LV_FS_RES_NOT_EX; @@ -146,14 +148,14 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path, } else { // f.seek(0, SeekSet); - // Log.verbose(F("LVFS: Assigning %s"), f.name()); - Log.verbose(F("LVFS: %d"), __LINE__); + // Log.verbose(TAG_LVFS,F("Assigning %s"), f.name()); + Log.verbose(TAG_LVFS, F("%d"), __LINE__); lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; /*Just avoid the confusing casings*/ - // Log.verbose(F("LVFS: Copying %s"), f.name()); - Log.verbose(F("LVFS: %d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t)); - if (fp != NULL) (*fp) = file; + // Log.verbose(TAG_LVFS,F("Copying %s"), f.name()); + Log.verbose(TAG_LVFS, F("%d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t)); + if(fp != NULL) (*fp) = file; // memcpy(fp,&file,sizeof(lv_spiffs_file_t)); - Log.verbose(F("LVFS: %d"), __LINE__); + Log.verbose(TAG_LVFS, F("%d"), __LINE__); return LV_FS_RES_OK; } } @@ -170,10 +172,10 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) (void)drv; /*Unused*/ lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p; // File file = fp; - //file = SPIFFS.open("/background.bin"); + // file = SPIFFS.open("/background.bin"); if(!file) { - // Log.verbose(F("LVFS: Invalid file")); + // Log.verbose(TAG_LVFS,F("Invalid file")); return LV_FS_RES_NOT_EX; } else if(file.isDirectory()) { @@ -198,15 +200,15 @@ static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) { (void)drv; /*Unused*/ - lv_spiffs_file_t *fp = (lv_spiffs_file_t *)file_p; - lv_spiffs_file_t file = *fp; + lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; + lv_spiffs_file_t file = *fp; if(!file) { - // Log.verbose(F("LVFS: Invalid file")); + // Log.verbose(TAG_LVFS,F("Invalid file")); return LV_FS_RES_NOT_EX; } else { - // Log.verbose(F("LVFS: Reading %u bytes from %s at position %u"), btr, file.name(), file.position()); + // Log.verbose(TAG_LVFS,F("Reading %u bytes from %s at position %u"), btr, file.name(), file.position()); *br = (uint32_t)file.readBytes((char *)buf, btr); Serial.print("!"); return LV_FS_RES_OK; @@ -229,7 +231,7 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, // File file = fp; if(!file) { - // Log.verbose(F("LVFS: Invalid file")); + // Log.verbose(TAG_LVFS,F("Invalid file")); return LV_FS_RES_NOT_EX; } else { @@ -253,7 +255,7 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos) // File file = fp; if(!file) { - // Log.verbose(F("LVFS: Invalid file")); + // Log.verbose(TAG_LVFS,F("Invalid file")); return LV_FS_RES_NOT_EX; } else { @@ -276,7 +278,7 @@ static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p) // File file = fp; if(!file) { - // Log.verbose(F("LVFS: Invalid file")); + // Log.verbose(TAG_LVFS,F("Invalid file")); return LV_FS_RES_NOT_EX; } else { @@ -300,7 +302,7 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) // File file = fp; if(!file) { - // Log.verbose(F("LVFS: Invalid file")); + // Log.verbose(TAG_LVFS,F("Invalid file")); return LV_FS_RES_NOT_EX; } else { diff --git a/lib/lv_lib_zifont/lv_zifont.cpp b/lib/lv_lib_zifont/lv_zifont.cpp index 087b2198..4059a867 100644 --- a/lib/lv_lib_zifont/lv_zifont.cpp +++ b/lib/lv_lib_zifont/lv_zifont.cpp @@ -19,6 +19,8 @@ #define ColorBlack 0x0f #define ColorWhite 0x00 +#define TAG_FONT 92 + /********************** * TYPEDEFS **********************/ @@ -79,7 +81,7 @@ static inline bool openFont(File & file, const char * filename) file = SPIFFS.open(filename, "r"); if(!file) { - Log.error(F("FONT: %sOpening font: %s"), filename); + Log.error(TAG_FONT,F("Opening font: %s"), filename); return false; } return file; @@ -133,14 +135,14 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size /* Check that we read the correct size */ if(readSize != sizeof(zi_font_header_t)) { - Log.error(F("FONT: Error reading ziFont Header")); + Log.error(TAG_FONT,F("Error reading ziFont Header")); file.close(); return ZIFONT_ERROR_READING_DATA; } /* Check ziFile Header Format */ if(header.Password != 4 || header.Version != 5) { - Log.error(F("FONT: Unknown font file format")); + Log.error(TAG_FONT,F("Unknown font file format")); file.close(); return ZIFONT_ERROR_UNKNOWN_HEADER; } @@ -171,12 +173,12 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size //* Check that we read the correct size if(readSize != sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE) { - Log.error(F("FONT: Error reading ziFont character map")); + Log.error(TAG_FONT,F("Error reading ziFont character map")); file.close(); return ZIFONT_ERROR_READING_DATA; } - Log.notice(F("FONT: Loaded V%d Font File: %s containing %d characters"), header.Version, font_path, + Log.notice(TAG_FONT,F("Loaded V%d Font File: %s containing %d characters"), header.Version, font_path, header.Maximumnumchars); file.close(); @@ -281,7 +283,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, if(readSize != sizeof(lv_zifont_char_t)) { file.close(); lv_mem_free(charInfo); - Log.error(F("FONT: Wrong number of bytes read from flash")); + Log.error(TAG_FONT,F("Wrong number of bytes read from flash")); return NULL; } @@ -289,7 +291,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, if(charInfo->character != unicode_letter) { file.close(); lv_mem_free(charInfo); - Log.error(F("FONT: Incorrect letter read from flash")); + Log.error(TAG_FONT,F("Incorrect letter read from flash")); return NULL; } } @@ -311,7 +313,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, if((uint8_t)b[0] != 3) { file.close(); lv_mem_free(charInfo); - snprintf_P(data, sizeof(data), PSTR("FONT: [ERROR] Character %u at %u is not 3bpp encoded but %u"), glyphID, + snprintf_P(data, sizeof(data), PSTR("[ERROR] Character %u at %u is not 3bpp encoded but %u"), glyphID, datapos, b[0]); debugPrintln(data); @@ -492,7 +494,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_ // Serial.printf("kernL %u - kernR %u \n", myCharIndex->kerningL, myCharIndex->kerningR); // Serial.printf("ofs_x %u - ofs_y %u \n\n", dsc_out->ofs_x, dsc_out->ofs_x); - // debugPrintln("FONT: Char " + String((char)myCharIndex->character) + " lookup took " + String(millis() - + // debugPrintln("Char " + String((char)myCharIndex->character) + " lookup took " + String(millis() - // startMillis) + "ms"); return true; } diff --git a/platformio.ini b/platformio.ini index 1d2b0ca7..b942f79e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -77,6 +77,9 @@ build_flags = ;-D DISABLE_LOGGING -I include ; include lv_conf.h and hasp_conf.h ${override.build_flags} + -D HASP_VERSION_MAJOR=0 + -D HASP_VERSION_MINOR=2 + -D HASP_VERSION_REVISION=1109 src_filter = +<*> -<.git/> -<.svn/> - - - - - @@ -88,6 +91,7 @@ esp8266_flags= ${env.build_flags} -D HTTP_UPLOAD_BUFLEN=640 ; lower http upload buffer -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages +; -- hasp-lvgl build options ------------------------ -D HASP_USE_WIFI=1 -D HASP_USE_MQTT=1 -D HASP_USE_HTTP=1 @@ -103,12 +107,13 @@ esp32_flags= ${env.build_flags} -D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages +; -- hasp-lvgl build options ------------------------ -D HASP_USE_WIFI=1 -D HASP_USE_MQTT=1 -D HASP_USE_HTTP=1 -D HASP_USE_MDNS=1 - -D HASP_USE_SYSLOG=0 - -D HASP_USE_TELNET=0 + -D HASP_USE_SYSLOG=1 + -D HASP_USE_TELNET=1 -D HASP_USE_SPIFFS=1 -D HASP_USE_EEPROM=1 -D HASP_USE_GPIO=1 diff --git a/src/hasp.cpp b/src/hasp.cpp index fd052bbd..62a56151 100644 --- a/src/hasp.cpp +++ b/src/hasp.cpp @@ -150,7 +150,7 @@ lv_obj_t * hasp_find_obj_from_id(lv_obj_t * parent, uint8_t objid) uint16_t tabcount = lv_tabview_get_tab_count(child); for(uint16_t i = 0; i < tabcount; i++) { lv_obj_t * tab = lv_tabview_get_tab(child, i); - Log.verbose("Found tab %i", i); + Log.verbose(TAG_HASP, "Found tab %i", i); if(tab->user_data && (lv_obj_user_data_t)objid == tab->user_data) return tab; // object found grandchild = hasp_find_obj_from_id(tab, objid); @@ -250,7 +250,11 @@ static inline void hasp_send_obj_attribute_txt(lv_obj_t * obj, const char * txt) // Used in the dispatcher void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, const char * payload) { - hasp_process_obj_attribute(hasp_find_obj_from_id(pageid, objid), attr, payload, strlen(payload) > 0); + if(lv_obj_t * obj = hasp_find_obj_from_id(pageid, objid)) { + hasp_process_obj_attribute(obj, attr, payload, strlen(payload) > 0); + } else { + Log.warning(TAG_HASP, F("Unknown object p[%d].b[%d]"), pageid, objid); + } } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -368,9 +372,9 @@ void haspSetup() lv_fs_res_t res; res = lv_fs_open(&f, "F:/pages.jsonl", LV_FS_MODE_RD); if(res == LV_FS_RES_OK) - Log.error(F("Opening pages.json OK")); + Log.error(TAG_HASP, F("Opening pages.json OK")); else - Log.verbose(F("Opening pages.json from FS failed %d"), res); + Log.verbose(TAG_HASP, F("Opening pages.json from FS failed %d"), res); uint32_t btoread = 128; uint32_t bread = 0; @@ -378,17 +382,17 @@ void haspSetup() res = lv_fs_read(&f, &buffer, btoread, &bread); if(res == LV_FS_RES_OK) { - Log.error(F("Reading pages.json OK %u"), bread); + Log.error(TAG_HASP, F("Reading pages.json OK %u"), bread); buffer[127] = '\0'; - Log.verbose(buffer); + Log.verbose(TAG_HASP, buffer); } else - Log.verbose(F("Reading pages.json from FS failed %d"), res); + Log.verbose(TAG_HASP, F("Reading pages.json from FS failed %d"), res); res = lv_fs_close(&f); if(res == LV_FS_RES_OK) - Log.error(F("Closing pages.json OK")); + Log.error(TAG_HASP, F("Closing pages.json OK")); else - Log.verbose(F("Closing pages.json on FS failed %d"), res); + Log.verbose(TAG_HASP, F("Closing pages.json on FS failed %d"), res); /******* File System Test ********************************************************************/ /* ********** Font Initializations ********** */ @@ -398,7 +402,7 @@ void haspSetup() lv_zifont_init(); if(lv_zifont_font_init(&haspFonts[0], haspZiFontPath, 32) != 0) { - Log.error(F("HASP: Failed to set font to %s"), haspZiFontPath); + Log.error(TAG_HASP, F("Failed to set font to %s"), haspZiFontPath); haspFonts[0] = LV_FONT_DEFAULT; } else { // defaultFont = haspFonts[0]; @@ -413,8 +417,8 @@ void haspSetup() switch(haspThemeId) { #if(LV_USE_THEME_EMPTY == 1) case 0: - th = lv_theme_empty_init(LV_COLOR_PURPLE, LV_COLOR_BLACK, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1], - haspFonts[2], haspFonts[3]); + th = lv_theme_empty_init(LV_COLOR_PURPLE, LV_COLOR_BLACK, LV_THEME_DEFAULT_FLAGS, haspFonts[0], + haspFonts[1], haspFonts[2], haspFonts[3]); break; #endif @@ -464,8 +468,8 @@ void haspSetup() #if LV_USE_THEME_TEMPLATE == 1 case 7: - th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1], - haspFonts[2], haspFonts[3]); + th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0], + haspFonts[1], haspFonts[2], haspFonts[3]); break; #endif #if(LV_USE_THEME_HASP == 1) @@ -487,13 +491,13 @@ void haspSetup() default: th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1], haspFonts[2], haspFonts[3]); - Log.error(F("HASP: Unknown theme selected")); + Log.error(TAG_HASP, F("Unknown theme selected")); } if(th) { - Log.verbose(F("HASP: Custom theme loaded")); + Log.verbose(TAG_HASP, F("Custom theme loaded")); } else { - Log.error(F("HASP: No theme could be loaded")); + Log.error(TAG_HASP, F("No theme could be loaded")); } // lv_theme_set_current(th); /* ********** Theme Initializations ********** */ @@ -634,16 +638,16 @@ void IRAM_ATTR btn_event_handler(lv_obj_t * obj, lv_event_t event) case LV_EVENT_VALUE_CHANGED: strcat_P(buffer, PSTR("Value Changed")); - Log.notice(buffer); + Log.notice(TAG_HASP, buffer); return; case LV_EVENT_DELETE: strcat_P(buffer, PSTR("Object deleted")); - Log.notice(buffer, event); + Log.notice(TAG_HASP, buffer, event); return; default: strcat_P(buffer, PSTR("HASP : Unknown Event occured")); - Log.warning(buffer, event); + Log.warning(TAG_HASP, buffer, event); return; } @@ -725,11 +729,11 @@ void haspClearPage(uint16_t pageid) { lv_obj_t * page = get_page_obj(pageid); if(!page || pageid > 255) { - Log.warning(F("HASP: Page ID %u not defined"), pageid); + Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid); } else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) { - Log.warning(F("HASP: Cannot clear system layer")); + Log.warning(TAG_HASP, F("Cannot clear system layer")); } else { - Log.notice(F("HASP: Clearing page %u"), pageid); + Log.notice(TAG_HASP, F("Clearing page %u"), pageid); lv_obj_clean(pages[pageid]); } } @@ -743,12 +747,12 @@ void haspSetPage(uint8_t pageid) { lv_obj_t * page = get_page_obj(pageid); if(!page) { - Log.warning(F("HASP: Page ID %u not found"), pageid); + Log.warning(TAG_HASP, F("Page ID %u not found"), pageid); } else if(page == lv_layer_sys() || page == lv_layer_top()) { - Log.warning(F("HASP: %sCannot change to a layer")); + Log.warning(TAG_HASP, F("%sCannot change to a layer")); } else { // if(pageid != current_page) { - Log.notice(F("HASP: Changing page to %u"), pageid); + Log.notice(TAG_HASP, F("Changing page to %u"), pageid); current_page = pageid; lv_scr_load(page); //} @@ -779,7 +783,7 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id) /* Page selection */ lv_obj_t * page = get_page_obj(pageid); if(!page) { - Log.warning(F("HASP: Page ID %u not defined"), pageid); + Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid); return; } /* save the current pageid */ @@ -793,10 +797,10 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id) uint8_t parentid = config[F("parentid")].as(); parent_obj = hasp_find_obj_from_id(page, parentid); if(!parent_obj) { - Log.warning(F("HASP: Parent ID p[%u].b[%u] not found"), pageid, parentid); + Log.warning(TAG_HASP, F("Parent ID p[%u].b[%u] not found"), pageid, parentid); parent_obj = page; // create on the page instead ?? } else { - Log.trace(F("HASP: Parent ID p[%u].b[%u] found"), pageid, parentid); + Log.trace(TAG_HASP, F("Parent ID p[%u].b[%u] found"), pageid, parentid); } } @@ -806,7 +810,7 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id) /* Define Objects*/ lv_obj_t * obj = hasp_find_obj_from_id(parent_obj, id); if(obj) { - Log.warning(F("HASP: Object ID %u already exists!"), id); + Log.warning(TAG_HASP, F("Object ID %u already exists!"), id); return; } @@ -950,12 +954,12 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id) /* ----- Other Object ------ */ default: - Log.warning(F("HASP: Unsupported Object ID %u"), objid); + Log.warning(TAG_HASP, F("Unsupported Object ID %u"), objid); return; } if(!obj) { - Log.warning(F("HASP: Object is NULL, skipping...")); + Log.warning(TAG_HASP, F("Object is NULL, skipping...")); return; } @@ -971,27 +975,27 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id) for(JsonPair keyValue : config) { v = keyValue.value().as(); hasp_process_obj_attribute(obj, keyValue.key().c_str(), v.c_str(), true); - // Log.trace(F(" * %s => %s"), keyValue.key().c_str(), v.c_str()); + // Log.trace(TAG_HASP,F(" * %s => %s"), keyValue.key().c_str(), v.c_str()); } /** testing start **/ lv_obj_user_data_t temp; if(!FindIdFromObj(obj, &pageid, &temp)) { - Log.error(F("HASP: Lost track of the created object, not found!")); + Log.error(TAG_HASP, F("Lost track of the created object, not found!")); return; } /** testing end **/ lv_obj_type_t list; lv_obj_get_type(obj, &list); - Log.verbose(F("HASP: * p[%u].b[%u] = %s"), pageid, temp, list.type[0]); + Log.verbose(TAG_HASP, F(" * p[%u].b[%u] = %s"), pageid, temp, list.type[0]); /* Double-check */ lv_obj_t * test = hasp_find_obj_from_id(pageid, (uint8_t)temp); if(test != obj) { - Log.error(F("HASP: Objects DO NOT match!")); + Log.error(TAG_HASP, F("Objects DO NOT match!")); } else { - // Log.trace(F("Objects match!")); + // Log.trace(TAG_HASP,F("Objects match!")); } } @@ -1001,29 +1005,29 @@ void haspLoadPage(const char * pages) if(pages[0] == '\0') return; if(!SPIFFS.begin()) { - Log.error(F("HASP: FS not mounted. Failed to load %s"), pages); + Log.error(TAG_HASP, F("FS not mounted. Failed to load %s"), pages); return; } if(!SPIFFS.exists(pages)) { - Log.error(F("HASP: Non existing file %s"), pages); + Log.error(TAG_HASP, F("Non existing file %s"), pages); return; } - Log.notice(F("HASP: Loading file %s"), pages); + Log.notice(TAG_HASP, F("Loading file %s"), pages); File file = SPIFFS.open(pages, "r"); dispatchParseJsonl(file); file.close(); - Log.notice(F("HASP: File %s loaded"), pages); + Log.notice(TAG_HASP, F("File %s loaded"), pages); #else #if HASP_USE_EEPROM > 0 - Log.notice(F("HASP: Loading jsonl from EEPROM...")); + Log.notice(TAG_HASP, F("Loading jsonl from EEPROM...")); EepromStream eepromStream(4096, 1024); dispatchJsonl(eepromStream); - Log.notice(F("HASP: Loaded jsonl from EEPROM")); + Log.notice(TAG_HASP, F("Loaded jsonl from EEPROM")); #endif #endif diff --git a/src/hasp_attribute.cpp b/src/hasp_attribute.cpp index da68cedf..0a5f4c20 100644 --- a/src/hasp_attribute.cpp +++ b/src/hasp_attribute.cpp @@ -48,7 +48,7 @@ static inline lv_color_t haspLogColor(lv_color_t color) // uint8_t r = (LV_COLOR_GET_R(color) * 263 + 7) >> 5; // uint8_t g = (LV_COLOR_GET_G(color) * 259 + 3) >> 6; // uint8_t b = (LV_COLOR_GET_B(color) * 263 + 7) >> 5; - // Log.trace(F("Color: R%u G%u B%u"), r, g, b); + // Log.trace(TAG_ATTR,F("Color: R%u G%u B%u"), r, g, b); return color; } @@ -114,7 +114,7 @@ static lv_color_t haspPayloadToColor(const char * payload) } /* Unknown format */ - Log.warning(F("Invalid color %s"), payload); + Log.warning(TAG_ATTR, F("Invalid color %s"), payload); return LV_COLOR_BLACK; } @@ -163,7 +163,7 @@ static void hasp_process_label_long_mode(lv_obj_t * obj, const char * payload, b } else if(!strcasecmp_P(payload, PSTR("loop"))) { mode = LV_LABEL_LONG_SROLL_CIRC; } else { - return Log.warning(F("Invalid long mode")); + return Log.warning(TAG_ATTR, F("Invalid long mode")); } lv_label_set_long_mode(obj, mode); } else { @@ -186,10 +186,10 @@ lv_obj_t * FindButtonLabel(lv_obj_t * btn) } } else { - Log.error(F("HASP: FindButtonLabel NULL Pointer encountered")); + Log.error(TAG_ATTR, F("HASP: FindButtonLabel NULL Pointer encountered")); } } else { - Log.warning(F("HASP: Button not defined")); + Log.warning(TAG_ATTR, F("HASP: Button not defined")); } return NULL; } @@ -207,7 +207,7 @@ static inline void haspSetLabelText(lv_obj_t * obj, const char * value) static inline bool haspGetLabelText(lv_obj_t * obj, char * text) { if(!obj) { - Log.warning(F("HASP: Button not defined")); + Log.warning(TAG_ATTR, F("HASP: Button not defined")); return false; } @@ -222,7 +222,7 @@ static inline bool haspGetLabelText(lv_obj_t * obj, char * text) } } else { - Log.warning(F("HASP: haspGetLabelText NULL Pointer encountered")); + Log.warning(TAG_ATTR, F("HASP: haspGetLabelText NULL Pointer encountered")); } return false; @@ -420,7 +420,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t if(font) { return lv_obj_set_style_local_text_font(obj, part, state, font); } else { - return Log.warning(F("HASP: Unknown Font ID %s"), payload); + return Log.warning(TAG_ATTR, F("HASP: Unknown Font ID %s"), payload); } } @@ -527,7 +527,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t if(font) { return lv_obj_set_style_local_value_font(obj, part, state, font); } else { - return Log.warning(F("HASP: Unknown Font ID %s"), attr_p); + return Log.warning(TAG_ATTR, F("HASP: Unknown Font ID %s"), attr_p); } } @@ -555,7 +555,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t /* Transition attributes */ // Todo } - Log.warning(F("HASP: Unknown property %s"), attr_p); + Log.warning(TAG_ATTR, F("HASP: Unknown property %s"), attr_p); } // OK @@ -640,7 +640,6 @@ static void hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, co if(check_obj_type(objtype, LV_HASP_CHECKBOX)) { return update ? lv_checkbox_set_checked(obj, is_true(payload)) : hasp_out_int(obj, attr, lv_checkbox_is_checked(obj)); - } if(check_obj_type(objtype, LV_HASP_SWITCH)) { if(update) { @@ -724,7 +723,7 @@ static void hasp_process_obj_attribute_range(lv_obj_t * obj, const char * attr, return update ? lv_bar_set_range(obj, set_min ? val : min, set_max ? val : max) : hasp_out_int(obj, attr, set_min ? lv_bar_get_min_value(obj) : lv_bar_get_max_value(obj)); } - + if(check_obj_type(objtype, LV_HASP_LMETER)) { int16_t min = lv_linemeter_get_min_value(obj); int16_t max = lv_linemeter_get_max_value(obj); @@ -746,14 +745,14 @@ static void hasp_process_obj_attribute_range(lv_obj_t * obj, const char * attr, void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update) { unsigned long start = millis(); - if(!obj) return Log.warning(F("HASP: Unknown object")); + if(!obj) return Log.warning(TAG_ATTR, F("Unknown object")); int16_t val = atoi(payload); char * attr = (char *)attr_p; if(*attr == '.') attr++; // strip leading '.' uint16_t attr_hash = sdbm(attr); - // Log.trace("ATTR: %s => %d", attr, attr_hash); + // Log.trace(TAG_ATTR,"%s => %d", attr, attr_hash); /* 16-bit Hash Lookup Table */ switch(attr_hash) { @@ -904,7 +903,7 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char } hasp_local_style_attr(obj, attr, attr_hash, payload, update); - Log.trace(F("ATTR: %s (%d)took %d millis"), attr_p, attr_hash, millis() - start); + Log.trace(TAG_ATTR, F("%s (%d) took %d ms."), attr_p, attr_hash, millis() - start); } /* ************************** diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index f7bd53c7..12478ed7 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -28,9 +28,9 @@ void confDebugSet(const char * name) { /*char buffer[128]; - snprintf(buffer, sizeof(buffer), PSTR("CONF: * %s set"), name); + snprintf(buffer, sizeof(buffer), PSTR(" * %s set"), name); debugPrintln(buffer);*/ - Log.trace(F("CONF: * %s set"), name); + Log.trace(TAG_CONF, F(" * %s set"), name); } bool configSet(int8_t & value, const JsonVariant & setting, const char * name) @@ -75,15 +75,15 @@ void configStartDebug(bool setupdebug, String & configFile) if(setupdebug) { debugStart(); // Debug started, now we can use it; HASP header sent #if HASP_USE_SPIFFS > 0 - Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted")); + Log.notice(TAG_CONF, F("FILE: [SUCCESS] SPI flash FS mounted")); spiffsInfo(); spiffsList(); #endif } #if HASP_USE_SPIFFS > 0 - Log.notice(F("CONF: Loading %s"), configFile.c_str()); + Log.notice(TAG_CONF, F("Loading %s"), configFile.c_str()); #else - Log.notice(F("CONF: reading EEPROM")); + Log.notice(TAG_CONF, F("reading EEPROM")); #endif } @@ -100,7 +100,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) if(file) { size_t size = file.size(); if(size > 1024) { - Log.error(F("CONF: Config file size is too large")); + Log.error(TAG_CONF, F("Config file size is too large")); return; } @@ -121,8 +121,8 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) output.replace(settings[F("http")][F("pass")].as(), passmask); output.replace(settings[F("mqtt")][F("pass")].as(), passmask); output.replace(settings[F("wifi")][F("pass")].as(), passmask); - Log.verbose(F("CONF: %s"), output.c_str()); - Log.notice(F("CONF: [SUCCESS] Loaded %s"), configFile.c_str()); + Log.verbose(TAG_CONF, output.c_str()); + Log.notice(TAG_CONF, F("[SUCCESS] Loaded %s"), configFile.c_str()); if(setupdebug) debugSetup(); return; @@ -144,7 +144,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) configStartDebug(setupdebug, configFile); #if HASP_USE_SPIFFS > 0 - Log.error(F("CONF: Failed to load %s"), configFile.c_str()); + Log.error(TAG_CONF, F("Failed to load %s"), configFile.c_str()); #endif } /* @@ -172,7 +172,7 @@ void configBackupToEeprom() file.close(); EEPROM.commit(); - Log.verbose(F("CONF: Written %u to EEPROM"), index); + Log.verbose(TAG_CONF,F("Written %u to EEPROM"), index); } #endif } @@ -183,11 +183,15 @@ void configWriteConfig() configFile.reserve(128); configFile = String(FPSTR(HASP_CONFIG_FILE)); + String settingsChanged((char *)0); + settingsChanged.reserve(128); + settingsChanged = F("Settings changed!"); + /* Read Config File */ DynamicJsonDocument doc(8 * 256); - Log.notice(F("CONF: Config LOADING first %s"), configFile.c_str()); + Log.notice(TAG_CONF, F("Config LOADING first %s"), configFile.c_str()); configGetConfig(doc, false); - Log.trace(F("CONF: Config LOADED first %s"), configFile.c_str()); + Log.trace(TAG_CONF, F("Config LOADED first %s"), configFile.c_str()); // Make sure we have a valid JsonObject to start from JsonObject settings; @@ -204,7 +208,7 @@ void configWriteConfig() if(settings[F("wifi")].as().isNull()) settings.createNestedObject(F("wifi")); changed = wifiGetConfig(settings[F("wifi")]); if(changed) { - Log.verbose(F("WIFI: Settings changed")); + Log.verbose(TAG_WIFI, settingsChanged.c_str()); writefile = true; } #endif @@ -212,7 +216,7 @@ void configWriteConfig() if(settings[F("mqtt")].as().isNull()) settings.createNestedObject(F("mqtt")); changed = mqttGetConfig(settings[F("mqtt")]); if(changed) { - Log.verbose(F("MQTT: Settings changed")); + Log.verbose(TAG_MQTT, settingsChanged.c_str()); configOutput(settings[F("mqtt")]); writefile = true; } @@ -221,7 +225,7 @@ void configWriteConfig() if(settings[F("telnet")].as().isNull()) settings.createNestedObject(F("telnet")); changed = telnetGetConfig(settings[F("telnet")]); if(changed) { - Log.verbose(F("TELNET: Settings changed")); + Log.verbose(TAG_TELN, settingsChanged.c_str()); configOutput(settings[F("telnet")]); writefile = true; } @@ -230,7 +234,7 @@ void configWriteConfig() if(settings[F("mdns")].as().isNull()) settings.createNestedObject(F("mdns")); changed = mdnsGetConfig(settings[F("mdns")]); if(changed) { - Log.verbose(F("MDNS: Settings changed")); + Log.verbose(TAG_MDNS, settingsChanged.c_str()); writefile = true; } #endif @@ -238,7 +242,7 @@ void configWriteConfig() if(settings[F("http")].as().isNull()) settings.createNestedObject(F("http")); changed = httpGetConfig(settings[F("http")]); if(changed) { - Log.verbose(F("HTTP: Settings changed")); + Log.verbose(TAG_HTTP, settingsChanged.c_str()); configOutput(settings[F("http")]); writefile = true; } @@ -247,7 +251,7 @@ void configWriteConfig() if(settings[F("gpio")].as().isNull()) settings.createNestedObject(F("gpio")); changed = gpioGetConfig(settings[F("gpio")]); if(changed) { - Log.verbose(F("GPIO: Settings changed")); + Log.verbose(TAG_GPIO, settingsChanged.c_str()); configOutput(settings[F("gpio")]); writefile = true; } @@ -256,21 +260,21 @@ void configWriteConfig() if(settings[F("debug")].as().isNull()) settings.createNestedObject(F("debug")); changed = debugGetConfig(settings[F("debug")]); if(changed) { - Log.verbose(F("DEBUG: Settings changed")); + Log.verbose(TAG_DEBG, settingsChanged.c_str()); writefile = true; } if(settings[F("gui")].as().isNull()) settings.createNestedObject(F("gui")); changed = guiGetConfig(settings[F("gui")]); if(changed) { - Log.verbose(F("GUI: Settings changed")); + Log.verbose(TAG_GUI,settingsChanged.c_str()); writefile = true; } if(settings[F("hasp")].as().isNull()) settings.createNestedObject(F("hasp")); changed = haspGetConfig(settings[F("hasp")]); if(changed) { - Log.verbose(F("HASP: Settings changed")); + Log.verbose(TAG_HASP, settingsChanged.c_str()); writefile = true; } @@ -280,22 +284,22 @@ void configWriteConfig() #if HASP_USE_SPIFFS > 0 File file = SPIFFS.open(configFile, "w"); if(file) { - Log.notice(F("CONF: Writing %s"), configFile.c_str()); + Log.notice(TAG_CONF, F("Writing %s"), configFile.c_str()); size_t size = serializeJson(doc, file); file.close(); if(size > 0) { - Log.verbose(F("CONF: [SUCCESS] Saved %s"), configFile.c_str()); + Log.verbose(TAG_CONF, F("[SUCCESS] Saved %s"), configFile.c_str()); // configBackupToEeprom(); } else { - Log.error(F("CONF: Failed to write %s"), configFile.c_str()); + Log.error(TAG_CONF, F("Failed to write %s"), configFile.c_str()); } } else { - Log.error(F("CONF: Failed to write %s"), configFile.c_str()); + Log.error(TAG_CONF, F("Failed to write %s"), configFile.c_str()); } #endif // Method 1 - // Log.verbose(F("CONF: Writing to EEPROM")); + // Log.verbose(TAG_CONF,F("Writing to EEPROM")); // EepromStream eepromStream(0, 1024); // WriteBufferingStream bufferedWifiClient{eepromStream, 512}; // serializeJson(doc, bufferedWifiClient); @@ -304,7 +308,7 @@ void configWriteConfig() #if defined(STM32F4xx) // Method 2 - Log.verbose(F("CONF: Writing to EEPROM")); + Log.verbose(TAG_CONF, F("Writing to EEPROM")); char buffer[1024 + 128]; size_t size = serializeJson(doc, buffer, sizeof(buffer)); if(size > 0) { @@ -312,14 +316,14 @@ void configWriteConfig() for(i = 0; i < size; i++) eeprom_buffered_write_byte(i, buffer[i]); eeprom_buffered_write_byte(i, 0); eeprom_buffer_flush(); - Log.verbose(F("CONF: [SUCCESS] Saved EEPROM")); + Log.verbose(TAG_CONF, F("[SUCCESS] Saved EEPROM")); } else { - Log.error(F("CONF: Failed to save config to EEPROM")); + Log.error(TAG_CONF, F("Failed to save config to EEPROM")); } #endif } else { - Log.notice(F("CONF: Configuration did not change")); + Log.notice(TAG_CONF, F("Configuration did not change")); } configOutput(settings); } @@ -342,7 +346,7 @@ void configSetup() } else { #if HASP_USE_SPIFFS > 0 if(!SPIFFS.begin()) { - Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings...")); + Log.error(TAG_CONF, F("FILE: SPI flash init failed. Unable to mount FS: Using default settings...")); return; } #endif @@ -350,40 +354,40 @@ void configSetup() } //#if HASP_USE_SPIFFS > 0 - Log.verbose(F("Loading debug settings")); + Log.verbose(TAG_CONF, F("Loading debug settings")); debugSetConfig(settings[F("debug")]); - Log.verbose(F("Loading GUI settings")); + Log.verbose(TAG_CONF, F("Loading GUI settings")); guiSetConfig(settings[F("gui")]); - Log.verbose(F("Loading HASP settings")); + Log.verbose(TAG_CONF, F("Loading HASP settings")); haspSetConfig(settings[F("hasp")]); // otaGetConfig(settings[F("ota")]); #if HASP_USE_WIFI > 0 - Log.verbose(F("Loading WiFi settings")); + Log.verbose(TAG_CONF, F("Loading WiFi settings")); wifiSetConfig(settings[F("wifi")]); #endif #if HASP_USE_MQTT > 0 - Log.verbose(F("Loading MQTT settings")); + Log.verbose(TAG_CONF, F("Loading MQTT settings")); mqttSetConfig(settings[F("mqtt")]); #endif #if HASP_USE_TELNET > 0 - Log.verbose(F("Loading Telnet settings")); + Log.verbose(TAG_CONF, F("Loading Telnet settings")); telnetSetConfig(settings[F("telnet")]); #endif #if HASP_USE_MDNS > 0 - Log.verbose(F("Loading MDNS settings")); + Log.verbose(TAG_CONF, F("Loading MDNS settings")); mdnsSetConfig(settings[F("mdns")]); #endif #if HASP_USE_HTTP > 0 - Log.verbose(F("Loading HTTP settings")); + Log.verbose(TAG_CONF, F("Loading HTTP settings")); httpSetConfig(settings[F("http")]); #endif #if HASP_USE_GPIO > 0 - Log.verbose(F("Loading GPIO settings")); + Log.verbose(TAG_CONF, F("Loading GPIO settings")); gpioSetConfig(settings[F("gpio")]); #endif // } - Log.notice(F("User configuration loaded")); + Log.notice(TAG_CONF, F("User configuration loaded")); } //#endif } @@ -430,13 +434,13 @@ void configOutput(const JsonObject & settings) output.replace(password, passmask); } - Log.trace(F("CONF: %s"), output.c_str()); + Log.trace(TAG_CONF, output.c_str()); } bool configClear() { #if defined(STM32F4xx) - Log.verbose(F("CONF: Clearing EEPROM")); + Log.verbose(TAG_CONF, F("Clearing EEPROM")); char buffer[1024 + 128]; memset(buffer, 1, sizeof(buffer)); if(sizeof(buffer) > 0) { @@ -444,10 +448,10 @@ bool configClear() for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]); eeprom_buffered_write_byte(i, 0); eeprom_buffer_flush(); - Log.verbose(F("CONF: [SUCCESS] Cleared EEPROM")); + Log.verbose(TAG_CONF, F("[SUCCESS] Cleared EEPROM")); return true; } else { - Log.error(F("CONF: Failed to clear to EEPROM")); + Log.error(TAG_CONF, F("Failed to clear to EEPROM")); return false; } #elif HASP_USE_SPIFFS > 0 diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index ea992d35..c13e523c 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -56,7 +56,7 @@ // static String debugOutput((char *)0); // static StringStream debugStream((String &)debugOutput); -extern char mqttNodeName[16]; +// extern char mqttNodeName[16]; const char * syslogAppName = APP_NAME; char debugSyslogHost[32] = SYSLOG_SERVER; uint16_t debugSyslogPort = SYSLOG_PORT; @@ -64,12 +64,13 @@ uint8_t debugSyslogFacility = 0; uint8_t debugSyslogProtocol = 0; // A UDP instance to let us send and receive packets over UDP -WiFiUDP syslogClient; +WiFiUDP * syslogClient; +#define SYSLOG_PROTO_IETF 0 // Create a new syslog instance with LOG_KERN facility // Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN); // Create a new empty syslog instance -Syslog * syslog; +// Syslog * syslog; #endif // USE_SYSLOG // Serial Settings @@ -116,33 +117,43 @@ void debugStart() { if(debugSerialStarted) { Serial.flush(); - Serial.println(); - Serial.println(debugHaspHeader()); - Serial.flush(); + // Serial.println(); + // Serial.println(debugHaspHeader()); + // Serial.flush(); } // prepare syslog configuration here (can be anywhere before first call of // log/logf method) } -#if HASP_USE_SYSLOG > 0 -void syslogSend(uint8_t priority, const char * debugText) -{ - if(strlen(debugSyslogHost) != 0 && WiFi.isConnected()) { - syslog->log(priority, debugText); - } -} -#endif +// #if HASP_USE_SYSLOG > 0 +// void syslogSend(uint8_t priority, const char * debugText) +// { +// if(strlen(debugSyslogHost) != 0 && WiFi.isConnected()) { +// syslog->log(priority, debugText); +// } +// } +// #endif void debugSetup() { #if HASP_USE_SYSLOG > 0 - syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD); - syslog->server(debugSyslogHost, debugSyslogPort); - syslog->deviceHostname(mqttNodeName); - syslog->appName(syslogAppName); - uint16_t priority = (uint16_t)(debugSyslogFacility + 16) << 3; // localx facility, x = 0-7 - syslog->defaultPriority(priority); + // syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD); + // syslog->server(debugSyslogHost, debugSyslogPort); + // syslog->deviceHostname(mqttNodeName); + // syslog->appName(syslogAppName); + // uint16_t priority = (uint16_t)(debugSyslogFacility + 16) << 3; // localx facility, x = 0-7 + // syslog->defaultPriority(priority); + + if(strlen(debugSyslogHost) > 0) { + syslogClient = new WiFiUDP(); + if(syslogClient) { + syslogClient->beginPacket(debugSyslogHost, debugSyslogPort); + { + Log.registerOutput(2, syslogClient, LOG_LEVEL_VERBOSE, true); + } + } + } #endif } @@ -307,17 +318,149 @@ static void debugPrintPriority(int level, Print * _logOutput) } } -void debugPrintPrefix(int level, Print * _logOutput) +static void debugPrintTag(uint8_t tag, Print * _logOutput) { + switch(tag) { + case TAG_MAIN: + _logOutput->print(F("MAIN")); + break; + + case TAG_HASP: + _logOutput->print(F("HASP")); + break; + + case TAG_ATTR: + _logOutput->print(F("ATTR")); + break; + + case TAG_MSGR: + _logOutput->print(F("MSGR")); + break; + + case TAG_OOBE: + _logOutput->print(F("OOBE")); + break; + case TAG_HAL: + _logOutput->print(F("HAL ")); + break; + + case TAG_DEBG: + _logOutput->print(F("DEBG")); + break; + case TAG_TELN: + _logOutput->print(F("TELN")); + break; + case TAG_SYSL: + _logOutput->print(F("SYSL")); + break; + case TAG_TASM: + _logOutput->print(F("TASM")); + break; + + case TAG_CONF: + _logOutput->print(F("CONF")); + break; + case TAG_GUI: + _logOutput->print(F("GUI ")); + break; + case TAG_TFT: + _logOutput->print(F("TFT ")); + break; + + case TAG_EPRM: + _logOutput->print(F("EPRM")); + break; + case TAG_FILE: + _logOutput->print(F("FILE")); + break; + case TAG_GPIO: + _logOutput->print(F("GPIO")); + break; + + case TAG_ETH: + _logOutput->print(F("ETH ")); + break; + case TAG_WIFI: + _logOutput->print(F("WIFI")); + break; + case TAG_HTTP: + _logOutput->print(F("HTTP")); + break; + case TAG_MDNS: + _logOutput->print(F("MDNS")); + break; + case TAG_MQTT: + _logOutput->print(F("MQTT")); + break; + case TAG_MQTT_PUB: + _logOutput->print(F("MQTT PUB")); + break; + case TAG_MQTT_RCV: + _logOutput->print(F("MQTT RCV")); + break; + + case TAG_OTA: + _logOutput->print(F("OTA")); + break; + case TAG_FWUP: + _logOutput->print(F("FWUP")); + break; + + case TAG_LVGL: + _logOutput->print(F("LVGL")); + break; + case TAG_LVFS: + _logOutput->print(F("LVFS")); + break; + case TAG_FONT: + _logOutput->print(F("FONT")); + break; + + default: + _logOutput->print(F("----")); + break; + } +} + +void debugPrintPrefix(uint8_t tag, int level, Print * _logOutput) +{ + if(_logOutput == syslogClient) { + syslogClient->beginPacket(); + + // IETF Doc: https://tools.ietf.org/html/rfc5424 - The Syslog Protocol + // BSD Doc: https://tools.ietf.org/html/rfc3164 - The BSD syslog Protocol + + syslogClient->print('<'); + syslogClient->print((16 + debugSyslogFacility) * 8 + level); + syslogClient->print('>'); + + if(debugSyslogProtocol == SYSLOG_PROTO_IETF) { + syslogClient->print(F("1 - ")); + } + + syslogClient->print(mqttGetNodename()); + syslogClient->print(' '); + syslogClient->print(syslogAppName); + + if(debugSyslogProtocol == SYSLOG_PROTO_IETF) { + syslogClient->print(F(" - - - \xEF\xBB\xBF")); // include UTF-8 BOM + } else { + syslogClient->print(F(": ")); + } + } + debugPrintTimestamp(level, _logOutput); debugPrintHaspMemory(level, _logOutput); #if LV_MEM_CUSTOM == 0 debugPrintLvglMemory(level, _logOutput); #endif debugPrintPriority(level, _logOutput); + _logOutput->print(F(" ")); + debugPrintTag(tag, _logOutput); + _logOutput->print(F(": ")); } -void debugPrintSuffix(int level, Print * _logOutput) +void debugPrintSuffix(uint8_t tag, int level, Print * _logOutput) { if(debugAnsiCodes) _logOutput->println(F(TERM_COLOR_RESET)); @@ -325,6 +468,10 @@ void debugPrintSuffix(int level, Print * _logOutput) _logOutput->println(); if(debugAnsiCodes) _logOutput->print(F(TERM_COLOR_MAGENTA)); + if(_logOutput == syslogClient && strlen(debugSyslogHost) > 0) { + syslogClient->endPacket(); + } + // syslogSend(level, debugOutput); } @@ -351,8 +498,14 @@ void debugPreSetup(JsonObject settings) delay(10); Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true); debugSerialStarted = true; + + // Print Header Serial.println(); - Log.trace(("Serial started at %u baud"), baudrate); + Serial.println(debugHaspHeader()); + Serial.println(); + Serial.flush(); + + Log.trace(TAG_DEBG, ("Serial started at %u baud"), baudrate); } } @@ -368,16 +521,16 @@ void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const cha if(line != lastDbgLine || mem_mon.free_biggest_size != lastDbgFree) { switch(level) { case LV_LOG_LEVEL_TRACE: - Log.trace(descr); + Log.trace(TAG_LVGL, descr); break; case LV_LOG_LEVEL_WARN: - Log.warning(descr); + Log.warning(TAG_LVGL, descr); break; case LV_LOG_LEVEL_ERROR: - Log.error(descr); + Log.error(TAG_LVGL, descr); break; default: - Log.notice(descr); + Log.notice(TAG_LVGL, descr); } lastDbgLine = line; lastDbgFree = mem_mon.free_biggest_size; diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 72a3c0a8..622d61fd 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -4,6 +4,43 @@ #include "ArduinoJson.h" #include "lvgl.h" +enum { + TAG_MAIN = 0, + TAG_HASP = 1, + TAG_ATTR = 2, + TAG_MSGR = 3, + TAG_OOBE = 4, + TAG_HAL = 5, + + TAG_DEBG = 10, + TAG_TELN = 11, + TAG_SYSL = 12, + TAG_TASM = 13, + + TAG_CONF = 20, + TAG_GUI = 21, + TAG_TFT = 22, + + TAG_EPRM = 30, + TAG_FILE = 31, + TAG_GPIO = 40, + + TAG_FWUP = 50, + + TAG_ETH = 60, + TAG_WIFI = 61, + TAG_HTTP = 62, + TAG_OTA = 63, + TAG_MDNS = 64, + TAG_MQTT = 65, + TAG_MQTT_PUB = 66, + TAG_MQTT_RCV = 67, + + TAG_LVGL = 90, + TAG_LVFS = 91, + TAG_FONT = 92 +}; + String debugHaspHeader(void); void debugPreSetup(JsonObject settings); diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp index 6a474ca7..d7cd1351 100644 --- a/src/hasp_dispatch.cpp +++ b/src/hasp_dispatch.cpp @@ -54,7 +54,7 @@ void dispatchGpioOutput(int output, bool state) int pin = 0; if(pin >= 0) { - Log.notice(F("PIN OUTPUT STATE %d"), state); + Log.notice(TAG_MSGR,F("PIN OUTPUT STATE %d"), state); #if defined(ARDUINO_ARCH_ESP32) ledcWrite(99, state ? 1023 : 0); // ledChannel and value @@ -89,7 +89,7 @@ void dispatchParseJson(char * payload) // haspCommands.shrinkToFit(); if(jsonError) { // Couldn't parse incoming JSON command - Log.warning(F("JSON: Failed to parse incoming JSON command with error: %s"), jsonError.c_str()); + Log.warning(TAG_MSGR,F("JSON: Failed to parse incoming JSON command with error: %s"), jsonError.c_str()); } else { JsonArray arr = haspCommands.as(); @@ -104,7 +104,7 @@ void dispatchParseJsonl(Stream & stream) DynamicJsonDocument jsonl(3 * 128u); uint8_t savedPage = haspGetPage(); - // Log.notice(F("DISPATCH: jsonl")); + // Log.notice(TAG_MSGR,F("DISPATCH: jsonl")); while(deserializeJson(jsonl, stream) == DeserializationError::Ok) { // serializeJson(jsonl, Serial); @@ -122,7 +122,7 @@ void dispatchParseJsonl(char * payload) // p[x].b[y]=value inline void dispatch_process_button_attribute(String strTopic, const char * payload) { - // Log.trace(F("BTN ATTR: %s = %s"), strTopic.c_str(), payload); + // Log.trace(TAG_MSGR,F("BTN ATTR: %s = %s"), strTopic.c_str(), payload); String strPageId((char *)0); String strTemp((char *)0); @@ -219,7 +219,7 @@ void dispatchCommand(const char * topic, const char * payload) if(strlen(payload) == 0) { // dispatchTextLine(topic); // Could cause an infinite loop! } - Log.warning(F(LOG_CMND_CTR "Command not found %s => %s"), topic, payload); + Log.warning(TAG_MSGR,F(LOG_CMND_CTR "Command not found %s => %s"), topic, payload); } } @@ -297,7 +297,7 @@ void dispatchBacklight(const char * payload) // Strip command/config prefix from the topic and process the payload void dispatchTopicPayload(const char * topic, const char * payload) { - // Log.trace(F("TOPIC: short topic: %s"), topic); + // Log.trace(TAG_MSGR,F("TOPIC: short topic: %s"), topic); if(!strcmp_P(topic, PSTR("command"))) { dispatchTextLine((char *)payload); @@ -306,7 +306,7 @@ void dispatchTopicPayload(const char * topic, const char * payload) if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/ topic += 8u; - // Log.trace(F("MQTT IN: command subtopic: %s"), topic); + // Log.trace(TAG_MSGR,F("MQTT IN: command subtopic: %s"), topic); // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' == // nextionSetAttr("p[1].b[4].txt", "\"Lights On\"") @@ -373,7 +373,7 @@ void dispatchTextLine(const char * cmnd) void dispatch_output_idle_state(const char * state) { #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) - Log.notice(F("OUT: idle = %s"), state); + Log.notice(TAG_MSGR,F("idle = %s"), state); #else #if HASP_USE_MQTT > 0 @@ -398,8 +398,8 @@ void dispatchReboot(bool saveConfig) #if HASP_USE_WIFI > 0 wifiStop(); #endif - Log.verbose(F("-------------------------------------")); - Log.notice(F("STOP: Properly Rebooting the MCU now!")); + Log.verbose(TAG_MSGR,F("-------------------------------------")); + Log.notice(TAG_MSGR,F("STOP: Properly Rebooting the MCU now!")); Serial.flush(); halRestart(); } @@ -407,7 +407,7 @@ void dispatchReboot(bool saveConfig) void dispatch_button(uint8_t id, const char * event) { #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) - Log.notice(F("OUT: input%d = %s"), id, event); + Log.notice(TAG_MSGR,F("input%d = %s"), id, event); #else #if HASP_USE_MQTT > 0 mqtt_send_input(id, event); @@ -477,7 +477,7 @@ void dispatch_send_group_event(uint8_t groupid, uint8_t eventid, bool update_has // send out value #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) - Log.notice(F("OUT: group%d = %s"), groupid, eventid); + Log.notice(TAG_MSGR,F("group%d = %s"), groupid, eventid); #else #if HASP_USE_MQTT > 0 // mqtt_send_input(id, event); @@ -494,7 +494,7 @@ void dispatch_send_group_event(uint8_t groupid, uint8_t eventid, bool update_has void IRAM_ATTR dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) { #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) - Log.notice(F("OUT: json = {\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data); + Log.notice(TAG_MSGR,F("json = {\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data); #else #if HASP_USE_MQTT > 0 mqtt_send_obj_attribute_str(pageid, btnid, attribute, data); @@ -520,7 +520,7 @@ void dispatch_send_object_event(uint8_t pageid, uint8_t objid, uint8_t eventid) void dispatchWebUpdate(const char * espOtaUrl) { #if HASP_USE_OTA > 0 - Log.verbose(F("FWUP: Checking for updates at URL: %s"), espOtaUrl); + Log.verbose(TAG_MSGR,F("Checking for updates at URL: %s"), espOtaUrl); otaHttpUpdate(espOtaUrl); #endif } @@ -529,7 +529,7 @@ void dispatchWebUpdate(const char * espOtaUrl) void IRAM_ATTR dispatch_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) { #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) - Log.notice(F("OUT: json = {\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data); + Log.notice(TAG_MSGR,F("json = {\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data); #else #if HASP_USE_MQTT > 0 mqtt_send_obj_attribute_str(pageid, btnid, attribute, data); @@ -556,7 +556,7 @@ void dispatchConfig(const char * topic, const char * payload) } else { DeserializationError jsonError = deserializeJson(doc, payload); if(jsonError) { // Couldn't parse incoming JSON command - Log.warning(F("JSON: Failed to parse incoming JSON command with error: %s"), jsonError.c_str()); + Log.warning(TAG_MSGR,F("JSON: Failed to parse incoming JSON command with error: %s"), jsonError.c_str()); return; } settings = doc.as(); @@ -626,7 +626,7 @@ void dispatchConfig(const char * topic, const char * payload) settings.remove(F("pass")); // hide password in output size_t size = serializeJson(doc, buffer, sizeof(buffer)); #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) - Log.notice(F("OUT: config %s = %s"), topic, buffer); + Log.notice(TAG_MSGR,F("config %s = %s"), topic, buffer); #else #if HASP_USE_MQTT > 0 mqtt_send_state(F("config"), buffer); diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp index 073de7b1..548f5271 100644 --- a/src/hasp_ethernet.cpp +++ b/src/hasp_ethernet.cpp @@ -13,15 +13,15 @@ void ethernetSetup() { #if USE_BUILTIN_ETHERNET > 0 // start Ethernet and UDP - Log.notice(F("ETH: Begin Ethernet LAN8720")); + Log.notice(TAG_ETH, F("Begin Ethernet LAN8720")); if(Ethernet.begin() == 0) { - Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); + Log.notice(TAG_ETH, F("Failed to configure Ethernet using DHCP")); } else { ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_ETH, F("DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); } - Log.notice(F("ETH: MAC Address %s"), halGetMacAddress(0, ":")); + Log.notice(TAG_ETH, F("MAC Address %s"), halGetMacAddress(0, ":")); #else byte mac[6]; @@ -34,18 +34,18 @@ void ethernetSetup() mac[5] = (baseUID & 0x000000FF); char ethHostname[12]; - memset(ethHostname, 0 ,sizeof(ethHostname)); + memset(ethHostname, 0, sizeof(ethHostname)); snprintf(ethHostname, sizeof(ethHostname), PSTR("HASP-%02x%02x%02x"), mac[3], mac[4], mac[5]); Ethernet.setCsPin(W5500_CS); Ethernet.setRstPin(W5500_RST); Ethernet.setHostname(ethHostname); - Log.notice(F("ETH: Begin Ethernet W5500")); + Log.notice(TAG_ETH, F("Begin Ethernet W5500")); if(Ethernet.begin(mac) == 0) { - Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); + Log.notice(TAG_ETH, F("Failed to configure Ethernet using DHCP")); } else { ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_ETH, F("DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); } #endif } @@ -55,24 +55,24 @@ void ethernetLoop(void) switch(Ethernet.maintain()) { case 1: // renewed fail - Log.notice(F("ETH: Error: renewed fail")); + Log.notice(TAG_ETH, F("Error: renewed fail")); break; case 2: // renewed success ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Renew Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_ETH, F("DHCP Renew Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); break; case 3: // rebind fail - Log.notice(F("Error: rebind fail")); + Log.notice(TAG_ETH, F("Error: rebind fail")); break; case 4: // rebind success ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Rebind Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_ETH, F("DHCP Rebind Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); break; default: @@ -89,7 +89,7 @@ bool ethernetEvery5Seconds() #else state = Ethernet.link() == 1; #endif - Log.warning(F("ETH: %s"), state ? F("ONLINE") : F("OFFLINE")); + Log.warning(TAG_ETH, state ? F("ONLINE") : F("OFFLINE")); return state; } diff --git a/src/hasp_ethernet_esp32.cpp b/src/hasp_ethernet_esp32.cpp index ede1a636..85fa2eb1 100644 --- a/src/hasp_ethernet_esp32.cpp +++ b/src/hasp_ethernet_esp32.cpp @@ -10,36 +10,36 @@ IPAddress ip; void EthernetEvent(WiFiEvent_t event) { - switch (event) { - case SYSTEM_EVENT_ETH_START: - Log.notice(F(LOG_ETH_CTR "Started")); - //set eth hostname here - ETH.setHostname("esp32-ethernet"); - break; - case SYSTEM_EVENT_ETH_CONNECTED: - Log.notice(F(LOG_ETH_CTR "Connected")); - break; - case SYSTEM_EVENT_ETH_GOT_IP: - Log.notice(F(LOG_ETH_CTR "MAC Address %s"), ETH.macAddress().c_str()); - ip = ETH.localIP(); - Log.notice(F(LOG_ETH_CTR "IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - if (ETH.fullDuplex()) { - Log.notice(F(LOG_ETH_CTR "FULL_DUPLEX")); - } - Log.notice(F(LOG_ETH_CTR "LINK_SPEED %d Mbps"), ETH.linkSpeed()); - eth_connected = true; - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - Log.notice(F(LOG_ETH_CTR "Disconnected")); - eth_connected = false; - break; - case SYSTEM_EVENT_ETH_STOP: - Log.notice(F(LOG_ETH_CTR "Stopped")); - eth_connected = false; - break; - default: - break; - } + switch(event) { + case SYSTEM_EVENT_ETH_START: + Log.notice(TAG_ETH, F("Started")); + // set eth hostname here + ETH.setHostname("esp32-ethernet"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + Log.notice(TAG_ETH, F("Connected")); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + Log.notice(TAG_ETH, F("MAC Address %s"), ETH.macAddress().c_str()); + ip = ETH.localIP(); + Log.notice(TAG_ETH, F("IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + if(ETH.fullDuplex()) { + Log.notice(TAG_ETH, F("FULL_DUPLEX")); + } + Log.notice(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed()); + eth_connected = true; + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + Log.notice(TAG_ETH, F("Disconnected")); + eth_connected = false; + break; + case SYSTEM_EVENT_ETH_STOP: + Log.notice(TAG_ETH, F("Stopped")); + eth_connected = false; + break; + default: + break; + } } void ethernetSetup() @@ -48,17 +48,15 @@ void ethernetSetup() ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE); } - void ethernetLoop(void) { -// + // } bool ethernetEvery5Seconds() { - Log.warning(F(LOG_ETH_CTR "%s"), eth_connected ? F("ONLINE") : F("OFFLINE")); + Log.warning(TAG_ETH, eth_connected ? F("ONLINE") : F("OFFLINE")); return eth_connected; } - #endif \ No newline at end of file diff --git a/src/hasp_ethernet_esp32.h b/src/hasp_ethernet_esp32.h index ed45e9ea..becd6a60 100644 --- a/src/hasp_ethernet_esp32.h +++ b/src/hasp_ethernet_esp32.h @@ -1,8 +1,6 @@ #ifndef HASP_ETHERNET_ESP32_H #define HASP_ETHERNET_ESP32_H -#define LOG_ETH_CTR "ETH: " - static bool eth_connected = false; void ethernetSetup(); diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp index 62071069..cd96e50c 100644 --- a/src/hasp_gpio.cpp +++ b/src/hasp_gpio.cpp @@ -131,14 +131,14 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8 buttonConfig->clearFeature( ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses - Log.verbose(F("GPIO: Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, + Log.verbose(TAG_GPIO,F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, input_mode, default_state); gpioUsedInputCount = i + 1; return; } } } - Log.error(F("GPIO: Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index, + Log.error(TAG_GPIO,F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index, HASP_NUM_INPUTS); } @@ -162,14 +162,14 @@ void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, buttonConfig->clearFeature( ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses - Log.verbose(F("GPIO: Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, + Log.verbose(TAG_GPIO,F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index, input_mode, default_state); gpioUsedInputCount = i + 1; return; } } } - Log.error(F("GPIO: Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index, + Log.error(TAG_GPIO,F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index, HASP_NUM_INPUTS); } @@ -417,7 +417,7 @@ bool gpioSavePinConfig(uint8_t config_num, uint8_t pin, uint8_t type, uint8_t gr gpioConfig[config_num].type = type; gpioConfig[config_num].group = group; gpioConfig[config_num].gpio_function = pinfunc; - Log.notice(F("GPIO: Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type, group, + Log.notice(TAG_GPIO,F("Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type, group, pinfunc); return true; } @@ -573,7 +573,7 @@ bool gpioGetConfig(const JsonObject & settings) if(i < HASP_NUM_GPIO_CONFIG) { uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) | (gpioConfig[i].gpio_function << 24); - Log.verbose(F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as()); + Log.verbose(TAG_GPIO,F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as()); if(cur_val != v.as()) changed = true; v.set(cur_val); diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 337d5357..324ad679 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -223,7 +223,7 @@ static void ICACHE_RAM_ATTR lv_tick_handler(void) // data->point.x = touchX; // 20 + (disp->driver.hor_res - 40) * (touchCorner % 2); // data->point.y = touchY; // 20 + (disp->driver.ver_res - 40) * (touchCorner / 2); -// Log.trace(F("Calibrate touch %u / %u"), touchX, touchY); +// Log.trace(TAG_GUI,F("Calibrate touch %u / %u"), touchX, touchY); // #endif @@ -301,9 +301,9 @@ void handleTouch(int8_t contacts, GTPoint * points) GT911_num_touches = contacts; GT911_points = points; - Log.trace("Contacts: %d", contacts); + Log.trace(TAG_GUI,"Contacts: %d", contacts); for(uint8_t i = 0; i < contacts; i++) { - Log.trace("C%d: #%d %d,%d s:%d", i, points[i].trackId, points[i].x, points[i].y, points[i].area); + Log.trace(TAG_GUI,"C%d: #%d %d,%d s:%d", i, points[i].trackId, points[i].x, points[i].y, points[i].area); yield(); } } @@ -378,7 +378,7 @@ void GT911_setup() touch.setHandler(handleTouch); touchStart(); - Log.verbose(F("Goodix GT911x touch driver started")); + Log.verbose(TAG_GUI,F("Goodix GT911x touch driver started")); } #endif @@ -513,16 +513,16 @@ void guiSetup() /* Dump TFT Configuration */ // tftSetup(tft); #ifdef USE_DMA_TO_TFT - Log.verbose(F("TFT: DMA : ENABLED")); + Log.verbose(TAG_GUI,F("DMA : ENABLED")); #else - Log.verbose(F("TFT: DMA : DISABLED")); + Log.verbose(TAG_GUI,F("DMA : DISABLED")); #endif /* Load User Settings */ // guiSetConfig(settings); /* Setup Backlight Control Pin */ if(guiBacklightPin >= 0) { - Log.verbose(F("LVGL: Backlight: Pin %d"), guiBacklightPin); + Log.verbose(TAG_LVGL,F("Backlight: Pin %d"), guiBacklightPin); #if defined(ARDUINO_ARCH_ESP32) // pinMode(guiBacklightPin, OUTPUT); @@ -535,16 +535,16 @@ void guiSetup() #endif } - Log.verbose(F("LVGL: Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH, + Log.verbose(TAG_LVGL,F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH, PSTR(LVGL_VERSION_INFO)); - Log.verbose(F("LVGL: Rotation : %d"), guiRotation); + Log.verbose(TAG_LVGL,F("Rotation : %d"), guiRotation); #ifdef LV_MEM_SIZE - Log.verbose(F("LVGL: MEM size : %d"), LV_MEM_SIZE); + Log.verbose(TAG_LVGL,F("MEM size : %d"), LV_MEM_SIZE); #endif - Log.verbose(F("LVGL: VFB size : %d"), (size_t)sizeof(lv_color_t) * guiVDBsize); + Log.verbose(TAG_LVGL,F("VFB size : %d"), (size_t)sizeof(lv_color_t) * guiVDBsize); #if LV_USE_LOG != 0 - Log.verbose(F("LVGL: Registering lvgl logging handler")); + Log.verbose(TAG_LVGL,F("Registering lvgl logging handler")); lv_log_register_print_cb(debugLvgl); /* register print function for debugging */ #endif @@ -621,7 +621,7 @@ void guiSetup() */ /* Initialize mouse pointer */ /*// if(true) { - debugPrintln(PSTR("LVGL: Initialize Cursor")); + debugPrintln(PSTR("Initialize Cursor")); lv_obj_t * cursor; lv_obj_t * mouse_layer = lv_disp_get_layer_sys(NULL); // default display // cursor = lv_obj_create(lv_scr_act(), NULL); @@ -746,7 +746,7 @@ bool guiGetConfig(const JsonObject & settings) JsonArray array = settings[FPSTR(F_GUI_CALIBRATION)].as(); uint8_t i = 0; for(JsonVariant v : array) { - Log.verbose(F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as()); + Log.verbose(TAG_GUI,F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as()); if(i < 5) { if(calData[i] != v.as()) changed = true; v.set(calData[i]); @@ -798,7 +798,7 @@ bool guiSetConfig(const JsonObject & settings) if(!settings[FPSTR(F_GUI_POINTER)].isNull()) { if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as()) { - Log.trace(F("guiShowPointer set")); + Log.trace(TAG_GUI,F("guiShowPointer set")); } changed |= guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as(); @@ -819,11 +819,11 @@ bool guiSetConfig(const JsonObject & settings) } if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) { - Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3], + Log.trace(TAG_GUI,F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3], calData[4]); oobeSetAutoCalibrate(false); } else { - Log.notice(F("First Touch Calibration enabled")); + Log.notice(TAG_GUI,F("First Touch Calibration enabled")); oobeSetAutoCalibrate(true); } @@ -900,7 +900,7 @@ static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize) void gui_flush_not_complete() { - Log.warning(F("GUI: Pixelbuffer not completely sent")); + Log.warning(TAG_GUI,F("GUI: Pixelbuffer not completely sent")); } #endif // HASP_USE_SPIFFS > 0 || HASP_USE_HTTP > 0 @@ -934,7 +934,7 @@ void guiTakeScreenshot(const char * pFileName) size_t len = pFileOut.write(buffer, 122); if(len == 122) { - Log.verbose(F("GUI: Bitmap header written")); + Log.verbose(TAG_GUI,F("GUI: Bitmap header written")); /* Refresh screen to screenshot callback */ lv_disp_t * disp = lv_disp_get_default(); @@ -945,15 +945,15 @@ void guiTakeScreenshot(const char * pFileName) lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */ disp->driver.flush_cb = flush_cb; /* restore callback */ - Log.verbose(F("GUI: Birmap data flushed to %s"), pFileName); + Log.verbose(TAG_GUI,F("GUI: Bitmap data flushed to %s"), pFileName); } else { - Log.error(F("GUI: Data written does not match header size")); + Log.error(TAG_GUI,F("GUI: Data written does not match header size")); } pFileOut.close(); } else { - Log.warning(F("GUI: %s cannot be opened"), pFileName); + Log.warning(TAG_GUI,F("GUI: %s cannot be opened"), pFileName); } } #endif @@ -982,7 +982,7 @@ void guiTakeScreenshot() gui_get_bitmap_header(buffer, sizeof(buffer)); if(httpClientWrite(buffer, 122) == 122) { - Log.verbose(F("GUI: Bitmap header sent")); + Log.verbose(TAG_GUI,F("GUI: Bitmap header sent")); /* Refresh screen to screenshot callback */ lv_disp_t * disp = lv_disp_get_default(); @@ -993,9 +993,9 @@ void guiTakeScreenshot() lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */ disp->driver.flush_cb = flush_cb; /* restore callback */ - Log.verbose(F("GUI: Bitmap data flushed to webclient")); + Log.verbose(TAG_GUI,F("GUI: Bitmap data flushed to webclient")); } else { - Log.error(F("GUI: Data sent does not match header size")); + Log.error(TAG_GUI,F("GUI: Data sent does not match header size")); } } #endif \ No newline at end of file diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index 51cb24c7..a21fe141 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -140,10 +140,10 @@ bool httpIsAuthenticated(const __FlashStringHelper * page) } #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, + Log.verbose(TAG_HTTP, F("Sending %s page to client connected from: %s"), page, webServer.client().remoteIP().toString().c_str()); #else - // Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, + // Log.verbose(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, // String(webServer.client().remoteIP()).c_str()); #endif @@ -200,7 +200,7 @@ void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false) contentLength += sizeof(HTTP_FOOTER) - 1; if(httpdatalength > HTTP_PAGE_SIZE) { - Log.warning(F("HTTP: Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength); + Log.warning(TAG_HTTP, F("Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength); } webServer.setContentLength(contentLength + httpdatalength); @@ -329,12 +329,17 @@ void webHandleScreenshot() httpMessage += F("
"); httpMessage += - F(""); - httpMessage += F("

"); - httpMessage += F( - "

"); - httpMessage += F("

"); + httpMessage += F("

"); httpMessage += F("

"); @@ -628,7 +633,7 @@ void webUploadProgress() { long t = webServer.header("Content-Length").toInt(); if(millis() - htppLastLoopTime >= 1250) { - Log.verbose(F(" * Uploaded %u bytes / %d"), upload->totalSize + upload->currentSize, t); + Log.verbose(TAG_HTTP, F(" * Uploaded %u bytes / %d"), upload->totalSize + upload->currentSize, t); htppLastLoopTime = millis(); } if(t > 0) t = (upload->totalSize + upload->currentSize) * 100 / t; @@ -642,13 +647,13 @@ void webUpdatePrintError() output.reserve(128); StringStream stream((String &)output); Update.printError(stream); - Log.error(F("HTTP: %s"), output.c_str()); + Log.error(TAG_HTTP, output.c_str()); haspProgressMsg(output.c_str()); } void webUpdateReboot() { - Log.notice(F("Update Success: %u bytes received. Rebooting..."), upload->totalSize); + Log.notice(TAG_HTTP, F("Update Success: %u bytes received. Rebooting..."), upload->totalSize); { String httpMessage((char *)0); @@ -674,7 +679,7 @@ void webHandleFirmwareUpdate() upload = &webServer.upload(); if(upload->status == UPLOAD_FILE_START) { if(!httpIsAuthenticated(F("update"))) return; - Log.notice(F("Update: %s"), upload->filename.c_str()); + Log.notice(TAG_HTTP, F("Update: %s"), upload->filename.c_str()); haspProgressMsg(upload->filename.c_str()); // WiFiUDP::stopAll(); uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; @@ -732,7 +737,7 @@ void handleFileUpload() upload = &webServer.upload(); if(upload->status == UPLOAD_FILE_START) { if(!httpIsAuthenticated(F("fileupload"))) return; - Log.verbose(F("Total size: %s"), webServer.headerName(0).c_str()); + Log.verbose(TAG_HTTP, F("Total size: %s"), webServer.headerName(0).c_str()); String filename((char *)0); filename.reserve(128); filename = upload->filename; @@ -742,23 +747,23 @@ void handleFileUpload() } if(filename.length() < 32) { fsUploadFile = filesystem->open(filename, "w"); - Log.notice(F("handleFileUpload Name: %s"), filename.c_str()); + Log.notice(TAG_HTTP, F("handleFileUpload Name: %s"), filename.c_str()); haspProgressMsg(fsUploadFile.name()); } else { - Log.error(F("Filename %s is too long"), filename.c_str()); + Log.error(TAG_HTTP, F("Filename %s is too long"), filename.c_str()); } } else if(upload->status == UPLOAD_FILE_WRITE) { // DBG_OUTPUT_PORT.print("handleFileUpload Data: "); debugPrintln(upload.currentSize); if(fsUploadFile) { if(fsUploadFile.write(upload->buf, upload->currentSize) != upload->currentSize) { - Log.error(F("HTTP: Failed to write received data to file")); + Log.error(TAG_HTTP, F("Failed to write received data to file")); } else { webUploadProgress(); // Moved to httpEverySecond Loop } } } else if(upload->status == UPLOAD_FILE_END) { if(fsUploadFile) { - Log.verbose(F("Uploaded %s (%u bytes)"), fsUploadFile.name(), upload->totalSize); + Log.verbose(TAG_HTTP, F("Uploaded %s (%u bytes)"), fsUploadFile.name(), upload->totalSize); fsUploadFile.close(); } haspProgressVal(255); @@ -781,7 +786,7 @@ void handleFileDelete() return webServer.send_P(500, mimetype, PSTR("BAD ARGS")); } String path = webServer.arg(0); - Log.verbose(F("handleFileDelete: %s"), path.c_str()); + Log.verbose(TAG_HTTP, F("handleFileDelete: %s"), path.c_str()); if(path == "/") { return webServer.send_P(500, mimetype, PSTR("BAD PATH")); } @@ -801,7 +806,7 @@ void handleFileCreate() return webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS")); } String path = webServer.arg(0); - Log.verbose(F("handleFileCreate: %s"), path.c_str()); + Log.verbose(TAG_HTTP, F("handleFileCreate: %s"), path.c_str()); if(path == "/") { return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH")); } @@ -828,7 +833,7 @@ void handleFileList() } String path = webServer.arg(F("dir")); - Log.verbose(F("handleFileList: %s"), path.c_str()); + Log.verbose(TAG_HTTP, F("handleFileList: %s"), path.c_str()); path.clear(); #if defined(ARDUINO_ARCH_ESP32) @@ -1543,9 +1548,10 @@ void httpHandleNotFound() #endif #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - Log.notice(F("HTTP: Sending 404 to client connected from: %s"), webServer.client().remoteIP().toString().c_str()); + Log.notice(TAG_HTTP, F("Sending 404 to client connected from: %s"), + webServer.client().remoteIP().toString().c_str()); #else - // Log.notice(F("HTTP: Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); + // Log.notice(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); #endif String httpMessage((char *)0); @@ -1622,7 +1628,7 @@ void httpHandleEspFirmware() } webSendFooter(); - Log.notice(F("HTTP: Attempting ESP firmware update from: %s"), webServer.arg("espFirmware").c_str()); + Log.notice(TAG_HTTP, F("Attempting ESP firmware update from: %s"), webServer.arg("espFirmware").c_str()); // espStartOta(webServer.arg("espFirmware")); } @@ -1684,9 +1690,9 @@ void webStart() #if defined(STM32F4xx) IPAddress ip; ip = WiFi.localIP(); - Log.notice(F("HTTP: Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_HTTP, F("Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); #else - Log.notice(F("HTTP: Server started @ http://%s"), + Log.notice(TAG_HTTP, F("Server started @ http://%s"), (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); #endif #else @@ -1696,7 +1702,7 @@ void webStart() #else ip = Ethernet.localIP(); #endif - Log.notice(F("HTTP: Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_HTTP, F("Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); #endif } @@ -1704,7 +1710,7 @@ void webStop() { webServer.stop(); webServerStarted = false; - Log.warning(F("HTTP: Server stoped")); + Log.warning(TAG_HTTP, F("Server stoped")); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1715,7 +1721,7 @@ void httpSetup() #if HASP_USE_WIFI > 0 #if !defined(STM32F4xx) if(WiFi.getMode() != WIFI_STA) { - Log.notice(F("HTTP: Wifi access point")); + Log.notice(TAG_HTTP, F("Wifi access point")); webServer.on(F("/"), webHandleWifiConfig); } else { #endif @@ -1745,7 +1751,7 @@ void httpSetup() F("/edit"), HTTP_POST, []() { webServer.send(200, "text/plain", ""); - Log.verbose(F("Headers: %d"), webServer.headers()); + Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers()); }, handleFileUpload); #endif @@ -1792,7 +1798,7 @@ void httpSetup() F("/update"), HTTP_POST, []() { webServer.send(200, "text/plain", ""); - Log.verbose(F("Total size: %s"), webServer.hostHeader().c_str()); + Log.verbose(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str()); }, webHandleFirmwareUpdate); webServer.on(F("/espfirmware"), httpHandleEspFirmware); @@ -1815,7 +1821,7 @@ void httpSetup() size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *); webServer.collectHeaders(headerkeys, headerkeyssize); - Log.verbose(F("HTTP: Setup Complete")); + Log.verbose(TAG_HTTP, F("Setup Complete")); webStart(); } diff --git a/src/hasp_mdns.cpp b/src/hasp_mdns.cpp index c6613820..bed68361 100644 --- a/src/hasp_mdns.cpp +++ b/src/hasp_mdns.cpp @@ -11,12 +11,13 @@ #include "hasp_conf.h" #include "hasp_config.h" +#include "hasp_debug.h" #include "hasp_conf.h" -#if HASP_USE_MQTT>0 +#if HASP_USE_MQTT > 0 #include "hasp_mqtt.h" #endif -#if HASP_USE_MDNS>0 +#if HASP_USE_MDNS > 0 #include "hasp_mdns.h" #endif @@ -25,7 +26,7 @@ uint8_t mdnsEnabled = true; void mdnsSetup() { // mdnsSetConfig(settings); - Log.verbose(F("MDNS: Setup Complete")); + Log.verbose(TAG_MDNS, F("Setup Complete")); } void mdnsStart() @@ -56,9 +57,9 @@ void mdnsStart() addServiceTxt("arduino", "tcp", "ssh_upload", "no"); addServiceTxt("arduino", "tcp", "board", ARDUINO_BOARD); addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes" : "no");*/ - Log.notice(F("MDNS: Responder started")); + Log.notice(TAG_MDNS, F("Responder started")); } else { - Log.error(F("MDNS: Responder failed to start %s"), hasp2Node.c_str()); + Log.error(TAG_MDNS, F("Responder failed to start %s"), hasp2Node.c_str()); }; } #endif diff --git a/src/hasp_mqtt.cpp b/src/hasp_mqtt.cpp index a03526d8..13b702d8 100644 --- a/src/hasp_mqtt.cpp +++ b/src/hasp_mqtt.cpp @@ -18,7 +18,7 @@ WiFiClient mqttNetworkClient; #include WiFiClient mqttNetworkClient; #else -#if defined(STM32F4xx) && HASP_USE_WIFI>0 +#if defined(STM32F4xx) && HASP_USE_WIFI > 0 // #include WiFiSpiClient mqttNetworkClient; #else @@ -120,7 +120,7 @@ PubSubClient mqttClient(mqttNetworkClient); void mqtt_log_no_connection() { - Log.error(F("MQTT: Not connected")); + Log.error(TAG_MQTT, F("Not connected")); } bool IRAM_ATTR mqttIsConnected() @@ -146,12 +146,12 @@ void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char } // Log after char buffers are cleared - Log.notice(F("MQTT PUB: %sstate/%S = %s"), mqttNodeTopic, subtopic, payload); + Log.notice(TAG_MQTT_PUB, F("%sstate/%S = %s"), mqttNodeTopic, subtopic, payload); } void mqtt_send_input(uint8_t id, const char * payload) { - // Log.trace(F("MQTT TST: %sstate/input%u = %s"), mqttNodeTopic, id, payload); // to be removed + // Log.trace(TAG_MQTT,F("TST: %sstate/input%u = %s"), mqttNodeTopic, id, payload); // to be removed if(mqttIsConnected()) { char topic[64]; @@ -162,7 +162,7 @@ void mqtt_send_input(uint8_t id, const char * payload) } // Log after char buffers are cleared - Log.notice(F("MQTT PUB: %sstate/input%u = %s"), mqttNodeTopic, id, payload); + Log.notice(TAG_MQTT_PUB, F("%sstate/input%u = %s"), mqttNodeTopic, id, payload); } void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) @@ -181,7 +181,7 @@ void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const } // Log after char buffers are cleared - Log.notice(F("MQTT PUB: %sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), mqttNodeTopic, pageid, btnid, attribute, + Log.notice(TAG_MQTT_PUB, F("%sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), mqttNodeTopic, pageid, btnid, attribute, data); } @@ -194,12 +194,12 @@ void mqtt_send_statusupdate() snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), haspGetVersion().c_str(), long(millis() / 1000)); strcat(buffer, data); -#if HASP_USE_WIFI>0 +#if HASP_USE_WIFI > 0 #if defined(STM32F4xx) IPAddress ip; ip = WiFi.localIP(); char espIp[16]; - memset(espIp, 0 ,sizeof(espIp)); + memset(espIp, 0, sizeof(espIp)); snprintf_P(buffer, sizeof(buffer), PSTR("\"ssid\":\"%s\",\"rssi\":%i,\"ip\":\"%d.%d.%d.%d\","), WiFi.SSID(), WiFi.RSSI(), ip[0], ip[1], ip[2], ip[3]); #else @@ -244,8 +244,8 @@ void mqtt_send_statusupdate() // mqttClient.publish(mqttSensorTopic, mqttStatusPayload); // mqttClient.publish(mqttStatusTopic, "ON", true); //, 1); - // debugPrintln(String(F("MQTT: status update: ")) + String(mqttStatusPayload)); - // debugPrintln(String(F("MQTT: binary_sensor state: [")) + mqttStatusTopic + "] : [ON]"); + // debugPrintln(String(F("status update: ")) + String(mqttStatusPayload)); + // debugPrintln(String(F("binary_sensor state: [")) + mqttStatusTopic + "] : [ON]"); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -253,7 +253,7 @@ void mqtt_send_statusupdate() static void mqtt_message_cb(char * topic_p, byte * payload, unsigned int length) { // Handle incoming commands from MQTT if(length >= MQTT_MAX_PACKET_SIZE) { - Log.error(F("MQTT RCV: Payload too long (%d bytes)"), length); + Log.error(TAG_MQTT_RCV, F("Payload too long (%d bytes)"), length); return; } payload[length] = '\0'; @@ -277,24 +277,27 @@ static void mqtt_message_cb(char * topic_p, byte * payload, unsigned int length) // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' = nextionSetAttr("p[1].b[4].txt", "\"Lights On\"") char * topic = (char *)topic_p; - Log.notice(F("MQTT RCV: %s = %s"), topic, (char *)payload); + Log.notice(TAG_MQTT_RCV, F("%s = %s"), topic, (char *)payload); if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic topic += strlen(mqttNodeTopic); } else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic topic += strlen(mqttGroupTopic); } else { - Log.error(F("MQTT: Message received with invalid topic")); + Log.error(TAG_MQTT, F("Message received with invalid topic")); return; } // catch a dangling LWT from a previous connection if it appears - if(!strcmp_P(topic, PSTR("status")) && !strcasecmp_P((char *)payload, PSTR("OFF"))) { - char topicBuffer[128]; - snprintf_P(topicBuffer, sizeof(topicBuffer), PSTR("%sstatus"), mqttNodeTopic); - mqttClient.publish(topicBuffer, "ON", true); - Log.notice(F("MQTT: binary_sensor state: [status] : ON")); - // return; + if(!strcmp_P(topic, PSTR("status"))) { + if(!strcasecmp_P((char *)payload, PSTR("OFF"))) { + char topicBuffer[128]; + snprintf_P(topicBuffer, sizeof(topicBuffer), PSTR("%sstatus"), mqttNodeTopic); + mqttClient.publish(topicBuffer, "ON", true); + Log.notice(TAG_MQTT, F("binary_sensor state: [status] : ON")); + } else { + // already ON + } } else { dispatchTopicPayload(topic, (char *)payload); } @@ -326,9 +329,9 @@ void mqttSubscribeTo(const char * format, const char * data) char topic[64]; snprintf_P(topic, sizeof(topic), format, data); if(mqttClient.subscribe(topic)) { - Log.verbose(F("MQTT: * Subscribed to %s"), topic); + Log.verbose(TAG_MQTT, F(" * Subscribed to %s"), topic); } else { - Log.error(F("MQTT: Failed to subscribe to %s"), topic); + Log.error(TAG_MQTT, F("Failed to subscribe to %s"), topic); } } @@ -344,7 +347,7 @@ void mqttReconnect() mac.toLowerCase(); memset(mqttClientId, 0, sizeof(mqttClientId)); snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("plate_%s"), mac.c_str()); - Log.verbose(mqttClientId); + Log.verbose(TAG_MQTT, mqttClientId); } // Attempt to connect and set LWT and Clean Session @@ -352,7 +355,7 @@ void mqttReconnect() if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, false, "OFF", true)) { // Retry until we give up and restart after connectTimeout seconds mqttReconnectCount++; - snprintf_P(buffer, sizeof(buffer), PSTR("MQTT: %%s")); + snprintf_P(buffer, sizeof(buffer), PSTR("%%s")); switch(mqttClient.state()) { case MQTT_CONNECTION_TIMEOUT: strcat_P(buffer, PSTR("Server didn't respond within the keepalive time")); @@ -387,16 +390,16 @@ void mqttReconnect() default: strcat_P(buffer, PSTR("Unknown failure")); } - Log.warning(buffer); + Log.warning(TAG_MQTT, buffer); if(mqttReconnectCount > 50) { - Log.error(F("MQTT: %sRetry count exceeded, rebooting...")); + Log.error(TAG_MQTT, F("Retry count exceeded, rebooting...")); dispatchReboot(false); } return; } - Log.notice(F("MQTT: [SUCCESS] Connected to broker %s as clientID %s"), mqttServer, mqttClientId); + Log.notice(TAG_MQTT, F("[SUCCESS] Connected to broker %s as clientID %s"), mqttServer, mqttClientId); /* // MQTT topic string definitions @@ -435,10 +438,10 @@ void mqttReconnect() snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); mqttClient.publish(buffer, mqttFirstConnect ? "OFF" : "ON", true); //, 1); - Log.notice(F("MQTT: binary_sensor state: [%sstatus] : %s"), mqttNodeTopic, + Log.notice(TAG_MQTT, F("binary_sensor state: [%sstatus] : %s"), mqttNodeTopic, mqttFirstConnect ? PSTR("OFF") : PSTR("ON")); - /* snprintf_P(buffer, sizeof(buffer), PSTR("MQTT: binary_sensor state: [%sstatus] : %s"), mqttNodeTopic, + /* snprintf_P(buffer, sizeof(buffer), PSTR("binary_sensor state: [%sstatus] : %s"), mqttNodeTopic, mqttFirstConnect ? PSTR("OFF") : PSTR("ON")); debugPrintln(buffer); */ @@ -458,9 +461,9 @@ void mqttSetup() if(mqttEnabled) { mqttClient.setServer(mqttServer, 1883); mqttClient.setCallback(mqtt_message_cb); - Log.notice(F("MQTT: Setup Complete")); + Log.notice(TAG_MQTT, F("Setup Complete")); } else { - Log.notice(F("MQTT: Broker not configured")); + Log.notice(TAG_MQTT, F("Broker not configured")); } } @@ -491,7 +494,7 @@ void mqttStop() mqttClient.publish(topicBuffer, "{\"status\": \"unavailable\"}"); mqttClient.disconnect(); - Log.notice(F("MQTT: Disconnected from broker")); + Log.notice(TAG_MQTT, F("Disconnected from broker")); } } diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index 479a7e9c..00f25c65 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -315,11 +315,11 @@ bool oobeSetup() if(oobeAutoCalibrate) { lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), oobe_calibrate_cb); - Log.verbose(F("OOBE: Enabled Auto Calibrate on touch")); + Log.verbose(TAG_OOBE,F("Enabled Auto Calibrate on touch")); } else { lv_obj_set_click(lv_disp_get_layer_sys(NULL), false); lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), gotoPage1_cb); - Log.verbose(F("OOBE: Already calibrated")); + Log.verbose(TAG_OOBE,F("Already calibrated")); } oobeSetPage(0); return true; @@ -346,9 +346,9 @@ void oobeFakeSetup() if(oobeAutoCalibrate) { lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), oobe_calibrate_cb); - Log.verbose(F("OOBE: Enabled Auto Calibrate on touch")); + Log.verbose(TAG_OOBE,F("Enabled Auto Calibrate on touch")); } else { - Log.verbose(F("OOBE: Already calibrated")); + Log.verbose(TAG_OOBE,F("Already calibrated")); } #endif } \ No newline at end of file diff --git a/src/hasp_ota.cpp b/src/hasp_ota.cpp index 1389ebcf..87434962 100644 --- a/src/hasp_ota.cpp +++ b/src/hasp_ota.cpp @@ -36,18 +36,18 @@ static WiFiClient otaClient; std::string otaUrl = "http://10.1.0.3"; int8_t otaPrecentageComplete = -1; -int16_t otaPort = HASP_OTA_PORT; +int16_t otaPort = HASP_OTA_PORT; void otaProgress() { - Log.verbose(F("OTA: %s update in progress... %3u%"), + Log.verbose(TAG_OTA, F("%s update in progress... %3u%"), (ArduinoOTA.getCommand() == U_FLASH ? PSTR("Firmware") : PSTR("Filesystem")), otaPrecentageComplete); } void otaSetup() { if(strlen(otaUrl.c_str())) { - Log.verbose(F("OTA: %s"), otaUrl.c_str()); + Log.verbose(TAG_OTA, otaUrl.c_str()); } if(otaPort > 0) { @@ -57,9 +57,9 @@ void otaSetup() // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() } - Log.notice(F("OTA: Start update")); + Log.notice(TAG_OTA, F("Start update")); haspProgressVal(0); - haspProgressMsg(F("OTA: Firmware Update")); + haspProgressMsg(F("Firmware Update")); // dispatchPage("0"); otaPrecentageComplete = 0; // haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\""); @@ -73,7 +73,7 @@ void otaSetup() // dispatchPage("0"); // haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rComplete!\""); setup(); - //dispatchReboot(true); + // dispatchReboot(true); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { if(total != 0) { @@ -85,17 +85,17 @@ void otaSetup() }); ArduinoOTA.onError([](ota_error_t error) { otaPrecentageComplete = -1; - Log.error(F("OTA: ERROR code %u"), error); + Log.error(TAG_OTA, F("ERROR code %u"), error); if(error == OTA_AUTH_ERROR) - Log.error(F("OTA: ERROR - Auth Failed")); + Log.error(TAG_OTA, F("ERROR - Auth Failed")); else if(error == OTA_BEGIN_ERROR) - Log.error(F("OTA: ERROR - Begin Failed")); + Log.error(TAG_OTA, F("ERROR - Begin Failed")); else if(error == OTA_CONNECT_ERROR) - Log.error(F("OTA: ERROR - Connect Failed")); + Log.error(TAG_OTA, F("ERROR - Connect Failed")); else if(error == OTA_RECEIVE_ERROR) - Log.error(F("OTA: ERROR - Receive Failed")); + Log.error(TAG_OTA, F("ERROR - Receive Failed")); else if(error == OTA_END_ERROR) - Log.error(F("OTA: ERROR - End Failed")); + Log.error(TAG_OTA, F("ERROR - End Failed")); // haspSetAttr("p[0].b[1].txt", "\"ESP OTA FAILED\""); // delay(5000); // haspSendCmd("page " + String(nextionActivePage)); @@ -120,9 +120,9 @@ void otaSetup() ArduinoOTA.setRebootOnSuccess(false); // We do that ArduinoOTA.begin(); - Log.notice(F("OTA: Over the Air firmware update ready")); + Log.notice(TAG_OTA, F("Over the Air firmware update ready")); } else { - Log.notice(F("OTA: Disabled")); + Log.notice(TAG_OTA, F("Disabled")); } } @@ -153,18 +153,18 @@ void otaHttpUpdate(const char * espOtaUrl) switch(returnCode) { case HTTP_UPDATE_FAILED: - Log.error("FWUP: HTTP_UPDATE_FAILED error %d %s", ESPhttpUpdate.getLastError(), + Log.error(TAG_FWUP, "FWUP: HTTP_UPDATE_FAILED error %d %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\""); break; case HTTP_UPDATE_NO_UPDATES: - Log.notice(F("FWUP: HTTP_UPDATE_NO_UPDATES")); + Log.notice(TAG_FWUP, F("HTTP_UPDATE_NO_UPDATES")); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rNo update\""); break; case HTTP_UPDATE_OK: - Log.notice(F("FWUP: HTTP_UPDATE_OK")); + Log.notice(TAG_FWUP, F("HTTP_UPDATE_OK")); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rcomplete!\\r\\rRestarting.\""); dispatchReboot(true); delay(5000); @@ -175,18 +175,18 @@ void otaHttpUpdate(const char * espOtaUrl) switch(returnCode) { case HTTP_UPDATE_FAILED: - Log.error("FWUP: HTTP_UPDATE_FAILED error %i %s", httpUpdate.getLastError(), + Log.error(TAG_FWUP, F("HTTP_UPDATE_FAILED error %i %s"), httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\""); break; case HTTP_UPDATE_NO_UPDATES: - Log.notice(F("FWUP: HTTP_UPDATE_NO_UPDATES")); + Log.notice(TAG_FWUP, F("HTTP_UPDATE_NO_UPDATES")); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rNo update\""); break; case HTTP_UPDATE_OK: - Log.notice(F("FWUP: HTTP_UPDATE_OK")); + Log.notice(TAG_FWUP, F("HTTP_UPDATE_OK")); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rcomplete!\\r\\rRestarting.\""); dispatchReboot(true); delay(5000); diff --git a/src/hasp_slave.cpp b/src/hasp_slave.cpp index e2f8b335..17eabccc 100644 --- a/src/hasp_slave.cpp +++ b/src/hasp_slave.cpp @@ -42,7 +42,7 @@ void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char slave.ExecuteCommand((char*)cBuffer); // Log after char buffers are cleared - Log.notice(F("TAS PUB: %sstate/%S = %s"), slaveNodeTopic, subtopic, payload); + Log.notice(TAG_TASM,F("TAS PUB: %sstate/%S = %s"), slaveNodeTopic, subtopic, payload); } void IRAM_ATTR slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) @@ -52,12 +52,12 @@ void IRAM_ATTR slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/json {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data); slave.ExecuteCommand((char*)cBuffer); // Log after char buffers are cleared - Log.notice(F("TAS PUB: %sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data); + Log.notice(TAG_TASM,F("TAS PUB: %sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data); } void slave_send_input(uint8_t id, const char * payload) { - // Log.trace(F("MQTT TST: %sstate/input%u = %s"), mqttNodeTopic, id, payload); // to be removed + // Log.trace(TAG_TASM,F("MQTT TST: %sstate/input%u = %s"), mqttNodeTopic, id, payload); // to be removed char cBuffer[strlen(payload) + 64]; memset(cBuffer, 0 ,sizeof(cBuffer)); @@ -65,7 +65,7 @@ void slave_send_input(uint8_t id, const char * payload) slave.ExecuteCommand((char*)cBuffer); // Log after char buffers are cleared - Log.notice(F("TAS PUB: %sstate/input%u = %s"), slaveNodeTopic, id, payload); + Log.notice(TAG_TASM,F("TAS PUB: %sstate/input%u = %s"), slaveNodeTopic, id, payload); } void TASMO_TELE_JSON() @@ -90,12 +90,12 @@ void TASMO_TELE_JSON() void TASMO_DATA_RECEIVE(char *data) { - Log.verbose(F("TAS: Slave IN [%s]"), data); + Log.verbose(TAG_TASM,F("Slave IN [%s]"), data); char dataType[3]; memset(dataType, 0 ,sizeof(dataType)); snprintf_P(dataType, sizeof(dataType), data); - Log.verbose(F("TAS: dataType [%s]"), dataType); + Log.verbose(TAG_TASM,F("dataType [%s]"), dataType); if (!strcmp(dataType, "p[")){ // dispatchTextLine(data); @@ -107,7 +107,7 @@ void TASMO_DATA_RECEIVE(char *data) memset(slvVal, 0 ,sizeof(slvVal)); sscanf(data,"%[^=] =%s", slvCmd, slvVal); - Log.verbose(F("TAS: Cmd[%s] Val[%s]"), slvCmd, slvVal); + Log.verbose(TAG_TASM,F("Cmd[%s] Val[%s]"), slvCmd, slvVal); if (!strcmp(slvCmd, "calData")){ if (strlen(slvVal) != 0) { @@ -133,11 +133,11 @@ void TASMO_EVERY_SECOND(void) if (ledstate) { ledstate = false; //digitalWrite(HASP_OUTPUT_PIN, 1); - // Log.verbose(F("LED OFF")); + // Log.verbose(TAG_TASM,F("LED OFF")); } else { ledstate = true; //digitalWrite(HASP_OUTPUT_PIN, 0); - // Log.verbose(F("LED ON")); + // Log.verbose(TAG_TASM,F("LED ON")); } } @@ -148,7 +148,7 @@ void slaveSetup() slave.attach_FUNC_JSON(TASMO_TELE_JSON); slave.attach_FUNC_COMMAND_SEND(TASMO_DATA_RECEIVE); - Log.notice(F("TAS: HASP SLAVE LOADED")); + Log.notice(TAG_TASM,F("HASP SLAVE LOADED")); } void slaveLoop(void) diff --git a/src/hasp_spiffs.cpp b/src/hasp_spiffs.cpp index 30c58a56..54e199b8 100644 --- a/src/hasp_spiffs.cpp +++ b/src/hasp_spiffs.cpp @@ -3,6 +3,7 @@ #include "ArduinoLog.h" #include "hasp_conf.h" +#include "hasp_debug.h" #include "hasp_spiffs.h" #if HASP_USE_SPIFFS > 0 @@ -75,23 +76,23 @@ void spiffsList() #else if(!SPIFFS.begin(true)) { #endif - Log.error(F("FILE: Flash file system not mouted.")); + Log.error(TAG_FILE,F("Flash file system not mouted.")); } else { - Log.verbose(F("FILE: Listing files on the internal flash:")); + Log.verbose(TAG_FILE,F("Listing files on the internal flash:")); #if defined(ARDUINO_ARCH_ESP32) File root = SPIFFS.open("/"); File file = root.openNextFile(); while(file) { - Log.verbose(F("FILE: * %s (%u bytes)"), file.name(), (uint32_t)file.size()); + Log.verbose(TAG_FILE,F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size()); file = root.openNextFile(); } #endif #if defined(ARDUINO_ARCH_ESP8266) Dir dir = SPIFFS.openDir("/"); while(dir.next()) { - Log.notice(F("FILE: * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize()); + Log.notice(TAG_FILE,F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize()); } #endif } @@ -108,9 +109,9 @@ void spiffsSetup() #else if(!SPIFFS.begin(true)) { #endif - Log.error(F("FILE: SPI flash init failed. Unable to mount FS.")); + Log.error(TAG_FILE,F("SPI flash init failed. Unable to mount FS.")); } else { - Log.verbose(F("FILE: SPI Flash FS mounted")); + Log.verbose(TAG_FILE,F("SPI Flash FS mounted")); } #endif } \ No newline at end of file diff --git a/src/hasp_telnet.cpp b/src/hasp_telnet.cpp index c05c3192..1a42dd54 100644 --- a/src/hasp_telnet.cpp +++ b/src/hasp_telnet.cpp @@ -47,7 +47,7 @@ char telnetInputBuffer[128]; void telnetClientDisconnect() { - // Log.notice(F("Closing session from %s"), telnetClient.remoteIP().toString().c_str()); + // Log.notice(TAG_TELN,F("Closing session from %s"), telnetClient.remoteIP().toString().c_str()); telnetClient.stop(); Log.unregisterOutput(1); // telnetClient telnetLoginState = TELNET_UNAUTHENTICATED; @@ -62,7 +62,7 @@ void telnetClientLogon() telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct telnetLoginAttempt = 0; // Reset attempt counter Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true); - // Log.notice(F("Client login from %s"), telnetClient.remoteIP().toString().c_str()); + // Log.notice(TAG_TELN,F("Client login from %s"), telnetClient.remoteIP().toString().c_str()); telnetClient.flush(); /* Echo locally as separate string */ // telnetClient.print(F("TELNET: Client login from ")); @@ -78,12 +78,12 @@ void telnetAcceptClient() Log.unregisterOutput(1); // telnetClient } telnetClient = telnetServer->available(); // ready for new client - // Log.notice(F("Client connected from %s"), telnetClient.remoteIP().toString().c_str()); + // Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str()); if(!telnetClient) { - Log.notice(F("Client NOT connected")); + Log.notice(TAG_TELN,F("Client NOT connected")); return; } - Log.notice(F("Client connected")); + Log.notice(TAG_TELN,F("Client connected")); /* Avoid a buffer here */ telnetClient.print(0xFF); // DO TERMINAL-TYPE @@ -132,7 +132,7 @@ static void telnetProcessLine() telnetLoginState = TELNET_UNAUTHENTICATED; telnetLoginAttempt++; // Subsequent attempt telnetClient.println(F("Authorization failed!\r\n")); - // Log.warning(F("Incorrect login attempt from %s"), telnetClient.remoteIP().toString().c_str()); + // Log.warning(TAG_TELN,F("Incorrect login attempt from %s"), telnetClient.remoteIP().toString().c_str()); if(telnetLoginAttempt >= 3) { telnetClientDisconnect(); } else { @@ -200,9 +200,9 @@ void telnetSetup() // if(!telnetServer) telnetServer = new EthernetServer(telnetPort); // if(telnetServer) { telnetServer->begin(); - Log.notice(F("Debug telnet console started")); + Log.notice(TAG_TELN,F("Debug telnet console started")); // } else { - // Log.error(F("Failed to start telnet server")); + // Log.error(TAG_TELN,F("Failed to start telnet server")); //} #else if(!telnetServer) telnetServer = new WiFiServer(telnetPort); @@ -212,14 +212,14 @@ void telnetSetup() // if(!telnetClient) telnetClient = new WiFiClient; // if(!telnetClient) { - // Log.error(F("Failed to start telnet client")); + // Log.error(TAG_TELN,F("Failed to start telnet client")); //} else { telnetClient.setNoDelay(true); //} - Log.notice(F("Debug telnet console started")); + Log.notice(TAG_TELN,F("Debug telnet console started")); } else { - Log.error(F("Failed to start telnet server")); + Log.error(TAG_TELN,F("Failed to start telnet server")); } #endif } @@ -238,12 +238,12 @@ Ethernet.schedule(); //telnetAcceptClient(client); telnetClient = client; // ready for new client - // Log.notice(F("Client connected from %s"), telnetClient.remoteIP().toString().c_str()); + // Log.notice(TAG_TELN,F("Client connected from %s"), telnetClient.remoteIP().toString().c_str()); if(!telnetClient) { - Log.notice(F("Client NOT connected")); + Log.notice(TAG_TELN,F("Client NOT connected")); return; } - Log.notice(F("Client connected")); + Log.notice(TAG_TELN,F("Client connected")); /* Avoid a buffer here */ // telnetClient.print(0xFF); // DO TERMINAL-TYPE diff --git a/src/hasp_tft.cpp b/src/hasp_tft.cpp index d176b834..88b404ee 100644 --- a/src/hasp_tft.cpp +++ b/src/hasp_tft.cpp @@ -8,6 +8,7 @@ #include "hasp_tft.h" #include "hasp_hal.h" #include "hasp_gpio.h" // PinNames +#include "hasp_debug.h" #if defined(ARDUINO_ARCH_ESP8266) ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin @@ -29,10 +30,10 @@ void tftStop() void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset) { if(x_offset != 0) { - Log.verbose(F("TFT: R%u x offset = %i"), pin, x_offset); + Log.verbose(TAG_TFT, F("R%u x offset = %i"), pin, x_offset); } if(y_offset != 0) { - Log.verbose(F("TFT: R%u y offset = %i"), pin, y_offset); + Log.verbose(TAG_TFT, F("R%u y offset = %i"), pin, y_offset); } } @@ -40,8 +41,8 @@ void tftPinInfo(const __FlashStringHelper * pinfunction, int8_t pin) { if(pin != -1) { char buffer[64]; - snprintf_P(buffer, sizeof(buffer), PSTR("TFT: %-11s: %s (GPIO %02d)"), pinfunction, gpioName(pin).c_str(), pin); - Log.verbose(buffer); + snprintf_P(buffer, sizeof(buffer), PSTR("%-11s: %s (GPIO %02d)"), pinfunction, gpioName(pin).c_str(), pin); + Log.verbose(TAG_TFT, buffer); } } @@ -50,29 +51,29 @@ void tftShowConfig(TFT_eSPI & tft) setup_t tftSetup; tft.getSetup(tftSetup); - Log.verbose(F("TFT: TFT_eSPI : v%s"), tftSetup.version.c_str()); + Log.verbose(TAG_TFT, F("TFT_eSPI : v%s"), tftSetup.version.c_str()); #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - Log.verbose(F("TFT: Processor : ESP%x"), tftSetup.esp); + Log.verbose(TAG_TFT, F("Processor : ESP%x"), tftSetup.esp); #else - Log.verbose(F("TFT: Processor : STM%x"), tftSetup.esp); + Log.verbose(TAG_TFT, F("Processor : STM%x"), tftSetup.esp); #endif - Log.verbose(F("TFT: CPU freq. : %i MHz"), halGetCpuFreqMHz()); + Log.verbose(TAG_TFT, F("CPU freq. : %i MHz"), halGetCpuFreqMHz()); #if defined(ARDUINO_ARCH_ESP8266) - Log.verbose(F("TFT: Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined + Log.verbose(TAG_TFT, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined #endif - Log.verbose(F("TFT: Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); - Log.verbose(F("TFT: Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); + Log.verbose(TAG_TFT, F("Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); + Log.verbose(TAG_TFT, F("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel")); #if defined(ARDUINO_ARCH_ESP8266) - Log.verbose(F("TFT: SPI overlap : %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); + Log.verbose(TAG_TFT, F("SPI overlap : %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No")); #endif if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch { - Log.verbose(F("TFT: Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver); - Log.verbose(F("TFT: Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height); + Log.verbose(TAG_TFT, F("Driver : %s"), halDisplayDriverName().c_str()); // tftSetup.tft_driver); + Log.verbose(TAG_TFT, F("Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height); } else if(tftSetup.tft_driver == 0xE9D) - Log.verbose(F("Driver = ePaper")); + Log.verbose(TAG_TFT, F("Driver = ePaper")); // Offsets, not all used yet tftOffsetInfo(0, tftSetup.r0_x_offset, tftSetup.r0_y_offset); @@ -94,14 +95,14 @@ void tftShowConfig(TFT_eSPI & tft) #if defined(ARDUINO_ARCH_ESP8266) if(tftSetup.overlap == true) { - Log.verbose(F("Overlap selected, following pins MUST be used:")); + Log.verbose(TAG_TFT, F("Overlap selected, following pins MUST be used:")); - Log.verbose(F("MOSI : SD1 (GPIO 8)")); - Log.verbose(F("MISO : SD0 (GPIO 7)")); - Log.verbose(F("SCK : CLK (GPIO 6)")); - Log.verbose(F("TFT_CS : D3 (GPIO 0)")); + Log.verbose(TAG_TFT, F("MOSI : SD1 (GPIO 8)")); + Log.verbose(TAG_TFT, F("MISO : SD0 (GPIO 7)")); + Log.verbose(TAG_TFT, F("SCK : CLK (GPIO 6)")); + Log.verbose(TAG_TFT, F("TFT_CS : D3 (GPIO 0)")); - Log.verbose(F("TFT_DC and TFT_RST pins can be tftSetup defined")); + Log.verbose(TAG_TFT, F("TFT_DC and TFT_RST pins can be tftSetup defined")); } #endif @@ -124,10 +125,12 @@ void tftShowConfig(TFT_eSPI & tft) tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7); if(tftSetup.serial == 1) { - Log.verbose(F("TFT: Display SPI freq. : %d.%d MHz"), tftSetup.tft_spi_freq / 10, tftSetup.tft_spi_freq % 10); + Log.verbose(TAG_TFT, F("Display SPI freq. : %d.%d MHz"), tftSetup.tft_spi_freq / 10, + tftSetup.tft_spi_freq % 10); } if(tftSetup.pin_tch_cs != -1) { - Log.verbose(F("TFT: Touch SPI freq. : %d.%d MHz"), tftSetup.tch_spi_freq / 10, tftSetup.tch_spi_freq % 10); + Log.verbose(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), tftSetup.tch_spi_freq / 10, + tftSetup.tch_spi_freq % 10); } } diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index 56aae575..7e4a1b6c 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -52,11 +52,11 @@ void wifiConnected(IPAddress ipaddress) #if defined(STM32F4xx) IPAddress ip; ip = WiFi.localIP(); - Log.notice(F("WIFI: Received IP address %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(TAG_WIFI,F("Received IP address %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); #else - Log.notice(F("WIFI: Received IP address %s"), ipaddress.toString().c_str()); + Log.notice(TAG_WIFI,F("Received IP address %s"), ipaddress.toString().c_str()); #endif - Log.verbose(F("WIFI: Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR("yes") : PSTR("no")); + Log.verbose(TAG_WIFI,F("Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR("yes") : PSTR("no")); haspProgressVal(255); // if(isConnected) { @@ -73,15 +73,15 @@ void wifiDisconnected(const char * ssid, uint8_t reason) haspProgressVal(wifiReconnectCounter * 3); haspProgressMsg(F("Wifi Disconnected")); if(wifiReconnectCounter > 33) { - Log.error(F("WIFI: Retries exceed %u: Rebooting..."), wifiReconnectCounter); + Log.error(TAG_WIFI,F("Retries exceed %u: Rebooting..."), wifiReconnectCounter); dispatchReboot(false); } - Log.warning(F("WIFI: Disconnected from %s (Reason: %d)"), ssid, reason); + Log.warning(TAG_WIFI,F("Disconnected from %s (Reason: %d)"), ssid, reason); } void wifiSsidConnected(const char * ssid) { - Log.notice(F("WIFI: Connected to SSID %s. Requesting IP..."), ssid); + Log.notice(TAG_WIFI,F("Connected to SSID %s. Requesting IP..."), ssid); wifiReconnectCounter = 0; } @@ -138,7 +138,7 @@ bool wifiShowAP(char * ssid, char * pass) sprintf_P(ssid, PSTR("HASP-%02x%02x%02x"), mac[3], mac[4], mac[5]); sprintf_P(pass, PSTR("haspadmin")); #if defined(STM32F4xx) - Log.warning(F("WIFI: We should setup Temporary Access Point %s password: %s"), ssid, pass); + Log.warning(TAG_WIFI,F("We should setup Temporary Access Point %s password: %s"), ssid, pass); #else WiFi.softAP(ssid, pass); @@ -146,8 +146,8 @@ bool wifiShowAP(char * ssid, char * pass) // dnsServer.setErrorReplyCode(DNSReplyCode::NoError); // dnsServer.start(DNS_PORT, "*", apIP); - Log.warning(F("WIFI: Temporary Access Point %s password: %s"), ssid, pass); - Log.warning(F("WIFI: AP IP address : %s"), WiFi.softAPIP().toString().c_str()); + Log.warning(TAG_WIFI,F("Temporary Access Point %s password: %s"), ssid, pass); + Log.warning(TAG_WIFI,F("AP IP address : %s"), WiFi.softAPIP().toString().c_str()); // httpReconnect();} #endif return true; @@ -181,13 +181,13 @@ void wifiSetup() // check for the presence of the shield: if (WiFiSpi.status() == WL_NO_SHIELD) { - Log.notice(F("WIFI: WiFi shield not present")); + Log.notice(TAG_WIFI,F("WiFi shield not present")); // don't continue: while (true); } if (!WiFiSpi.checkProtocolVersion()) { - Log.notice(F("WIFI: Protocol version mismatch. Please upgrade the firmware")); + Log.notice(TAG_WIFI,F("Protocol version mismatch. Please upgrade the firmware")); // don't continue: while (true); } @@ -196,7 +196,7 @@ void wifiSetup() // int status = WL_IDLE_STATUS; // the Wifi radio's status if(!wifiShowAP()) { // while (status != WL_CONNECTED) { - Log.notice(F("WIFI: Connecting to : %s"), wifiSsid); + Log.notice(TAG_WIFI,F("Connecting to : %s"), wifiSsid); // Connect to WPA/WPA2 network // status = WiFi.begin(wifiSsid, wifiPassword); WiFi.begin(wifiSsid, wifiPassword); @@ -220,7 +220,7 @@ void wifiSetup() #endif wifiReconnect(); - Log.notice(F("WIFI: Connecting to : %s"), wifiSsid); + Log.notice(TAG_WIFI,F("Connecting to : %s"), wifiSsid); } #endif } @@ -240,10 +240,10 @@ bool wifiEvery5Seconds() } else { wifiReconnectCounter++; if(wifiReconnectCounter > 45) { - Log.error(F("WIFI: Retries exceed %u: Rebooting..."), wifiReconnectCounter); + Log.error(TAG_WIFI,F("Retries exceed %u: Rebooting..."), wifiReconnectCounter); dispatchReboot(false); } - Log.warning(F("WIFI: No Connection... retry %u"), wifiReconnectCounter); + Log.warning(TAG_WIFI,F("No Connection... retry %u"), wifiReconnectCounter); if(wifiReconnectCounter % 6 == 0) { wifiReconnect(); } @@ -307,14 +307,14 @@ bool wifiTestConnection() while(attempt < 10 && (WiFi.status() != WL_CONNECTED || WiFi.localIP().toString() == F("0.0.0.0"))) { #endif attempt++; - Log.verbose(F("WIFI: Trying to connect to %s... %u"), wifiSsid, attempt); + Log.verbose(TAG_WIFI,F("Trying to connect to %s... %u"), wifiSsid, attempt); delay(1000); } #if defined(STM32F4xx) - Log.verbose(F("WIFI: Received IP addres %s"), espIp); + Log.verbose(TAG_WIFI,F("Received IP addres %s"), espIp); if((WiFi.status() == WL_CONNECTED && String(espIp) != F("0.0.0.0"))) return true; #else - Log.verbose(F("WIFI: Received IP addres %s"), WiFi.localIP().toString().c_str()); + Log.verbose(TAG_WIFI,F("Received IP addres %s"), WiFi.localIP().toString().c_str()); if((WiFi.status() == WL_CONNECTED && WiFi.localIP().toString() != F("0.0.0.0"))) return true; #endif WiFi.disconnect(); @@ -328,7 +328,7 @@ void wifiStop() #if !defined(STM32F4xx) WiFi.mode(WIFI_OFF); #endif - Log.warning(F("WIFI: Stopped")); + Log.warning(TAG_WIFI,F("Stopped")); } #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f76822a9..39dc3bfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,6 @@ void setup() /**************************** * Apply User Configuration ***************************/ - debugSetup(); #if HASP_USE_GPIO > 0 gpioSetup(); @@ -57,6 +56,9 @@ void setup() wifiSetup(); #endif + // The network stack needs to be initialized before calling debugSetup, cause syslog needs lwip + debugSetup(); + guiSetup(); if(!oobeSetup()) { haspSetup();