Rewrite Logging

This commit is contained in:
fvanroie 2020-11-10 00:22:42 +01:00
parent 7d087e37b4
commit aa244d5cf2
27 changed files with 672 additions and 453 deletions

View File

@ -1,10 +1,6 @@
#ifndef HASP_CONF_H #ifndef HASP_CONF_H
#define 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 #define HASP_USE_APP 1
/* Network Services */ /* Network Services */

View File

@ -22,7 +22,7 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
#include "WProgram.h" #include "WProgram.h"
#endif #endif
#include "StringStream.h" #include "StringStream.h"
typedef void (*printfunction)(int level, Print *); typedef void (*printfunction)(uint8_t tag, int level, Print *);
//#include <stdint.h> //#include <stdint.h>
//#include <stddef.h> //#include <stddef.h>
@ -31,13 +31,18 @@ typedef void (*printfunction)(int level, Print *);
// ************************************************************************ // ************************************************************************
//#define DISABLE_LOGGING //#define DISABLE_LOGGING
#define LOG_LEVEL_SILENT 0 #define LOG_LEVEL_SILENT -1
#define LOG_LEVEL_FATAL 1
#define LOG_LEVEL_ERROR 2 #define LOG_LEVEL_FATAL 0
#define LOG_LEVEL_WARNING 3 #define LOG_LEVEL_ALERT 1
#define LOG_LEVEL_NOTICE 4 #define LOG_LEVEL_CRITICAL 2
#define LOG_LEVEL_TRACE 5 #define LOG_LEVEL_ERROR 3
#define LOG_LEVEL_VERBOSE 6 #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 CR "\n"
#define LOGGING_VERSION 1_0_3 #define LOGGING_VERSION 1_0_3
@ -126,7 +131,7 @@ class Logging {
* \param level - The new log level. * \param level - The new log level.
* \return void * \return void
*/ */
void setLevel(uint8_t slot,int level); void setLevel(uint8_t slot, int level);
/** /**
* Get the log level. * Get the log level.
@ -142,7 +147,7 @@ class Logging {
* false otherwise. * false otherwise.
* \return void * \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 * Get whether the log level is shown during logging
@ -178,10 +183,10 @@ class Logging {
* \param ... any number of variables * \param ... any number of variables
* \return void * \return void
*/ */
template <class T, typename... Args> void fatal(T msg, Args... args) template <class T, typename... Args> void fatal(uint8_t tag, T msg, Args... args)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_FATAL, msg, args...); printLevel(tag, LOG_LEVEL_FATAL, msg, args...);
#endif #endif
} }
@ -195,10 +200,10 @@ class Logging {
* \param ... any number of variables * \param ... any number of variables
* \return void * \return void
*/ */
template <class T, typename... Args> void error(T msg, Args... args) template <class T, typename... Args> void error(uint8_t tag, T msg, Args... args)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_ERROR, msg, args...); printLevel(tag, LOG_LEVEL_ERROR, msg, args...);
#endif #endif
} }
@ -212,10 +217,10 @@ class Logging {
* \param ... any number of variables * \param ... any number of variables
* \return void * \return void
*/ */
template <class T, typename... Args> void warning(T msg, Args... args) template <class T, typename... Args> void warning(uint8_t tag, T msg, Args... args)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_WARNING, msg, args...); printLevel(tag, LOG_LEVEL_WARNING, msg, args...);
#endif #endif
} }
@ -229,10 +234,10 @@ class Logging {
* \param ... any number of variables * \param ... any number of variables
* \return void * \return void
*/ */
template <class T, typename... Args> void notice(T msg, Args... args) template <class T, typename... Args> void notice(uint8_t tag, T msg, Args... args)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_NOTICE, msg, args...); printLevel(tag, LOG_LEVEL_NOTICE, msg, args...);
#endif #endif
} }
@ -246,10 +251,10 @@ class Logging {
* \param ... any number of variables * \param ... any number of variables
* \return void * \return void
*/ */
template <class T, typename... Args> void trace(T msg, Args... args) template <class T, typename... Args> void trace(uint8_t tag, T msg, Args... args)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_TRACE, msg, args...); printLevel(tag, LOG_LEVEL_TRACE, msg, args...);
#endif #endif
} }
@ -263,10 +268,10 @@ class Logging {
* \param ... any number of variables * \param ... any number of variables
* \return void * \return void
*/ */
template <class T, typename... Args> void verbose(T msg, Args... args) template <class T, typename... Args> void verbose(uint8_t tag, T msg, Args... args)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_VERBOSE, msg, args...); printLevel(tag, LOG_LEVEL_VERBOSE, msg, args...);
#endif #endif
} }
@ -277,15 +282,15 @@ class Logging {
void printFormat(Print * logOutput, const char format, va_list * args); void printFormat(Print * logOutput, const char format, va_list * args);
template <class T> void printLevel(int level, T msg, ...) template <class T> void printLevel(uint8_t tag, int level, T msg, ...)
{ {
#ifndef DISABLE_LOGGING #ifndef DISABLE_LOGGING
for(uint8_t i = 0; i < 3; i++) { 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) { if(_prefix != NULL) {
_prefix(level, _logOutput[i]); _prefix(tag, level, _logOutput[i]);
} }
va_list args; va_list args;
@ -293,7 +298,7 @@ class Logging {
print(_logOutput[i], msg, args); print(_logOutput[i], msg, args);
if(_suffix != NULL) { if(_suffix != NULL) {
_suffix(level, _logOutput[i]); _suffix(tag, level, _logOutput[i]);
} }
} }

View File

@ -19,6 +19,8 @@
#endif #endif
#include "FS.h" // Include the SPIFFS library #include "FS.h" // Include the SPIFFS library
#define TAG_LVFS 91
/********************* /*********************
* DEFINES * 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]; char filename[32];
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path); 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); 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) { if(!file) {
return LV_FS_RES_NOT_EX; 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 { } else {
// f.seek(0, SeekSet); // f.seek(0, SeekSet);
// Log.verbose(F("LVFS: Assigning %s"), f.name()); // Log.verbose(TAG_LVFS,F("Assigning %s"), f.name());
Log.verbose(F("LVFS: %d"), __LINE__); Log.verbose(TAG_LVFS, F("%d"), __LINE__);
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; /*Just avoid the confusing casings*/ 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(TAG_LVFS,F("Copying %s"), f.name());
Log.verbose(F("LVFS: %d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t)); Log.verbose(TAG_LVFS, F("%d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t));
if (fp != NULL) (*fp) = file; if(fp != NULL) (*fp) = file;
// memcpy(fp,&file,sizeof(lv_spiffs_file_t)); // 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; 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*/ (void)drv; /*Unused*/
lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p; lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p;
// File file = fp; // File file = fp;
//file = SPIFFS.open("/background.bin"); // file = SPIFFS.open("/background.bin");
if(!file) { if(!file) {
// Log.verbose(F("LVFS: Invalid file")); // Log.verbose(TAG_LVFS,F("Invalid file"));
return LV_FS_RES_NOT_EX; return LV_FS_RES_NOT_EX;
} else if(file.isDirectory()) { } 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) 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*/ (void)drv; /*Unused*/
lv_spiffs_file_t *fp = (lv_spiffs_file_t *)file_p; lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
lv_spiffs_file_t file = *fp; lv_spiffs_file_t file = *fp;
if(!file) { if(!file) {
// Log.verbose(F("LVFS: Invalid file")); // Log.verbose(TAG_LVFS,F("Invalid file"));
return LV_FS_RES_NOT_EX; return LV_FS_RES_NOT_EX;
} else { } 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); *br = (uint32_t)file.readBytes((char *)buf, btr);
Serial.print("!"); Serial.print("!");
return LV_FS_RES_OK; 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; // File file = fp;
if(!file) { if(!file) {
// Log.verbose(F("LVFS: Invalid file")); // Log.verbose(TAG_LVFS,F("Invalid file"));
return LV_FS_RES_NOT_EX; return LV_FS_RES_NOT_EX;
} else { } 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; // File file = fp;
if(!file) { if(!file) {
// Log.verbose(F("LVFS: Invalid file")); // Log.verbose(TAG_LVFS,F("Invalid file"));
return LV_FS_RES_NOT_EX; return LV_FS_RES_NOT_EX;
} else { } 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; // File file = fp;
if(!file) { if(!file) {
// Log.verbose(F("LVFS: Invalid file")); // Log.verbose(TAG_LVFS,F("Invalid file"));
return LV_FS_RES_NOT_EX; return LV_FS_RES_NOT_EX;
} else { } 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; // File file = fp;
if(!file) { if(!file) {
// Log.verbose(F("LVFS: Invalid file")); // Log.verbose(TAG_LVFS,F("Invalid file"));
return LV_FS_RES_NOT_EX; return LV_FS_RES_NOT_EX;
} else { } else {

View File

@ -19,6 +19,8 @@
#define ColorBlack 0x0f #define ColorBlack 0x0f
#define ColorWhite 0x00 #define ColorWhite 0x00
#define TAG_FONT 92
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
@ -79,7 +81,7 @@ static inline bool openFont(File & file, const char * filename)
file = SPIFFS.open(filename, "r"); file = SPIFFS.open(filename, "r");
if(!file) { if(!file) {
Log.error(F("FONT: %sOpening font: %s"), filename); Log.error(TAG_FONT,F("Opening font: %s"), filename);
return false; return false;
} }
return file; 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 */ /* Check that we read the correct size */
if(readSize != sizeof(zi_font_header_t)) { 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(); file.close();
return ZIFONT_ERROR_READING_DATA; return ZIFONT_ERROR_READING_DATA;
} }
/* Check ziFile Header Format */ /* Check ziFile Header Format */
if(header.Password != 4 || header.Version != 5) { 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(); file.close();
return ZIFONT_ERROR_UNKNOWN_HEADER; 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 //* Check that we read the correct size
if(readSize != sizeof(lv_zifont_char_t) * CHAR_CACHE_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(); file.close();
return ZIFONT_ERROR_READING_DATA; 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); header.Maximumnumchars);
file.close(); 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)) { if(readSize != sizeof(lv_zifont_char_t)) {
file.close(); file.close();
lv_mem_free(charInfo); 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; 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) { if(charInfo->character != unicode_letter) {
file.close(); file.close();
lv_mem_free(charInfo); 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; 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) { if((uint8_t)b[0] != 3) {
file.close(); file.close();
lv_mem_free(charInfo); 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]); datapos, b[0]);
debugPrintln(data); 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("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); // 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"); // startMillis) + "ms");
return true; return true;
} }

View File

@ -77,6 +77,9 @@ build_flags =
;-D DISABLE_LOGGING ;-D DISABLE_LOGGING
-I include ; include lv_conf.h and hasp_conf.h -I include ; include lv_conf.h and hasp_conf.h
${override.build_flags} ${override.build_flags}
-D HASP_VERSION_MAJOR=0
-D HASP_VERSION_MINOR=2
-D HASP_VERSION_REVISION=1109
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<stm32f4/> src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<stm32f4/>
@ -88,6 +91,7 @@ esp8266_flags=
${env.build_flags} ${env.build_flags}
-D HTTP_UPLOAD_BUFLEN=640 ; lower http upload buffer -D HTTP_UPLOAD_BUFLEN=640 ; lower http upload buffer
-D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages -D MQTT_MAX_PACKET_SIZE=1024 ; longer PubSubClient messages
; -- hasp-lvgl build options ------------------------
-D HASP_USE_WIFI=1 -D HASP_USE_WIFI=1
-D HASP_USE_MQTT=1 -D HASP_USE_MQTT=1
-D HASP_USE_HTTP=1 -D HASP_USE_HTTP=1
@ -103,12 +107,13 @@ esp32_flags=
${env.build_flags} ${env.build_flags}
-D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer -D HTTP_UPLOAD_BUFLEN=1024 ; lower http upload buffer
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
; -- hasp-lvgl build options ------------------------
-D HASP_USE_WIFI=1 -D HASP_USE_WIFI=1
-D HASP_USE_MQTT=1 -D HASP_USE_MQTT=1
-D HASP_USE_HTTP=1 -D HASP_USE_HTTP=1
-D HASP_USE_MDNS=1 -D HASP_USE_MDNS=1
-D HASP_USE_SYSLOG=0 -D HASP_USE_SYSLOG=1
-D HASP_USE_TELNET=0 -D HASP_USE_TELNET=1
-D HASP_USE_SPIFFS=1 -D HASP_USE_SPIFFS=1
-D HASP_USE_EEPROM=1 -D HASP_USE_EEPROM=1
-D HASP_USE_GPIO=1 -D HASP_USE_GPIO=1

View File

@ -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); uint16_t tabcount = lv_tabview_get_tab_count(child);
for(uint16_t i = 0; i < tabcount; i++) { for(uint16_t i = 0; i < tabcount; i++) {
lv_obj_t * tab = lv_tabview_get_tab(child, 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 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); 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 // Used in the dispatcher
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, const char * payload) 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; lv_fs_res_t res;
res = lv_fs_open(&f, "F:/pages.jsonl", LV_FS_MODE_RD); res = lv_fs_open(&f, "F:/pages.jsonl", LV_FS_MODE_RD);
if(res == LV_FS_RES_OK) if(res == LV_FS_RES_OK)
Log.error(F("Opening pages.json OK")); Log.error(TAG_HASP, F("Opening pages.json OK"));
else 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 btoread = 128;
uint32_t bread = 0; uint32_t bread = 0;
@ -378,17 +382,17 @@ void haspSetup()
res = lv_fs_read(&f, &buffer, btoread, &bread); res = lv_fs_read(&f, &buffer, btoread, &bread);
if(res == LV_FS_RES_OK) { 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'; buffer[127] = '\0';
Log.verbose(buffer); Log.verbose(TAG_HASP, buffer);
} else } 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); res = lv_fs_close(&f);
if(res == LV_FS_RES_OK) if(res == LV_FS_RES_OK)
Log.error(F("Closing pages.json OK")); Log.error(TAG_HASP, F("Closing pages.json OK"));
else 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 ********************************************************************/ /******* File System Test ********************************************************************/
/* ********** Font Initializations ********** */ /* ********** Font Initializations ********** */
@ -398,7 +402,7 @@ void haspSetup()
lv_zifont_init(); lv_zifont_init();
if(lv_zifont_font_init(&haspFonts[0], haspZiFontPath, 32) != 0) { 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; haspFonts[0] = LV_FONT_DEFAULT;
} else { } else {
// defaultFont = haspFonts[0]; // defaultFont = haspFonts[0];
@ -413,8 +417,8 @@ void haspSetup()
switch(haspThemeId) { switch(haspThemeId) {
#if(LV_USE_THEME_EMPTY == 1) #if(LV_USE_THEME_EMPTY == 1)
case 0: case 0:
th = lv_theme_empty_init(LV_COLOR_PURPLE, LV_COLOR_BLACK, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1], th = lv_theme_empty_init(LV_COLOR_PURPLE, LV_COLOR_BLACK, LV_THEME_DEFAULT_FLAGS, haspFonts[0],
haspFonts[2], haspFonts[3]); haspFonts[1], haspFonts[2], haspFonts[3]);
break; break;
#endif #endif
@ -464,8 +468,8 @@ void haspSetup()
#if LV_USE_THEME_TEMPLATE == 1 #if LV_USE_THEME_TEMPLATE == 1
case 7: case 7:
th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1], th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0],
haspFonts[2], haspFonts[3]); haspFonts[1], haspFonts[2], haspFonts[3]);
break; break;
#endif #endif
#if(LV_USE_THEME_HASP == 1) #if(LV_USE_THEME_HASP == 1)
@ -487,13 +491,13 @@ void haspSetup()
default: default:
th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0], th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0],
haspFonts[1], haspFonts[2], haspFonts[3]); haspFonts[1], haspFonts[2], haspFonts[3]);
Log.error(F("HASP: Unknown theme selected")); Log.error(TAG_HASP, F("Unknown theme selected"));
} }
if(th) { if(th) {
Log.verbose(F("HASP: Custom theme loaded")); Log.verbose(TAG_HASP, F("Custom theme loaded"));
} else { } 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); // lv_theme_set_current(th);
/* ********** Theme Initializations ********** */ /* ********** 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: case LV_EVENT_VALUE_CHANGED:
strcat_P(buffer, PSTR("Value Changed")); strcat_P(buffer, PSTR("Value Changed"));
Log.notice(buffer); Log.notice(TAG_HASP, buffer);
return; return;
case LV_EVENT_DELETE: case LV_EVENT_DELETE:
strcat_P(buffer, PSTR("Object deleted")); strcat_P(buffer, PSTR("Object deleted"));
Log.notice(buffer, event); Log.notice(TAG_HASP, buffer, event);
return; return;
default: default:
strcat_P(buffer, PSTR("HASP : Unknown Event occured")); strcat_P(buffer, PSTR("HASP : Unknown Event occured"));
Log.warning(buffer, event); Log.warning(TAG_HASP, buffer, event);
return; return;
} }
@ -725,11 +729,11 @@ void haspClearPage(uint16_t pageid)
{ {
lv_obj_t * page = get_page_obj(pageid); lv_obj_t * page = get_page_obj(pageid);
if(!page || pageid > 255) { 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()*/) { } 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 { } else {
Log.notice(F("HASP: Clearing page %u"), pageid); Log.notice(TAG_HASP, F("Clearing page %u"), pageid);
lv_obj_clean(pages[pageid]); lv_obj_clean(pages[pageid]);
} }
} }
@ -743,12 +747,12 @@ void haspSetPage(uint8_t pageid)
{ {
lv_obj_t * page = get_page_obj(pageid); lv_obj_t * page = get_page_obj(pageid);
if(!page) { 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()) { } 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 { } else {
// if(pageid != current_page) { // 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; current_page = pageid;
lv_scr_load(page); lv_scr_load(page);
//} //}
@ -779,7 +783,7 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
/* Page selection */ /* Page selection */
lv_obj_t * page = get_page_obj(pageid); lv_obj_t * page = get_page_obj(pageid);
if(!page) { if(!page) {
Log.warning(F("HASP: Page ID %u not defined"), pageid); Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid);
return; return;
} }
/* save the current pageid */ /* 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<uint8_t>(); uint8_t parentid = config[F("parentid")].as<uint8_t>();
parent_obj = hasp_find_obj_from_id(page, parentid); parent_obj = hasp_find_obj_from_id(page, parentid);
if(!parent_obj) { 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 ?? parent_obj = page; // create on the page instead ??
} else { } 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*/ /* Define Objects*/
lv_obj_t * obj = hasp_find_obj_from_id(parent_obj, id); lv_obj_t * obj = hasp_find_obj_from_id(parent_obj, id);
if(obj) { if(obj) {
Log.warning(F("HASP: Object ID %u already exists!"), id); Log.warning(TAG_HASP, F("Object ID %u already exists!"), id);
return; return;
} }
@ -950,12 +954,12 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
/* ----- Other Object ------ */ /* ----- Other Object ------ */
default: default:
Log.warning(F("HASP: Unsupported Object ID %u"), objid); Log.warning(TAG_HASP, F("Unsupported Object ID %u"), objid);
return; return;
} }
if(!obj) { if(!obj) {
Log.warning(F("HASP: Object is NULL, skipping...")); Log.warning(TAG_HASP, F("Object is NULL, skipping..."));
return; return;
} }
@ -971,27 +975,27 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
for(JsonPair keyValue : config) { for(JsonPair keyValue : config) {
v = keyValue.value().as<String>(); v = keyValue.value().as<String>();
hasp_process_obj_attribute(obj, keyValue.key().c_str(), v.c_str(), true); 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 **/ /** testing start **/
lv_obj_user_data_t temp; lv_obj_user_data_t temp;
if(!FindIdFromObj(obj, &pageid, &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; return;
} }
/** testing end **/ /** testing end **/
lv_obj_type_t list; lv_obj_type_t list;
lv_obj_get_type(obj, &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 */ /* Double-check */
lv_obj_t * test = hasp_find_obj_from_id(pageid, (uint8_t)temp); lv_obj_t * test = hasp_find_obj_from_id(pageid, (uint8_t)temp);
if(test != obj) { if(test != obj) {
Log.error(F("HASP: Objects DO NOT match!")); Log.error(TAG_HASP, F("Objects DO NOT match!"));
} else { } 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(pages[0] == '\0') return;
if(!SPIFFS.begin()) { 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; return;
} }
if(!SPIFFS.exists(pages)) { if(!SPIFFS.exists(pages)) {
Log.error(F("HASP: Non existing file %s"), pages); Log.error(TAG_HASP, F("Non existing file %s"), pages);
return; return;
} }
Log.notice(F("HASP: Loading file %s"), pages); Log.notice(TAG_HASP, F("Loading file %s"), pages);
File file = SPIFFS.open(pages, "r"); File file = SPIFFS.open(pages, "r");
dispatchParseJsonl(file); dispatchParseJsonl(file);
file.close(); file.close();
Log.notice(F("HASP: File %s loaded"), pages); Log.notice(TAG_HASP, F("File %s loaded"), pages);
#else #else
#if HASP_USE_EEPROM > 0 #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); EepromStream eepromStream(4096, 1024);
dispatchJsonl(eepromStream); dispatchJsonl(eepromStream);
Log.notice(F("HASP: Loaded jsonl from EEPROM")); Log.notice(TAG_HASP, F("Loaded jsonl from EEPROM"));
#endif #endif
#endif #endif

View File

@ -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 r = (LV_COLOR_GET_R(color) * 263 + 7) >> 5;
// uint8_t g = (LV_COLOR_GET_G(color) * 259 + 3) >> 6; // uint8_t g = (LV_COLOR_GET_G(color) * 259 + 3) >> 6;
// uint8_t b = (LV_COLOR_GET_B(color) * 263 + 7) >> 5; // 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; return color;
} }
@ -114,7 +114,7 @@ static lv_color_t haspPayloadToColor(const char * payload)
} }
/* Unknown format */ /* Unknown format */
Log.warning(F("Invalid color %s"), payload); Log.warning(TAG_ATTR, F("Invalid color %s"), payload);
return LV_COLOR_BLACK; 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"))) { } else if(!strcasecmp_P(payload, PSTR("loop"))) {
mode = LV_LABEL_LONG_SROLL_CIRC; mode = LV_LABEL_LONG_SROLL_CIRC;
} else { } else {
return Log.warning(F("Invalid long mode")); return Log.warning(TAG_ATTR, F("Invalid long mode"));
} }
lv_label_set_long_mode(obj, mode); lv_label_set_long_mode(obj, mode);
} else { } else {
@ -186,10 +186,10 @@ lv_obj_t * FindButtonLabel(lv_obj_t * btn)
} }
} else { } else {
Log.error(F("HASP: FindButtonLabel NULL Pointer encountered")); Log.error(TAG_ATTR, F("HASP: FindButtonLabel NULL Pointer encountered"));
} }
} else { } else {
Log.warning(F("HASP: Button not defined")); Log.warning(TAG_ATTR, F("HASP: Button not defined"));
} }
return NULL; 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) static inline bool haspGetLabelText(lv_obj_t * obj, char * text)
{ {
if(!obj) { if(!obj) {
Log.warning(F("HASP: Button not defined")); Log.warning(TAG_ATTR, F("HASP: Button not defined"));
return false; return false;
} }
@ -222,7 +222,7 @@ static inline bool haspGetLabelText(lv_obj_t * obj, char * text)
} }
} else { } else {
Log.warning(F("HASP: haspGetLabelText NULL Pointer encountered")); Log.warning(TAG_ATTR, F("HASP: haspGetLabelText NULL Pointer encountered"));
} }
return false; return false;
@ -420,7 +420,7 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
if(font) { if(font) {
return lv_obj_set_style_local_text_font(obj, part, state, font); return lv_obj_set_style_local_text_font(obj, part, state, font);
} else { } 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) { if(font) {
return lv_obj_set_style_local_value_font(obj, part, state, font); return lv_obj_set_style_local_value_font(obj, part, state, font);
} else { } 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 */ /* Transition attributes */
// Todo // Todo
} }
Log.warning(F("HASP: Unknown property %s"), attr_p); Log.warning(TAG_ATTR, F("HASP: Unknown property %s"), attr_p);
} }
// OK // 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)) { if(check_obj_type(objtype, LV_HASP_CHECKBOX)) {
return update ? lv_checkbox_set_checked(obj, is_true(payload)) return update ? lv_checkbox_set_checked(obj, is_true(payload))
: hasp_out_int(obj, attr, lv_checkbox_is_checked(obj)); : hasp_out_int(obj, attr, lv_checkbox_is_checked(obj));
} }
if(check_obj_type(objtype, LV_HASP_SWITCH)) { if(check_obj_type(objtype, LV_HASP_SWITCH)) {
if(update) { if(update) {
@ -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) void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update)
{ {
unsigned long start = millis(); 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); int16_t val = atoi(payload);
char * attr = (char *)attr_p; char * attr = (char *)attr_p;
if(*attr == '.') attr++; // strip leading '.' if(*attr == '.') attr++; // strip leading '.'
uint16_t attr_hash = sdbm(attr); 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 */ /* 16-bit Hash Lookup Table */
switch(attr_hash) { 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); 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);
} }
/* ************************** /* **************************

View File

@ -28,9 +28,9 @@
void confDebugSet(const char * name) void confDebugSet(const char * name)
{ {
/*char buffer[128]; /*char buffer[128];
snprintf(buffer, sizeof(buffer), PSTR("CONF: * %s set"), name); snprintf(buffer, sizeof(buffer), PSTR(" * %s set"), name);
debugPrintln(buffer);*/ 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) bool configSet(int8_t & value, const JsonVariant & setting, const char * name)
@ -75,15 +75,15 @@ void configStartDebug(bool setupdebug, String & configFile)
if(setupdebug) { if(setupdebug) {
debugStart(); // Debug started, now we can use it; HASP header sent debugStart(); // Debug started, now we can use it; HASP header sent
#if HASP_USE_SPIFFS > 0 #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(); spiffsInfo();
spiffsList(); spiffsList();
#endif #endif
} }
#if HASP_USE_SPIFFS > 0 #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 #else
Log.notice(F("CONF: reading EEPROM")); Log.notice(TAG_CONF, F("reading EEPROM"));
#endif #endif
} }
@ -100,7 +100,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
if(file) { if(file) {
size_t size = file.size(); size_t size = file.size();
if(size > 1024) { 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; return;
} }
@ -121,8 +121,8 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
output.replace(settings[F("http")][F("pass")].as<String>(), passmask); output.replace(settings[F("http")][F("pass")].as<String>(), passmask);
output.replace(settings[F("mqtt")][F("pass")].as<String>(), passmask); output.replace(settings[F("mqtt")][F("pass")].as<String>(), passmask);
output.replace(settings[F("wifi")][F("pass")].as<String>(), passmask); output.replace(settings[F("wifi")][F("pass")].as<String>(), passmask);
Log.verbose(F("CONF: %s"), output.c_str()); Log.verbose(TAG_CONF, output.c_str());
Log.notice(F("CONF: [SUCCESS] Loaded %s"), configFile.c_str()); Log.notice(TAG_CONF, F("[SUCCESS] Loaded %s"), configFile.c_str());
if(setupdebug) debugSetup(); if(setupdebug) debugSetup();
return; return;
@ -144,7 +144,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
configStartDebug(setupdebug, configFile); configStartDebug(setupdebug, configFile);
#if HASP_USE_SPIFFS > 0 #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 #endif
} }
/* /*
@ -172,7 +172,7 @@ void configBackupToEeprom()
file.close(); file.close();
EEPROM.commit(); EEPROM.commit();
Log.verbose(F("CONF: Written %u to EEPROM"), index); Log.verbose(TAG_CONF,F("Written %u to EEPROM"), index);
} }
#endif #endif
} }
@ -183,11 +183,15 @@ void configWriteConfig()
configFile.reserve(128); configFile.reserve(128);
configFile = String(FPSTR(HASP_CONFIG_FILE)); configFile = String(FPSTR(HASP_CONFIG_FILE));
String settingsChanged((char *)0);
settingsChanged.reserve(128);
settingsChanged = F("Settings changed!");
/* Read Config File */ /* Read Config File */
DynamicJsonDocument doc(8 * 256); 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); 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 // Make sure we have a valid JsonObject to start from
JsonObject settings; JsonObject settings;
@ -204,7 +208,7 @@ void configWriteConfig()
if(settings[F("wifi")].as<JsonObject>().isNull()) settings.createNestedObject(F("wifi")); if(settings[F("wifi")].as<JsonObject>().isNull()) settings.createNestedObject(F("wifi"));
changed = wifiGetConfig(settings[F("wifi")]); changed = wifiGetConfig(settings[F("wifi")]);
if(changed) { if(changed) {
Log.verbose(F("WIFI: Settings changed")); Log.verbose(TAG_WIFI, settingsChanged.c_str());
writefile = true; writefile = true;
} }
#endif #endif
@ -212,7 +216,7 @@ void configWriteConfig()
if(settings[F("mqtt")].as<JsonObject>().isNull()) settings.createNestedObject(F("mqtt")); if(settings[F("mqtt")].as<JsonObject>().isNull()) settings.createNestedObject(F("mqtt"));
changed = mqttGetConfig(settings[F("mqtt")]); changed = mqttGetConfig(settings[F("mqtt")]);
if(changed) { if(changed) {
Log.verbose(F("MQTT: Settings changed")); Log.verbose(TAG_MQTT, settingsChanged.c_str());
configOutput(settings[F("mqtt")]); configOutput(settings[F("mqtt")]);
writefile = true; writefile = true;
} }
@ -221,7 +225,7 @@ void configWriteConfig()
if(settings[F("telnet")].as<JsonObject>().isNull()) settings.createNestedObject(F("telnet")); if(settings[F("telnet")].as<JsonObject>().isNull()) settings.createNestedObject(F("telnet"));
changed = telnetGetConfig(settings[F("telnet")]); changed = telnetGetConfig(settings[F("telnet")]);
if(changed) { if(changed) {
Log.verbose(F("TELNET: Settings changed")); Log.verbose(TAG_TELN, settingsChanged.c_str());
configOutput(settings[F("telnet")]); configOutput(settings[F("telnet")]);
writefile = true; writefile = true;
} }
@ -230,7 +234,7 @@ void configWriteConfig()
if(settings[F("mdns")].as<JsonObject>().isNull()) settings.createNestedObject(F("mdns")); if(settings[F("mdns")].as<JsonObject>().isNull()) settings.createNestedObject(F("mdns"));
changed = mdnsGetConfig(settings[F("mdns")]); changed = mdnsGetConfig(settings[F("mdns")]);
if(changed) { if(changed) {
Log.verbose(F("MDNS: Settings changed")); Log.verbose(TAG_MDNS, settingsChanged.c_str());
writefile = true; writefile = true;
} }
#endif #endif
@ -238,7 +242,7 @@ void configWriteConfig()
if(settings[F("http")].as<JsonObject>().isNull()) settings.createNestedObject(F("http")); if(settings[F("http")].as<JsonObject>().isNull()) settings.createNestedObject(F("http"));
changed = httpGetConfig(settings[F("http")]); changed = httpGetConfig(settings[F("http")]);
if(changed) { if(changed) {
Log.verbose(F("HTTP: Settings changed")); Log.verbose(TAG_HTTP, settingsChanged.c_str());
configOutput(settings[F("http")]); configOutput(settings[F("http")]);
writefile = true; writefile = true;
} }
@ -247,7 +251,7 @@ void configWriteConfig()
if(settings[F("gpio")].as<JsonObject>().isNull()) settings.createNestedObject(F("gpio")); if(settings[F("gpio")].as<JsonObject>().isNull()) settings.createNestedObject(F("gpio"));
changed = gpioGetConfig(settings[F("gpio")]); changed = gpioGetConfig(settings[F("gpio")]);
if(changed) { if(changed) {
Log.verbose(F("GPIO: Settings changed")); Log.verbose(TAG_GPIO, settingsChanged.c_str());
configOutput(settings[F("gpio")]); configOutput(settings[F("gpio")]);
writefile = true; writefile = true;
} }
@ -256,21 +260,21 @@ void configWriteConfig()
if(settings[F("debug")].as<JsonObject>().isNull()) settings.createNestedObject(F("debug")); if(settings[F("debug")].as<JsonObject>().isNull()) settings.createNestedObject(F("debug"));
changed = debugGetConfig(settings[F("debug")]); changed = debugGetConfig(settings[F("debug")]);
if(changed) { if(changed) {
Log.verbose(F("DEBUG: Settings changed")); Log.verbose(TAG_DEBG, settingsChanged.c_str());
writefile = true; writefile = true;
} }
if(settings[F("gui")].as<JsonObject>().isNull()) settings.createNestedObject(F("gui")); if(settings[F("gui")].as<JsonObject>().isNull()) settings.createNestedObject(F("gui"));
changed = guiGetConfig(settings[F("gui")]); changed = guiGetConfig(settings[F("gui")]);
if(changed) { if(changed) {
Log.verbose(F("GUI: Settings changed")); Log.verbose(TAG_GUI,settingsChanged.c_str());
writefile = true; writefile = true;
} }
if(settings[F("hasp")].as<JsonObject>().isNull()) settings.createNestedObject(F("hasp")); if(settings[F("hasp")].as<JsonObject>().isNull()) settings.createNestedObject(F("hasp"));
changed = haspGetConfig(settings[F("hasp")]); changed = haspGetConfig(settings[F("hasp")]);
if(changed) { if(changed) {
Log.verbose(F("HASP: Settings changed")); Log.verbose(TAG_HASP, settingsChanged.c_str());
writefile = true; writefile = true;
} }
@ -280,22 +284,22 @@ void configWriteConfig()
#if HASP_USE_SPIFFS > 0 #if HASP_USE_SPIFFS > 0
File file = SPIFFS.open(configFile, "w"); File file = SPIFFS.open(configFile, "w");
if(file) { 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); size_t size = serializeJson(doc, file);
file.close(); file.close();
if(size > 0) { 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(); // configBackupToEeprom();
} else { } 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 { } 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 #endif
// Method 1 // Method 1
// Log.verbose(F("CONF: Writing to EEPROM")); // Log.verbose(TAG_CONF,F("Writing to EEPROM"));
// EepromStream eepromStream(0, 1024); // EepromStream eepromStream(0, 1024);
// WriteBufferingStream bufferedWifiClient{eepromStream, 512}; // WriteBufferingStream bufferedWifiClient{eepromStream, 512};
// serializeJson(doc, bufferedWifiClient); // serializeJson(doc, bufferedWifiClient);
@ -304,7 +308,7 @@ void configWriteConfig()
#if defined(STM32F4xx) #if defined(STM32F4xx)
// Method 2 // Method 2
Log.verbose(F("CONF: Writing to EEPROM")); Log.verbose(TAG_CONF, F("Writing to EEPROM"));
char buffer[1024 + 128]; char buffer[1024 + 128];
size_t size = serializeJson(doc, buffer, sizeof(buffer)); size_t size = serializeJson(doc, buffer, sizeof(buffer));
if(size > 0) { if(size > 0) {
@ -312,14 +316,14 @@ void configWriteConfig()
for(i = 0; i < size; i++) eeprom_buffered_write_byte(i, buffer[i]); for(i = 0; i < size; i++) eeprom_buffered_write_byte(i, buffer[i]);
eeprom_buffered_write_byte(i, 0); eeprom_buffered_write_byte(i, 0);
eeprom_buffer_flush(); eeprom_buffer_flush();
Log.verbose(F("CONF: [SUCCESS] Saved EEPROM")); Log.verbose(TAG_CONF, F("[SUCCESS] Saved EEPROM"));
} else { } else {
Log.error(F("CONF: Failed to save config to EEPROM")); Log.error(TAG_CONF, F("Failed to save config to EEPROM"));
} }
#endif #endif
} else { } else {
Log.notice(F("CONF: Configuration did not change")); Log.notice(TAG_CONF, F("Configuration did not change"));
} }
configOutput(settings); configOutput(settings);
} }
@ -342,7 +346,7 @@ void configSetup()
} else { } else {
#if HASP_USE_SPIFFS > 0 #if HASP_USE_SPIFFS > 0
if(!SPIFFS.begin()) { 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; return;
} }
#endif #endif
@ -350,40 +354,40 @@ void configSetup()
} }
//#if HASP_USE_SPIFFS > 0 //#if HASP_USE_SPIFFS > 0
Log.verbose(F("Loading debug settings")); Log.verbose(TAG_CONF, F("Loading debug settings"));
debugSetConfig(settings[F("debug")]); debugSetConfig(settings[F("debug")]);
Log.verbose(F("Loading GUI settings")); Log.verbose(TAG_CONF, F("Loading GUI settings"));
guiSetConfig(settings[F("gui")]); guiSetConfig(settings[F("gui")]);
Log.verbose(F("Loading HASP settings")); Log.verbose(TAG_CONF, F("Loading HASP settings"));
haspSetConfig(settings[F("hasp")]); haspSetConfig(settings[F("hasp")]);
// otaGetConfig(settings[F("ota")]); // otaGetConfig(settings[F("ota")]);
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
Log.verbose(F("Loading WiFi settings")); Log.verbose(TAG_CONF, F("Loading WiFi settings"));
wifiSetConfig(settings[F("wifi")]); wifiSetConfig(settings[F("wifi")]);
#endif #endif
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
Log.verbose(F("Loading MQTT settings")); Log.verbose(TAG_CONF, F("Loading MQTT settings"));
mqttSetConfig(settings[F("mqtt")]); mqttSetConfig(settings[F("mqtt")]);
#endif #endif
#if HASP_USE_TELNET > 0 #if HASP_USE_TELNET > 0
Log.verbose(F("Loading Telnet settings")); Log.verbose(TAG_CONF, F("Loading Telnet settings"));
telnetSetConfig(settings[F("telnet")]); telnetSetConfig(settings[F("telnet")]);
#endif #endif
#if HASP_USE_MDNS > 0 #if HASP_USE_MDNS > 0
Log.verbose(F("Loading MDNS settings")); Log.verbose(TAG_CONF, F("Loading MDNS settings"));
mdnsSetConfig(settings[F("mdns")]); mdnsSetConfig(settings[F("mdns")]);
#endif #endif
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0
Log.verbose(F("Loading HTTP settings")); Log.verbose(TAG_CONF, F("Loading HTTP settings"));
httpSetConfig(settings[F("http")]); httpSetConfig(settings[F("http")]);
#endif #endif
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
Log.verbose(F("Loading GPIO settings")); Log.verbose(TAG_CONF, F("Loading GPIO settings"));
gpioSetConfig(settings[F("gpio")]); gpioSetConfig(settings[F("gpio")]);
#endif #endif
// } // }
Log.notice(F("User configuration loaded")); Log.notice(TAG_CONF, F("User configuration loaded"));
} }
//#endif //#endif
} }
@ -430,13 +434,13 @@ void configOutput(const JsonObject & settings)
output.replace(password, passmask); output.replace(password, passmask);
} }
Log.trace(F("CONF: %s"), output.c_str()); Log.trace(TAG_CONF, output.c_str());
} }
bool configClear() bool configClear()
{ {
#if defined(STM32F4xx) #if defined(STM32F4xx)
Log.verbose(F("CONF: Clearing EEPROM")); Log.verbose(TAG_CONF, F("Clearing EEPROM"));
char buffer[1024 + 128]; char buffer[1024 + 128];
memset(buffer, 1, sizeof(buffer)); memset(buffer, 1, sizeof(buffer));
if(sizeof(buffer) > 0) { if(sizeof(buffer) > 0) {
@ -444,10 +448,10 @@ bool configClear()
for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]); for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]);
eeprom_buffered_write_byte(i, 0); eeprom_buffered_write_byte(i, 0);
eeprom_buffer_flush(); eeprom_buffer_flush();
Log.verbose(F("CONF: [SUCCESS] Cleared EEPROM")); Log.verbose(TAG_CONF, F("[SUCCESS] Cleared EEPROM"));
return true; return true;
} else { } else {
Log.error(F("CONF: Failed to clear to EEPROM")); Log.error(TAG_CONF, F("Failed to clear to EEPROM"));
return false; return false;
} }
#elif HASP_USE_SPIFFS > 0 #elif HASP_USE_SPIFFS > 0

View File

@ -56,7 +56,7 @@
// static String debugOutput((char *)0); // static String debugOutput((char *)0);
// static StringStream debugStream((String &)debugOutput); // static StringStream debugStream((String &)debugOutput);
extern char mqttNodeName[16]; // extern char mqttNodeName[16];
const char * syslogAppName = APP_NAME; const char * syslogAppName = APP_NAME;
char debugSyslogHost[32] = SYSLOG_SERVER; char debugSyslogHost[32] = SYSLOG_SERVER;
uint16_t debugSyslogPort = SYSLOG_PORT; uint16_t debugSyslogPort = SYSLOG_PORT;
@ -64,12 +64,13 @@ uint8_t debugSyslogFacility = 0;
uint8_t debugSyslogProtocol = 0; uint8_t debugSyslogProtocol = 0;
// A UDP instance to let us send and receive packets over UDP // 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 // Create a new syslog instance with LOG_KERN facility
// Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN); // Syslog syslog(syslogClient, SYSLOG_SERVER, SYSLOG_PORT, MQTT_CLIENT, APP_NAME, LOG_KERN);
// Create a new empty syslog instance // Create a new empty syslog instance
Syslog * syslog; // Syslog * syslog;
#endif // USE_SYSLOG #endif // USE_SYSLOG
// Serial Settings // Serial Settings
@ -116,33 +117,43 @@ void debugStart()
{ {
if(debugSerialStarted) { if(debugSerialStarted) {
Serial.flush(); Serial.flush();
Serial.println(); // Serial.println();
Serial.println(debugHaspHeader()); // Serial.println(debugHaspHeader());
Serial.flush(); // Serial.flush();
} }
// prepare syslog configuration here (can be anywhere before first call of // prepare syslog configuration here (can be anywhere before first call of
// log/logf method) // log/logf method)
} }
#if HASP_USE_SYSLOG > 0 // #if HASP_USE_SYSLOG > 0
void syslogSend(uint8_t priority, const char * debugText) // void syslogSend(uint8_t priority, const char * debugText)
{ // {
if(strlen(debugSyslogHost) != 0 && WiFi.isConnected()) { // if(strlen(debugSyslogHost) != 0 && WiFi.isConnected()) {
syslog->log(priority, debugText); // syslog->log(priority, debugText);
} // }
} // }
#endif // #endif
void debugSetup() void debugSetup()
{ {
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD); // syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD);
syslog->server(debugSyslogHost, debugSyslogPort); // syslog->server(debugSyslogHost, debugSyslogPort);
syslog->deviceHostname(mqttNodeName); // syslog->deviceHostname(mqttNodeName);
syslog->appName(syslogAppName); // syslog->appName(syslogAppName);
uint16_t priority = (uint16_t)(debugSyslogFacility + 16) << 3; // localx facility, x = 0-7 // uint16_t priority = (uint16_t)(debugSyslogFacility + 16) << 3; // localx facility, x = 0-7
syslog->defaultPriority(priority); // 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 #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); debugPrintTimestamp(level, _logOutput);
debugPrintHaspMemory(level, _logOutput); debugPrintHaspMemory(level, _logOutput);
#if LV_MEM_CUSTOM == 0 #if LV_MEM_CUSTOM == 0
debugPrintLvglMemory(level, _logOutput); debugPrintLvglMemory(level, _logOutput);
#endif #endif
debugPrintPriority(level, _logOutput); 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) if(debugAnsiCodes)
_logOutput->println(F(TERM_COLOR_RESET)); _logOutput->println(F(TERM_COLOR_RESET));
@ -325,6 +468,10 @@ void debugPrintSuffix(int level, Print * _logOutput)
_logOutput->println(); _logOutput->println();
if(debugAnsiCodes) _logOutput->print(F(TERM_COLOR_MAGENTA)); if(debugAnsiCodes) _logOutput->print(F(TERM_COLOR_MAGENTA));
if(_logOutput == syslogClient && strlen(debugSyslogHost) > 0) {
syslogClient->endPacket();
}
// syslogSend(level, debugOutput); // syslogSend(level, debugOutput);
} }
@ -351,8 +498,14 @@ void debugPreSetup(JsonObject settings)
delay(10); delay(10);
Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true); Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true);
debugSerialStarted = true; debugSerialStarted = true;
// Print Header
Serial.println(); 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) { if(line != lastDbgLine || mem_mon.free_biggest_size != lastDbgFree) {
switch(level) { switch(level) {
case LV_LOG_LEVEL_TRACE: case LV_LOG_LEVEL_TRACE:
Log.trace(descr); Log.trace(TAG_LVGL, descr);
break; break;
case LV_LOG_LEVEL_WARN: case LV_LOG_LEVEL_WARN:
Log.warning(descr); Log.warning(TAG_LVGL, descr);
break; break;
case LV_LOG_LEVEL_ERROR: case LV_LOG_LEVEL_ERROR:
Log.error(descr); Log.error(TAG_LVGL, descr);
break; break;
default: default:
Log.notice(descr); Log.notice(TAG_LVGL, descr);
} }
lastDbgLine = line; lastDbgLine = line;
lastDbgFree = mem_mon.free_biggest_size; lastDbgFree = mem_mon.free_biggest_size;

View File

@ -4,6 +4,43 @@
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "lvgl.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); String debugHaspHeader(void);
void debugPreSetup(JsonObject settings); void debugPreSetup(JsonObject settings);

View File

@ -54,7 +54,7 @@ void dispatchGpioOutput(int output, bool state)
int pin = 0; int pin = 0;
if(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) #if defined(ARDUINO_ARCH_ESP32)
ledcWrite(99, state ? 1023 : 0); // ledChannel and value ledcWrite(99, state ? 1023 : 0); // ledChannel and value
@ -89,7 +89,7 @@ void dispatchParseJson(char * payload)
// haspCommands.shrinkToFit(); // haspCommands.shrinkToFit();
if(jsonError) { // Couldn't parse incoming JSON command 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 { } else {
JsonArray arr = haspCommands.as<JsonArray>(); JsonArray arr = haspCommands.as<JsonArray>();
@ -104,7 +104,7 @@ void dispatchParseJsonl(Stream & stream)
DynamicJsonDocument jsonl(3 * 128u); DynamicJsonDocument jsonl(3 * 128u);
uint8_t savedPage = haspGetPage(); uint8_t savedPage = haspGetPage();
// Log.notice(F("DISPATCH: jsonl")); // Log.notice(TAG_MSGR,F("DISPATCH: jsonl"));
while(deserializeJson(jsonl, stream) == DeserializationError::Ok) { while(deserializeJson(jsonl, stream) == DeserializationError::Ok) {
// serializeJson(jsonl, Serial); // serializeJson(jsonl, Serial);
@ -122,7 +122,7 @@ void dispatchParseJsonl(char * payload)
// p[x].b[y]=value // p[x].b[y]=value
inline void dispatch_process_button_attribute(String strTopic, const char * payload) 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 strPageId((char *)0);
String strTemp((char *)0); String strTemp((char *)0);
@ -219,7 +219,7 @@ void dispatchCommand(const char * topic, const char * payload)
if(strlen(payload) == 0) { if(strlen(payload) == 0) {
// dispatchTextLine(topic); // Could cause an infinite loop! // 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 // Strip command/config prefix from the topic and process the payload
void dispatchTopicPayload(const char * topic, const char * 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"))) { if(!strcmp_P(topic, PSTR("command"))) {
dispatchTextLine((char *)payload); dispatchTextLine((char *)payload);
@ -306,7 +306,7 @@ void dispatchTopicPayload(const char * topic, const char * payload)
if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/ if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/
topic += 8u; 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"' == // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' ==
// nextionSetAttr("p[1].b[4].txt", "\"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) void dispatch_output_idle_state(const char * state)
{ {
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) #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 #else
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
@ -398,8 +398,8 @@ void dispatchReboot(bool saveConfig)
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
wifiStop(); wifiStop();
#endif #endif
Log.verbose(F("-------------------------------------")); Log.verbose(TAG_MSGR,F("-------------------------------------"));
Log.notice(F("STOP: Properly Rebooting the MCU now!")); Log.notice(TAG_MSGR,F("STOP: Properly Rebooting the MCU now!"));
Serial.flush(); Serial.flush();
halRestart(); halRestart();
} }
@ -407,7 +407,7 @@ void dispatchReboot(bool saveConfig)
void dispatch_button(uint8_t id, const char * event) void dispatch_button(uint8_t id, const char * event)
{ {
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) #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 #else
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
mqtt_send_input(id, event); 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 // send out value
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) #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 #else
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
// mqtt_send_input(id, event); // 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) 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) #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 #else
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
mqtt_send_obj_attribute_str(pageid, btnid, attribute, data); 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) void dispatchWebUpdate(const char * espOtaUrl)
{ {
#if HASP_USE_OTA > 0 #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); otaHttpUpdate(espOtaUrl);
#endif #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) 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) #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 #else
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
mqtt_send_obj_attribute_str(pageid, btnid, attribute, data); mqtt_send_obj_attribute_str(pageid, btnid, attribute, data);
@ -556,7 +556,7 @@ void dispatchConfig(const char * topic, const char * payload)
} else { } else {
DeserializationError jsonError = deserializeJson(doc, payload); DeserializationError jsonError = deserializeJson(doc, payload);
if(jsonError) { // Couldn't parse incoming JSON command 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; return;
} }
settings = doc.as<JsonObject>(); settings = doc.as<JsonObject>();
@ -626,7 +626,7 @@ void dispatchConfig(const char * topic, const char * payload)
settings.remove(F("pass")); // hide password in output settings.remove(F("pass")); // hide password in output
size_t size = serializeJson(doc, buffer, sizeof(buffer)); size_t size = serializeJson(doc, buffer, sizeof(buffer));
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE) #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 #else
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
mqtt_send_state(F("config"), buffer); mqtt_send_state(F("config"), buffer);

View File

@ -13,15 +13,15 @@ void ethernetSetup()
{ {
#if USE_BUILTIN_ETHERNET > 0 #if USE_BUILTIN_ETHERNET > 0
// start Ethernet and UDP // start Ethernet and UDP
Log.notice(F("ETH: Begin Ethernet LAN8720")); Log.notice(TAG_ETH, F("Begin Ethernet LAN8720"));
if(Ethernet.begin() == 0) { 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 { } else {
ip = Ethernet.localIP(); 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 #else
byte mac[6]; byte mac[6];
@ -34,18 +34,18 @@ void ethernetSetup()
mac[5] = (baseUID & 0x000000FF); mac[5] = (baseUID & 0x000000FF);
char ethHostname[12]; 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]); snprintf(ethHostname, sizeof(ethHostname), PSTR("HASP-%02x%02x%02x"), mac[3], mac[4], mac[5]);
Ethernet.setCsPin(W5500_CS); Ethernet.setCsPin(W5500_CS);
Ethernet.setRstPin(W5500_RST); Ethernet.setRstPin(W5500_RST);
Ethernet.setHostname(ethHostname); Ethernet.setHostname(ethHostname);
Log.notice(F("ETH: Begin Ethernet W5500")); Log.notice(TAG_ETH, F("Begin Ethernet W5500"));
if(Ethernet.begin(mac) == 0) { 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 { } else {
ip = Ethernet.localIP(); 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 #endif
} }
@ -55,24 +55,24 @@ void ethernetLoop(void)
switch(Ethernet.maintain()) { switch(Ethernet.maintain()) {
case 1: case 1:
// renewed fail // renewed fail
Log.notice(F("ETH: Error: renewed fail")); Log.notice(TAG_ETH, F("Error: renewed fail"));
break; break;
case 2: case 2:
// renewed success // renewed success
ip = Ethernet.localIP(); 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; break;
case 3: case 3:
// rebind fail // rebind fail
Log.notice(F("Error: rebind fail")); Log.notice(TAG_ETH, F("Error: rebind fail"));
break; break;
case 4: case 4:
// rebind success // rebind success
ip = Ethernet.localIP(); 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; break;
default: default:
@ -89,7 +89,7 @@ bool ethernetEvery5Seconds()
#else #else
state = Ethernet.link() == 1; state = Ethernet.link() == 1;
#endif #endif
Log.warning(F("ETH: %s"), state ? F("ONLINE") : F("OFFLINE")); Log.warning(TAG_ETH, state ? F("ONLINE") : F("OFFLINE"));
return state; return state;
} }

View File

@ -10,31 +10,31 @@ IPAddress ip;
void EthernetEvent(WiFiEvent_t event) void EthernetEvent(WiFiEvent_t event)
{ {
switch (event) { switch(event) {
case SYSTEM_EVENT_ETH_START: case SYSTEM_EVENT_ETH_START:
Log.notice(F(LOG_ETH_CTR "Started")); Log.notice(TAG_ETH, F("Started"));
//set eth hostname here // set eth hostname here
ETH.setHostname("esp32-ethernet"); ETH.setHostname("esp32-ethernet");
break; break;
case SYSTEM_EVENT_ETH_CONNECTED: case SYSTEM_EVENT_ETH_CONNECTED:
Log.notice(F(LOG_ETH_CTR "Connected")); Log.notice(TAG_ETH, F("Connected"));
break; break;
case SYSTEM_EVENT_ETH_GOT_IP: case SYSTEM_EVENT_ETH_GOT_IP:
Log.notice(F(LOG_ETH_CTR "MAC Address %s"), ETH.macAddress().c_str()); Log.notice(TAG_ETH, F("MAC Address %s"), ETH.macAddress().c_str());
ip = ETH.localIP(); ip = ETH.localIP();
Log.notice(F(LOG_ETH_CTR "IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); Log.notice(TAG_ETH, F("IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
if (ETH.fullDuplex()) { if(ETH.fullDuplex()) {
Log.notice(F(LOG_ETH_CTR "FULL_DUPLEX")); Log.notice(TAG_ETH, F("FULL_DUPLEX"));
} }
Log.notice(F(LOG_ETH_CTR "LINK_SPEED %d Mbps"), ETH.linkSpeed()); Log.notice(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed());
eth_connected = true; eth_connected = true;
break; break;
case SYSTEM_EVENT_ETH_DISCONNECTED: case SYSTEM_EVENT_ETH_DISCONNECTED:
Log.notice(F(LOG_ETH_CTR "Disconnected")); Log.notice(TAG_ETH, F("Disconnected"));
eth_connected = false; eth_connected = false;
break; break;
case SYSTEM_EVENT_ETH_STOP: case SYSTEM_EVENT_ETH_STOP:
Log.notice(F(LOG_ETH_CTR "Stopped")); Log.notice(TAG_ETH, F("Stopped"));
eth_connected = false; eth_connected = false;
break; break;
default: default:
@ -48,17 +48,15 @@ void ethernetSetup()
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE); ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE);
} }
void ethernetLoop(void) void ethernetLoop(void)
{ {
// //
} }
bool ethernetEvery5Seconds() 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; return eth_connected;
} }
#endif #endif

View File

@ -1,8 +1,6 @@
#ifndef HASP_ETHERNET_ESP32_H #ifndef HASP_ETHERNET_ESP32_H
#define HASP_ETHERNET_ESP32_H #define HASP_ETHERNET_ESP32_H
#define LOG_ETH_CTR "ETH: "
static bool eth_connected = false; static bool eth_connected = false;
void ethernetSetup(); void ethernetSetup();

View File

@ -131,14 +131,14 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
buttonConfig->clearFeature( buttonConfig->clearFeature(
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses 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); input_mode, default_state);
gpioUsedInputCount = i + 1; gpioUsedInputCount = i + 1;
return; 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); HASP_NUM_INPUTS);
} }
@ -162,14 +162,14 @@ void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state,
buttonConfig->clearFeature( buttonConfig->clearFeature(
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses 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); input_mode, default_state);
gpioUsedInputCount = i + 1; gpioUsedInputCount = i + 1;
return; 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); 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].type = type;
gpioConfig[config_num].group = group; gpioConfig[config_num].group = group;
gpioConfig[config_num].gpio_function = pinfunc; 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); pinfunc);
return true; return true;
} }
@ -573,7 +573,7 @@ bool gpioGetConfig(const JsonObject & settings)
if(i < HASP_NUM_GPIO_CONFIG) { if(i < HASP_NUM_GPIO_CONFIG) {
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) | uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
(gpioConfig[i].gpio_function << 24); (gpioConfig[i].gpio_function << 24);
Log.verbose(F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as<uint32_t>()); Log.verbose(TAG_GPIO,F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as<uint32_t>());
if(cur_val != v.as<uint32_t>()) changed = true; if(cur_val != v.as<uint32_t>()) changed = true;
v.set(cur_val); v.set(cur_val);

View File

@ -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.x = touchX; // 20 + (disp->driver.hor_res - 40) * (touchCorner % 2);
// data->point.y = touchY; // 20 + (disp->driver.ver_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 // #endif
@ -301,9 +301,9 @@ void handleTouch(int8_t contacts, GTPoint * points)
GT911_num_touches = contacts; GT911_num_touches = contacts;
GT911_points = points; GT911_points = points;
Log.trace("Contacts: %d", contacts); Log.trace(TAG_GUI,"Contacts: %d", contacts);
for(uint8_t i = 0; i < contacts; i++) { 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(); yield();
} }
} }
@ -378,7 +378,7 @@ void GT911_setup()
touch.setHandler(handleTouch); touch.setHandler(handleTouch);
touchStart(); touchStart();
Log.verbose(F("Goodix GT911x touch driver started")); Log.verbose(TAG_GUI,F("Goodix GT911x touch driver started"));
} }
#endif #endif
@ -513,16 +513,16 @@ void guiSetup()
/* Dump TFT Configuration */ /* Dump TFT Configuration */
// tftSetup(tft); // tftSetup(tft);
#ifdef USE_DMA_TO_TFT #ifdef USE_DMA_TO_TFT
Log.verbose(F("TFT: DMA : ENABLED")); Log.verbose(TAG_GUI,F("DMA : ENABLED"));
#else #else
Log.verbose(F("TFT: DMA : DISABLED")); Log.verbose(TAG_GUI,F("DMA : DISABLED"));
#endif #endif
/* Load User Settings */ /* Load User Settings */
// guiSetConfig(settings); // guiSetConfig(settings);
/* Setup Backlight Control Pin */ /* Setup Backlight Control Pin */
if(guiBacklightPin >= 0) { 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) #if defined(ARDUINO_ARCH_ESP32)
// pinMode(guiBacklightPin, OUTPUT); // pinMode(guiBacklightPin, OUTPUT);
@ -535,16 +535,16 @@ void guiSetup()
#endif #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)); PSTR(LVGL_VERSION_INFO));
Log.verbose(F("LVGL: Rotation : %d"), guiRotation); Log.verbose(TAG_LVGL,F("Rotation : %d"), guiRotation);
#ifdef LV_MEM_SIZE #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 #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 #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 */ lv_log_register_print_cb(debugLvgl); /* register print function for debugging */
#endif #endif
@ -621,7 +621,7 @@ void guiSetup()
*/ */
/* Initialize mouse pointer */ /* Initialize mouse pointer */
/*// if(true) { /*// if(true) {
debugPrintln(PSTR("LVGL: Initialize Cursor")); debugPrintln(PSTR("Initialize Cursor"));
lv_obj_t * cursor; lv_obj_t * cursor;
lv_obj_t * mouse_layer = lv_disp_get_layer_sys(NULL); // default display lv_obj_t * mouse_layer = lv_disp_get_layer_sys(NULL); // default display
// cursor = lv_obj_create(lv_scr_act(), NULL); // 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<JsonArray>(); JsonArray array = settings[FPSTR(F_GUI_CALIBRATION)].as<JsonArray>();
uint8_t i = 0; uint8_t i = 0;
for(JsonVariant v : array) { for(JsonVariant v : array) {
Log.verbose(F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as<uint16_t>()); Log.verbose(TAG_GUI,F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as<uint16_t>());
if(i < 5) { if(i < 5) {
if(calData[i] != v.as<uint16_t>()) changed = true; if(calData[i] != v.as<uint16_t>()) changed = true;
v.set(calData[i]); v.set(calData[i]);
@ -798,7 +798,7 @@ bool guiSetConfig(const JsonObject & settings)
if(!settings[FPSTR(F_GUI_POINTER)].isNull()) { if(!settings[FPSTR(F_GUI_POINTER)].isNull()) {
if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) { if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) {
Log.trace(F("guiShowPointer set")); Log.trace(TAG_GUI,F("guiShowPointer set"));
} }
changed |= guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>(); changed |= guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>();
@ -819,11 +819,11 @@ bool guiSetConfig(const JsonObject & settings)
} }
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) { 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]); calData[4]);
oobeSetAutoCalibrate(false); oobeSetAutoCalibrate(false);
} else { } else {
Log.notice(F("First Touch Calibration enabled")); Log.notice(TAG_GUI,F("First Touch Calibration enabled"));
oobeSetAutoCalibrate(true); oobeSetAutoCalibrate(true);
} }
@ -900,7 +900,7 @@ static void gui_get_bitmap_header(uint8_t * buffer, size_t bufsize)
void gui_flush_not_complete() 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 #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); size_t len = pFileOut.write(buffer, 122);
if(len == 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 */ /* Refresh screen to screenshot callback */
lv_disp_t * disp = lv_disp_get_default(); 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 */ lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */
disp->driver.flush_cb = flush_cb; /* restore callback */ 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 { } 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(); pFileOut.close();
} else { } else {
Log.warning(F("GUI: %s cannot be opened"), pFileName); Log.warning(TAG_GUI,F("GUI: %s cannot be opened"), pFileName);
} }
} }
#endif #endif
@ -982,7 +982,7 @@ void guiTakeScreenshot()
gui_get_bitmap_header(buffer, sizeof(buffer)); gui_get_bitmap_header(buffer, sizeof(buffer));
if(httpClientWrite(buffer, 122) == 122) { 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 */ /* Refresh screen to screenshot callback */
lv_disp_t * disp = lv_disp_get_default(); 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 */ lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */
disp->driver.flush_cb = flush_cb; /* restore callback */ 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 { } 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 #endif

View File

@ -140,10 +140,10 @@ bool httpIsAuthenticated(const __FlashStringHelper * page)
} }
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #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()); webServer.client().remoteIP().toString().c_str());
#else #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()); // String(webServer.client().remoteIP()).c_str());
#endif #endif
@ -200,7 +200,7 @@ void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
contentLength += sizeof(HTTP_FOOTER) - 1; contentLength += sizeof(HTTP_FOOTER) - 1;
if(httpdatalength > HTTP_PAGE_SIZE) { 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); webServer.setContentLength(contentLength + httpdatalength);
@ -329,12 +329,17 @@ void webHandleScreenshot()
httpMessage += F("</h1><hr>"); httpMessage += F("</h1><hr>");
httpMessage += httpMessage +=
F("<script>function ref(a){ var timestamp=new Date().getTime();var el=document.getElementById('bmp');" F("<script>function aref(t){setTimeout(function() {ref('');}, t*1000)} function ref(a){ var t=new "
"el.src='?a='+a+'&q='+timestamp;return false;}</script>"); "Date().getTime();document.getElementById('bmp').src='?a='+a+'&q='+t;return false;}</script>");
httpMessage += F("<p class='c'><img id='bmp' src='?q=0'></p>"); httpMessage += F("<p class='c'><img id='bmp' src='?q=0'");
httpMessage += F(
"<p><form method='get' onsubmit=\"return ref('');\"><button type='submit'>Refresh</button></form></p>"); // Automatic refresh
httpMessage += F("<p><form method='get' onsubmit=\"return ref('prev');\"><button type='submit'>Previous " httpMessage += F(" onload=\"aref(5)\" onerror=\"aref(5)\"/></p>");
httpMessage += F("<p><form method='get' onsubmit=\"return ref('')\"><button "
"type='submit'>Refresh</button></form></p>");
httpMessage += F("<p><form method='get' onsubmit=\"return ref('prev');\"><button "
"type='submit'>Previous "
"Page</button></form></p>"); "Page</button></form></p>");
httpMessage += F("<p><form method='get' onsubmit=\"return ref('next');\"><button type='submit'>Next " httpMessage += F("<p><form method='get' onsubmit=\"return ref('next');\"><button type='submit'>Next "
"Page</button></form></p>"); "Page</button></form></p>");
@ -628,7 +633,7 @@ void webUploadProgress()
{ {
long t = webServer.header("Content-Length").toInt(); long t = webServer.header("Content-Length").toInt();
if(millis() - htppLastLoopTime >= 1250) { 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(); htppLastLoopTime = millis();
} }
if(t > 0) t = (upload->totalSize + upload->currentSize) * 100 / t; if(t > 0) t = (upload->totalSize + upload->currentSize) * 100 / t;
@ -642,13 +647,13 @@ void webUpdatePrintError()
output.reserve(128); output.reserve(128);
StringStream stream((String &)output); StringStream stream((String &)output);
Update.printError(stream); Update.printError(stream);
Log.error(F("HTTP: %s"), output.c_str()); Log.error(TAG_HTTP, output.c_str());
haspProgressMsg(output.c_str()); haspProgressMsg(output.c_str());
} }
void webUpdateReboot() 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); String httpMessage((char *)0);
@ -674,7 +679,7 @@ void webHandleFirmwareUpdate()
upload = &webServer.upload(); upload = &webServer.upload();
if(upload->status == UPLOAD_FILE_START) { if(upload->status == UPLOAD_FILE_START) {
if(!httpIsAuthenticated(F("update"))) return; 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()); haspProgressMsg(upload->filename.c_str());
// WiFiUDP::stopAll(); // WiFiUDP::stopAll();
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
@ -732,7 +737,7 @@ void handleFileUpload()
upload = &webServer.upload(); upload = &webServer.upload();
if(upload->status == UPLOAD_FILE_START) { if(upload->status == UPLOAD_FILE_START) {
if(!httpIsAuthenticated(F("fileupload"))) return; 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); String filename((char *)0);
filename.reserve(128); filename.reserve(128);
filename = upload->filename; filename = upload->filename;
@ -742,23 +747,23 @@ void handleFileUpload()
} }
if(filename.length() < 32) { if(filename.length() < 32) {
fsUploadFile = filesystem->open(filename, "w"); 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()); haspProgressMsg(fsUploadFile.name());
} else { } 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) { } else if(upload->status == UPLOAD_FILE_WRITE) {
// DBG_OUTPUT_PORT.print("handleFileUpload Data: "); debugPrintln(upload.currentSize); // DBG_OUTPUT_PORT.print("handleFileUpload Data: "); debugPrintln(upload.currentSize);
if(fsUploadFile) { if(fsUploadFile) {
if(fsUploadFile.write(upload->buf, upload->currentSize) != upload->currentSize) { 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 { } else {
webUploadProgress(); // Moved to httpEverySecond Loop webUploadProgress(); // Moved to httpEverySecond Loop
} }
} }
} else if(upload->status == UPLOAD_FILE_END) { } else if(upload->status == UPLOAD_FILE_END) {
if(fsUploadFile) { 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(); fsUploadFile.close();
} }
haspProgressVal(255); haspProgressVal(255);
@ -781,7 +786,7 @@ void handleFileDelete()
return webServer.send_P(500, mimetype, PSTR("BAD ARGS")); return webServer.send_P(500, mimetype, PSTR("BAD ARGS"));
} }
String path = webServer.arg(0); 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 == "/") { if(path == "/") {
return webServer.send_P(500, mimetype, PSTR("BAD 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")); return webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS"));
} }
String path = webServer.arg(0); 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 == "/") { if(path == "/") {
return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH")); return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH"));
} }
@ -828,7 +833,7 @@ void handleFileList()
} }
String path = webServer.arg(F("dir")); 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(); path.clear();
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
@ -1543,9 +1548,10 @@ void httpHandleNotFound()
#endif #endif
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #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 #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 #endif
String httpMessage((char *)0); String httpMessage((char *)0);
@ -1622,7 +1628,7 @@ void httpHandleEspFirmware()
} }
webSendFooter(); 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")); // espStartOta(webServer.arg("espFirmware"));
} }
@ -1684,9 +1690,9 @@ void webStart()
#if defined(STM32F4xx) #if defined(STM32F4xx)
IPAddress ip; IPAddress ip;
ip = WiFi.localIP(); 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 #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())); (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
#endif #endif
#else #else
@ -1696,7 +1702,7 @@ void webStart()
#else #else
ip = Ethernet.localIP(); ip = Ethernet.localIP();
#endif #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 #endif
} }
@ -1704,7 +1710,7 @@ void webStop()
{ {
webServer.stop(); webServer.stop();
webServerStarted = false; 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 HASP_USE_WIFI > 0
#if !defined(STM32F4xx) #if !defined(STM32F4xx)
if(WiFi.getMode() != WIFI_STA) { if(WiFi.getMode() != WIFI_STA) {
Log.notice(F("HTTP: Wifi access point")); Log.notice(TAG_HTTP, F("Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig); webServer.on(F("/"), webHandleWifiConfig);
} else { } else {
#endif #endif
@ -1745,7 +1751,7 @@ void httpSetup()
F("/edit"), HTTP_POST, F("/edit"), HTTP_POST,
[]() { []() {
webServer.send(200, "text/plain", ""); webServer.send(200, "text/plain", "");
Log.verbose(F("Headers: %d"), webServer.headers()); Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers());
}, },
handleFileUpload); handleFileUpload);
#endif #endif
@ -1792,7 +1798,7 @@ void httpSetup()
F("/update"), HTTP_POST, F("/update"), HTTP_POST,
[]() { []() {
webServer.send(200, "text/plain", ""); 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); webHandleFirmwareUpdate);
webServer.on(F("/espfirmware"), httpHandleEspFirmware); webServer.on(F("/espfirmware"), httpHandleEspFirmware);
@ -1815,7 +1821,7 @@ void httpSetup()
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *); size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);
webServer.collectHeaders(headerkeys, headerkeyssize); webServer.collectHeaders(headerkeys, headerkeyssize);
Log.verbose(F("HTTP: Setup Complete")); Log.verbose(TAG_HTTP, F("Setup Complete"));
webStart(); webStart();
} }

View File

@ -11,12 +11,13 @@
#include "hasp_conf.h" #include "hasp_conf.h"
#include "hasp_config.h" #include "hasp_config.h"
#include "hasp_debug.h"
#include "hasp_conf.h" #include "hasp_conf.h"
#if HASP_USE_MQTT>0 #if HASP_USE_MQTT > 0
#include "hasp_mqtt.h" #include "hasp_mqtt.h"
#endif #endif
#if HASP_USE_MDNS>0 #if HASP_USE_MDNS > 0
#include "hasp_mdns.h" #include "hasp_mdns.h"
#endif #endif
@ -25,7 +26,7 @@ uint8_t mdnsEnabled = true;
void mdnsSetup() void mdnsSetup()
{ {
// mdnsSetConfig(settings); // mdnsSetConfig(settings);
Log.verbose(F("MDNS: Setup Complete")); Log.verbose(TAG_MDNS, F("Setup Complete"));
} }
void mdnsStart() void mdnsStart()
@ -56,9 +57,9 @@ void mdnsStart()
addServiceTxt("arduino", "tcp", "ssh_upload", "no"); addServiceTxt("arduino", "tcp", "ssh_upload", "no");
addServiceTxt("arduino", "tcp", "board", ARDUINO_BOARD); addServiceTxt("arduino", "tcp", "board", ARDUINO_BOARD);
addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes" : "no");*/ addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes" : "no");*/
Log.notice(F("MDNS: Responder started")); Log.notice(TAG_MDNS, F("Responder started"));
} else { } 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 #endif

View File

@ -18,7 +18,7 @@ WiFiClient mqttNetworkClient;
#include <ESP.h> #include <ESP.h>
WiFiClient mqttNetworkClient; WiFiClient mqttNetworkClient;
#else #else
#if defined(STM32F4xx) && HASP_USE_WIFI>0 #if defined(STM32F4xx) && HASP_USE_WIFI > 0
// #include <WiFi.h> // #include <WiFi.h>
WiFiSpiClient mqttNetworkClient; WiFiSpiClient mqttNetworkClient;
#else #else
@ -120,7 +120,7 @@ PubSubClient mqttClient(mqttNetworkClient);
void mqtt_log_no_connection() void mqtt_log_no_connection()
{ {
Log.error(F("MQTT: Not connected")); Log.error(TAG_MQTT, F("Not connected"));
} }
bool IRAM_ATTR mqttIsConnected() 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 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) 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()) { if(mqttIsConnected()) {
char topic[64]; char topic[64];
@ -162,7 +162,7 @@ void mqtt_send_input(uint8_t id, const char * payload)
} }
// Log after char buffers are cleared // 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) 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 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); data);
} }
@ -194,12 +194,12 @@ void mqtt_send_statusupdate()
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
haspGetVersion().c_str(), long(millis() / 1000)); haspGetVersion().c_str(), long(millis() / 1000));
strcat(buffer, data); strcat(buffer, data);
#if HASP_USE_WIFI>0 #if HASP_USE_WIFI > 0
#if defined(STM32F4xx) #if defined(STM32F4xx)
IPAddress ip; IPAddress ip;
ip = WiFi.localIP(); ip = WiFi.localIP();
char espIp[16]; 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(), 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]); WiFi.RSSI(), ip[0], ip[1], ip[2], ip[3]);
#else #else
@ -244,8 +244,8 @@ void mqtt_send_statusupdate()
// mqttClient.publish(mqttSensorTopic, mqttStatusPayload); // mqttClient.publish(mqttSensorTopic, mqttStatusPayload);
// mqttClient.publish(mqttStatusTopic, "ON", true); //, 1); // mqttClient.publish(mqttStatusTopic, "ON", true); //, 1);
// debugPrintln(String(F("MQTT: status update: ")) + String(mqttStatusPayload)); // debugPrintln(String(F("status update: ")) + String(mqttStatusPayload));
// debugPrintln(String(F("MQTT: binary_sensor state: [")) + mqttStatusTopic + "] : [ON]"); // 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) static void mqtt_message_cb(char * topic_p, byte * payload, unsigned int length)
{ // Handle incoming commands from MQTT { // Handle incoming commands from MQTT
if(length >= MQTT_MAX_PACKET_SIZE) { 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; return;
} }
payload[length] = '\0'; 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\"") // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' = nextionSetAttr("p[1].b[4].txt", "\"Lights On\"")
char * topic = (char *)topic_p; 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 if(topic == strstr(topic, mqttNodeTopic)) { // startsWith mqttNodeTopic
topic += strlen(mqttNodeTopic); topic += strlen(mqttNodeTopic);
} else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic } else if(topic == strstr(topic, mqttGroupTopic)) { // startsWith mqttGroupTopic
topic += strlen(mqttGroupTopic); topic += strlen(mqttGroupTopic);
} else { } else {
Log.error(F("MQTT: Message received with invalid topic")); Log.error(TAG_MQTT, F("Message received with invalid topic"));
return; return;
} }
// catch a dangling LWT from a previous connection if it appears // catch a dangling LWT from a previous connection if it appears
if(!strcmp_P(topic, PSTR("status")) && !strcasecmp_P((char *)payload, PSTR("OFF"))) { if(!strcmp_P(topic, PSTR("status"))) {
if(!strcasecmp_P((char *)payload, PSTR("OFF"))) {
char topicBuffer[128]; char topicBuffer[128];
snprintf_P(topicBuffer, sizeof(topicBuffer), PSTR("%sstatus"), mqttNodeTopic); snprintf_P(topicBuffer, sizeof(topicBuffer), PSTR("%sstatus"), mqttNodeTopic);
mqttClient.publish(topicBuffer, "ON", true); mqttClient.publish(topicBuffer, "ON", true);
Log.notice(F("MQTT: binary_sensor state: [status] : ON")); Log.notice(TAG_MQTT, F("binary_sensor state: [status] : ON"));
// return; } else {
// already ON
}
} else { } else {
dispatchTopicPayload(topic, (char *)payload); dispatchTopicPayload(topic, (char *)payload);
} }
@ -326,9 +329,9 @@ void mqttSubscribeTo(const char * format, const char * data)
char topic[64]; char topic[64];
snprintf_P(topic, sizeof(topic), format, data); snprintf_P(topic, sizeof(topic), format, data);
if(mqttClient.subscribe(topic)) { if(mqttClient.subscribe(topic)) {
Log.verbose(F("MQTT: * Subscribed to %s"), topic); Log.verbose(TAG_MQTT, F(" * Subscribed to %s"), topic);
} else { } 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(); mac.toLowerCase();
memset(mqttClientId, 0, sizeof(mqttClientId)); memset(mqttClientId, 0, sizeof(mqttClientId));
snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("plate_%s"), mac.c_str()); 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 // 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)) { if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, false, "OFF", true)) {
// Retry until we give up and restart after connectTimeout seconds // Retry until we give up and restart after connectTimeout seconds
mqttReconnectCount++; mqttReconnectCount++;
snprintf_P(buffer, sizeof(buffer), PSTR("MQTT: %%s")); snprintf_P(buffer, sizeof(buffer), PSTR("%%s"));
switch(mqttClient.state()) { switch(mqttClient.state()) {
case MQTT_CONNECTION_TIMEOUT: case MQTT_CONNECTION_TIMEOUT:
strcat_P(buffer, PSTR("Server didn't respond within the keepalive time")); strcat_P(buffer, PSTR("Server didn't respond within the keepalive time"));
@ -387,16 +390,16 @@ void mqttReconnect()
default: default:
strcat_P(buffer, PSTR("Unknown failure")); strcat_P(buffer, PSTR("Unknown failure"));
} }
Log.warning(buffer); Log.warning(TAG_MQTT, buffer);
if(mqttReconnectCount > 50) { if(mqttReconnectCount > 50) {
Log.error(F("MQTT: %sRetry count exceeded, rebooting...")); Log.error(TAG_MQTT, F("Retry count exceeded, rebooting..."));
dispatchReboot(false); dispatchReboot(false);
} }
return; 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 // MQTT topic string definitions
@ -435,10 +438,10 @@ void mqttReconnect()
snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic);
mqttClient.publish(buffer, mqttFirstConnect ? "OFF" : "ON", true); //, 1); 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")); 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")); mqttFirstConnect ? PSTR("OFF") : PSTR("ON"));
debugPrintln(buffer); */ debugPrintln(buffer); */
@ -458,9 +461,9 @@ void mqttSetup()
if(mqttEnabled) { if(mqttEnabled) {
mqttClient.setServer(mqttServer, 1883); mqttClient.setServer(mqttServer, 1883);
mqttClient.setCallback(mqtt_message_cb); mqttClient.setCallback(mqtt_message_cb);
Log.notice(F("MQTT: Setup Complete")); Log.notice(TAG_MQTT, F("Setup Complete"));
} else { } 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.publish(topicBuffer, "{\"status\": \"unavailable\"}");
mqttClient.disconnect(); mqttClient.disconnect();
Log.notice(F("MQTT: Disconnected from broker")); Log.notice(TAG_MQTT, F("Disconnected from broker"));
} }
} }

View File

@ -315,11 +315,11 @@ bool oobeSetup()
if(oobeAutoCalibrate) { if(oobeAutoCalibrate) {
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); 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); 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 { } else {
lv_obj_set_click(lv_disp_get_layer_sys(NULL), false); lv_obj_set_click(lv_disp_get_layer_sys(NULL), false);
lv_obj_set_event_cb(lv_disp_get_layer_sys(NULL), gotoPage1_cb); 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); oobeSetPage(0);
return true; return true;
@ -346,9 +346,9 @@ void oobeFakeSetup()
if(oobeAutoCalibrate) { if(oobeAutoCalibrate) {
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); 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); 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 { } else {
Log.verbose(F("OOBE: Already calibrated")); Log.verbose(TAG_OOBE,F("Already calibrated"));
} }
#endif #endif
} }

View File

@ -40,14 +40,14 @@ int16_t otaPort = HASP_OTA_PORT;
void otaProgress() 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); (ArduinoOTA.getCommand() == U_FLASH ? PSTR("Firmware") : PSTR("Filesystem")), otaPrecentageComplete);
} }
void otaSetup() void otaSetup()
{ {
if(strlen(otaUrl.c_str())) { if(strlen(otaUrl.c_str())) {
Log.verbose(F("OTA: %s"), otaUrl.c_str()); Log.verbose(TAG_OTA, otaUrl.c_str());
} }
if(otaPort > 0) { if(otaPort > 0) {
@ -57,9 +57,9 @@ void otaSetup()
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() // 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); haspProgressVal(0);
haspProgressMsg(F("OTA: Firmware Update")); haspProgressMsg(F("Firmware Update"));
// dispatchPage("0"); // dispatchPage("0");
otaPrecentageComplete = 0; otaPrecentageComplete = 0;
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\""); // haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\"");
@ -73,7 +73,7 @@ void otaSetup()
// dispatchPage("0"); // dispatchPage("0");
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rComplete!\""); // haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rComplete!\"");
setup(); setup();
//dispatchReboot(true); // dispatchReboot(true);
}); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
if(total != 0) { if(total != 0) {
@ -85,17 +85,17 @@ void otaSetup()
}); });
ArduinoOTA.onError([](ota_error_t error) { ArduinoOTA.onError([](ota_error_t error) {
otaPrecentageComplete = -1; otaPrecentageComplete = -1;
Log.error(F("OTA: ERROR code %u"), error); Log.error(TAG_OTA, F("ERROR code %u"), error);
if(error == OTA_AUTH_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) 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) 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) 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) 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\""); // haspSetAttr("p[0].b[1].txt", "\"ESP OTA FAILED\"");
// delay(5000); // delay(5000);
// haspSendCmd("page " + String(nextionActivePage)); // haspSendCmd("page " + String(nextionActivePage));
@ -120,9 +120,9 @@ void otaSetup()
ArduinoOTA.setRebootOnSuccess(false); // We do that ArduinoOTA.setRebootOnSuccess(false); // We do that
ArduinoOTA.begin(); ArduinoOTA.begin();
Log.notice(F("OTA: Over the Air firmware update ready")); Log.notice(TAG_OTA, F("Over the Air firmware update ready"));
} else { } else {
Log.notice(F("OTA: Disabled")); Log.notice(TAG_OTA, F("Disabled"));
} }
} }
@ -153,18 +153,18 @@ void otaHttpUpdate(const char * espOtaUrl)
switch(returnCode) { switch(returnCode) {
case HTTP_UPDATE_FAILED: 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()); ESPhttpUpdate.getLastErrorString().c_str());
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\""); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\"");
break; break;
case HTTP_UPDATE_NO_UPDATES: 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\""); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rNo update\"");
break; break;
case HTTP_UPDATE_OK: 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.\""); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rcomplete!\\r\\rRestarting.\"");
dispatchReboot(true); dispatchReboot(true);
delay(5000); delay(5000);
@ -175,18 +175,18 @@ void otaHttpUpdate(const char * espOtaUrl)
switch(returnCode) { switch(returnCode) {
case HTTP_UPDATE_FAILED: 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()); httpUpdate.getLastErrorString().c_str());
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\""); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\"");
break; break;
case HTTP_UPDATE_NO_UPDATES: 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\""); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rNo update\"");
break; break;
case HTTP_UPDATE_OK: 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.\""); // nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rcomplete!\\r\\rRestarting.\"");
dispatchReboot(true); dispatchReboot(true);
delay(5000); delay(5000);

View File

@ -42,7 +42,7 @@ void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char
slave.ExecuteCommand((char*)cBuffer); slave.ExecuteCommand((char*)cBuffer);
// Log after char buffers are cleared // 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) 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); snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/json {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data);
slave.ExecuteCommand((char*)cBuffer); slave.ExecuteCommand((char*)cBuffer);
// Log after char buffers are cleared // 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) 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]; char cBuffer[strlen(payload) + 64];
memset(cBuffer, 0 ,sizeof(cBuffer)); memset(cBuffer, 0 ,sizeof(cBuffer));
@ -65,7 +65,7 @@ void slave_send_input(uint8_t id, const char * payload)
slave.ExecuteCommand((char*)cBuffer); slave.ExecuteCommand((char*)cBuffer);
// Log after char buffers are cleared // 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() void TASMO_TELE_JSON()
@ -90,12 +90,12 @@ void TASMO_TELE_JSON()
void TASMO_DATA_RECEIVE(char *data) 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]; char dataType[3];
memset(dataType, 0 ,sizeof(dataType)); memset(dataType, 0 ,sizeof(dataType));
snprintf_P(dataType, sizeof(dataType), data); 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[")){ // if (!strcmp(dataType, "p[")){ //
dispatchTextLine(data); dispatchTextLine(data);
@ -107,7 +107,7 @@ void TASMO_DATA_RECEIVE(char *data)
memset(slvVal, 0 ,sizeof(slvVal)); memset(slvVal, 0 ,sizeof(slvVal));
sscanf(data,"%[^=] =%s", slvCmd, 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 (!strcmp(slvCmd, "calData")){
if (strlen(slvVal) != 0) { if (strlen(slvVal) != 0) {
@ -133,11 +133,11 @@ void TASMO_EVERY_SECOND(void)
if (ledstate) { if (ledstate) {
ledstate = false; ledstate = false;
//digitalWrite(HASP_OUTPUT_PIN, 1); //digitalWrite(HASP_OUTPUT_PIN, 1);
// Log.verbose(F("LED OFF")); // Log.verbose(TAG_TASM,F("LED OFF"));
} else { } else {
ledstate = true; ledstate = true;
//digitalWrite(HASP_OUTPUT_PIN, 0); //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_JSON(TASMO_TELE_JSON);
slave.attach_FUNC_COMMAND_SEND(TASMO_DATA_RECEIVE); 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) void slaveLoop(void)

View File

@ -3,6 +3,7 @@
#include "ArduinoLog.h" #include "ArduinoLog.h"
#include "hasp_conf.h" #include "hasp_conf.h"
#include "hasp_debug.h"
#include "hasp_spiffs.h" #include "hasp_spiffs.h"
#if HASP_USE_SPIFFS > 0 #if HASP_USE_SPIFFS > 0
@ -75,23 +76,23 @@ void spiffsList()
#else #else
if(!SPIFFS.begin(true)) { if(!SPIFFS.begin(true)) {
#endif #endif
Log.error(F("FILE: Flash file system not mouted.")); Log.error(TAG_FILE,F("Flash file system not mouted."));
} else { } 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) #if defined(ARDUINO_ARCH_ESP32)
File root = SPIFFS.open("/"); File root = SPIFFS.open("/");
File file = root.openNextFile(); File file = root.openNextFile();
while(file) { 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(); file = root.openNextFile();
} }
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
Dir dir = SPIFFS.openDir("/"); Dir dir = SPIFFS.openDir("/");
while(dir.next()) { 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 #endif
} }
@ -108,9 +109,9 @@ void spiffsSetup()
#else #else
if(!SPIFFS.begin(true)) { if(!SPIFFS.begin(true)) {
#endif #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 { } else {
Log.verbose(F("FILE: SPI Flash FS mounted")); Log.verbose(TAG_FILE,F("SPI Flash FS mounted"));
} }
#endif #endif
} }

View File

@ -47,7 +47,7 @@ char telnetInputBuffer[128];
void telnetClientDisconnect() 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(); telnetClient.stop();
Log.unregisterOutput(1); // telnetClient Log.unregisterOutput(1); // telnetClient
telnetLoginState = TELNET_UNAUTHENTICATED; telnetLoginState = TELNET_UNAUTHENTICATED;
@ -62,7 +62,7 @@ void telnetClientLogon()
telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct
telnetLoginAttempt = 0; // Reset attempt counter telnetLoginAttempt = 0; // Reset attempt counter
Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true); 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(); telnetClient.flush();
/* Echo locally as separate string */ /* Echo locally as separate string */
// telnetClient.print(F("TELNET: Client login from ")); // telnetClient.print(F("TELNET: Client login from "));
@ -78,12 +78,12 @@ void telnetAcceptClient()
Log.unregisterOutput(1); // telnetClient Log.unregisterOutput(1); // telnetClient
} }
telnetClient = telnetServer->available(); // ready for new client 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) { if(!telnetClient) {
Log.notice(F("Client NOT connected")); Log.notice(TAG_TELN,F("Client NOT connected"));
return; return;
} }
Log.notice(F("Client connected")); Log.notice(TAG_TELN,F("Client connected"));
/* Avoid a buffer here */ /* Avoid a buffer here */
telnetClient.print(0xFF); // DO TERMINAL-TYPE telnetClient.print(0xFF); // DO TERMINAL-TYPE
@ -132,7 +132,7 @@ static void telnetProcessLine()
telnetLoginState = TELNET_UNAUTHENTICATED; telnetLoginState = TELNET_UNAUTHENTICATED;
telnetLoginAttempt++; // Subsequent attempt telnetLoginAttempt++; // Subsequent attempt
telnetClient.println(F("Authorization failed!\r\n")); 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) { if(telnetLoginAttempt >= 3) {
telnetClientDisconnect(); telnetClientDisconnect();
} else { } else {
@ -200,9 +200,9 @@ void telnetSetup()
// if(!telnetServer) telnetServer = new EthernetServer(telnetPort); // if(!telnetServer) telnetServer = new EthernetServer(telnetPort);
// if(telnetServer) { // if(telnetServer) {
telnetServer->begin(); telnetServer->begin();
Log.notice(F("Debug telnet console started")); Log.notice(TAG_TELN,F("Debug telnet console started"));
// } else { // } else {
// Log.error(F("Failed to start telnet server")); // Log.error(TAG_TELN,F("Failed to start telnet server"));
//} //}
#else #else
if(!telnetServer) telnetServer = new WiFiServer(telnetPort); if(!telnetServer) telnetServer = new WiFiServer(telnetPort);
@ -212,14 +212,14 @@ void telnetSetup()
// if(!telnetClient) telnetClient = new WiFiClient; // if(!telnetClient) telnetClient = new WiFiClient;
// if(!telnetClient) { // if(!telnetClient) {
// Log.error(F("Failed to start telnet client")); // Log.error(TAG_TELN,F("Failed to start telnet client"));
//} else { //} else {
telnetClient.setNoDelay(true); telnetClient.setNoDelay(true);
//} //}
Log.notice(F("Debug telnet console started")); Log.notice(TAG_TELN,F("Debug telnet console started"));
} else { } else {
Log.error(F("Failed to start telnet server")); Log.error(TAG_TELN,F("Failed to start telnet server"));
} }
#endif #endif
} }
@ -238,12 +238,12 @@ Ethernet.schedule();
//telnetAcceptClient(client); //telnetAcceptClient(client);
telnetClient = client; // ready for new 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) { if(!telnetClient) {
Log.notice(F("Client NOT connected")); Log.notice(TAG_TELN,F("Client NOT connected"));
return; return;
} }
Log.notice(F("Client connected")); Log.notice(TAG_TELN,F("Client connected"));
/* Avoid a buffer here */ /* Avoid a buffer here */
// telnetClient.print(0xFF); // DO TERMINAL-TYPE // telnetClient.print(0xFF); // DO TERMINAL-TYPE

View File

@ -8,6 +8,7 @@
#include "hasp_tft.h" #include "hasp_tft.h"
#include "hasp_hal.h" #include "hasp_hal.h"
#include "hasp_gpio.h" // PinNames #include "hasp_gpio.h" // PinNames
#include "hasp_debug.h"
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
ADC_MODE(ADC_VCC); // tftShowConfig measures the voltage on the pin 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) void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset)
{ {
if(x_offset != 0) { 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) { 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) { if(pin != -1) {
char buffer[64]; char buffer[64];
snprintf_P(buffer, sizeof(buffer), PSTR("TFT: %-11s: %s (GPIO %02d)"), pinfunction, gpioName(pin).c_str(), pin); snprintf_P(buffer, sizeof(buffer), PSTR("%-11s: %s (GPIO %02d)"), pinfunction, gpioName(pin).c_str(), pin);
Log.verbose(buffer); Log.verbose(TAG_TFT, buffer);
} }
} }
@ -50,29 +51,29 @@ void tftShowConfig(TFT_eSPI & tft)
setup_t tftSetup; setup_t tftSetup;
tft.getSetup(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) #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 #else
Log.verbose(F("TFT: Processor : STM%x"), tftSetup.esp); Log.verbose(TAG_TFT, F("Processor : STM%x"), tftSetup.esp);
#endif #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) #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 #endif
Log.verbose(F("TFT: Transactns : %s"), (tftSetup.trans == 1) ? PSTR("Yes") : PSTR("No")); Log.verbose(TAG_TFT, F("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("Interface : %s"), (tftSetup.serial == 1) ? PSTR("SPI") : PSTR("Parallel"));
#if defined(ARDUINO_ARCH_ESP8266) #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 #endif
if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch 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(TAG_TFT, F("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("Resolution : %ix%i"), tftSetup.tft_width, tftSetup.tft_height);
} else if(tftSetup.tft_driver == 0xE9D) } else if(tftSetup.tft_driver == 0xE9D)
Log.verbose(F("Driver = ePaper")); Log.verbose(TAG_TFT, F("Driver = ePaper"));
// Offsets, not all used yet // Offsets, not all used yet
tftOffsetInfo(0, tftSetup.r0_x_offset, tftSetup.r0_y_offset); 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 defined(ARDUINO_ARCH_ESP8266)
if(tftSetup.overlap == true) { 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(TAG_TFT, F("MOSI : SD1 (GPIO 8)"));
Log.verbose(F("MISO : SD0 (GPIO 7)")); Log.verbose(TAG_TFT, F("MISO : SD0 (GPIO 7)"));
Log.verbose(F("SCK : CLK (GPIO 6)")); Log.verbose(TAG_TFT, F("SCK : CLK (GPIO 6)"));
Log.verbose(F("TFT_CS : D3 (GPIO 0)")); 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 #endif
@ -124,10 +125,12 @@ void tftShowConfig(TFT_eSPI & tft)
tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7); tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7);
if(tftSetup.serial == 1) { 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) { 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);
} }
} }

View File

@ -52,11 +52,11 @@ void wifiConnected(IPAddress ipaddress)
#if defined(STM32F4xx) #if defined(STM32F4xx)
IPAddress ip; IPAddress ip;
ip = WiFi.localIP(); 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 #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 #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); haspProgressVal(255);
// if(isConnected) { // if(isConnected) {
@ -73,15 +73,15 @@ void wifiDisconnected(const char * ssid, uint8_t reason)
haspProgressVal(wifiReconnectCounter * 3); haspProgressVal(wifiReconnectCounter * 3);
haspProgressMsg(F("Wifi Disconnected")); haspProgressMsg(F("Wifi Disconnected"));
if(wifiReconnectCounter > 33) { if(wifiReconnectCounter > 33) {
Log.error(F("WIFI: Retries exceed %u: Rebooting..."), wifiReconnectCounter); Log.error(TAG_WIFI,F("Retries exceed %u: Rebooting..."), wifiReconnectCounter);
dispatchReboot(false); 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) 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; 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(ssid, PSTR("HASP-%02x%02x%02x"), mac[3], mac[4], mac[5]);
sprintf_P(pass, PSTR("haspadmin")); sprintf_P(pass, PSTR("haspadmin"));
#if defined(STM32F4xx) #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 #else
WiFi.softAP(ssid, pass); WiFi.softAP(ssid, pass);
@ -146,8 +146,8 @@ bool wifiShowAP(char * ssid, char * pass)
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError); // dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
// dnsServer.start(DNS_PORT, "*", apIP); // dnsServer.start(DNS_PORT, "*", apIP);
Log.warning(F("WIFI: Temporary Access Point %s password: %s"), ssid, pass); Log.warning(TAG_WIFI,F("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("AP IP address : %s"), WiFi.softAPIP().toString().c_str());
// httpReconnect();} // httpReconnect();}
#endif #endif
return true; return true;
@ -181,13 +181,13 @@ void wifiSetup()
// check for the presence of the shield: // check for the presence of the shield:
if (WiFiSpi.status() == WL_NO_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: // don't continue:
while (true); while (true);
} }
if (!WiFiSpi.checkProtocolVersion()) { 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: // don't continue:
while (true); while (true);
} }
@ -196,7 +196,7 @@ void wifiSetup()
// int status = WL_IDLE_STATUS; // the Wifi radio's status // int status = WL_IDLE_STATUS; // the Wifi radio's status
if(!wifiShowAP()) { if(!wifiShowAP()) {
// while (status != WL_CONNECTED) { // 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 // Connect to WPA/WPA2 network
// status = WiFi.begin(wifiSsid, wifiPassword); // status = WiFi.begin(wifiSsid, wifiPassword);
WiFi.begin(wifiSsid, wifiPassword); WiFi.begin(wifiSsid, wifiPassword);
@ -220,7 +220,7 @@ void wifiSetup()
#endif #endif
wifiReconnect(); wifiReconnect();
Log.notice(F("WIFI: Connecting to : %s"), wifiSsid); Log.notice(TAG_WIFI,F("Connecting to : %s"), wifiSsid);
} }
#endif #endif
} }
@ -240,10 +240,10 @@ bool wifiEvery5Seconds()
} else { } else {
wifiReconnectCounter++; wifiReconnectCounter++;
if(wifiReconnectCounter > 45) { if(wifiReconnectCounter > 45) {
Log.error(F("WIFI: Retries exceed %u: Rebooting..."), wifiReconnectCounter); Log.error(TAG_WIFI,F("Retries exceed %u: Rebooting..."), wifiReconnectCounter);
dispatchReboot(false); 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) { if(wifiReconnectCounter % 6 == 0) {
wifiReconnect(); wifiReconnect();
} }
@ -307,14 +307,14 @@ bool wifiTestConnection()
while(attempt < 10 && (WiFi.status() != WL_CONNECTED || WiFi.localIP().toString() == F("0.0.0.0"))) { while(attempt < 10 && (WiFi.status() != WL_CONNECTED || WiFi.localIP().toString() == F("0.0.0.0"))) {
#endif #endif
attempt++; 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); delay(1000);
} }
#if defined(STM32F4xx) #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; if((WiFi.status() == WL_CONNECTED && String(espIp) != F("0.0.0.0"))) return true;
#else #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; if((WiFi.status() == WL_CONNECTED && WiFi.localIP().toString() != F("0.0.0.0"))) return true;
#endif #endif
WiFi.disconnect(); WiFi.disconnect();
@ -328,7 +328,7 @@ void wifiStop()
#if !defined(STM32F4xx) #if !defined(STM32F4xx)
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
#endif #endif
Log.warning(F("WIFI: Stopped")); Log.warning(TAG_WIFI,F("Stopped"));
} }
#endif #endif

View File

@ -39,7 +39,6 @@ void setup()
/**************************** /****************************
* Apply User Configuration * Apply User Configuration
***************************/ ***************************/
debugSetup();
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
gpioSetup(); gpioSetup();
@ -57,6 +56,9 @@ void setup()
wifiSetup(); wifiSetup();
#endif #endif
// The network stack needs to be initialized before calling debugSetup, cause syslog needs lwip
debugSetup();
guiSetup(); guiSetup();
if(!oobeSetup()) { if(!oobeSetup()) {
haspSetup(); haspSetup();