diff --git a/.gitignore b/.gitignore index ab6f693b..eac47ff6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,13 +5,12 @@ .git .pio data/* +src/user_setups/active/* include/user_config_override.h src/user_config_override.h user_config_override.h platformio_override.ini user_setups/active/* -src/user_setups/active/* -test/config.yaml build_output/* build_output/firmware/*.bin build_output/firmware/*.exe diff --git a/include/lv_conf.h b/include/lv_conf.h index c7ea9aad..7a1d57a6 100644 --- a/include/lv_conf.h +++ b/include/lv_conf.h @@ -1,7 +1,3 @@ -#ifdef USE_CONFIG_OVERRIDE -#include "user_config_override.h" -#endif - #include "lv_conf_v7.h" #define LV_THEME_DEFAULT_FLAGS LV_THEME_DEFAULT_FLAG diff --git a/include/lv_conf_v7.h b/include/lv_conf_v7.h index 74897617..a4d3b2eb 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -367,19 +367,6 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in #define ROBOTOCONDENSED_REGULAR_48_LATIN1 1 #endif -#ifndef HASP_FONT_SIZE_1 -#define HASP_FONT_SIZE_1 16 -#endif -#ifndef HASP_FONT_SIZE_2 -#define HASP_FONT_SIZE_2 24 -#endif -#ifndef HASP_FONT_SIZE_3 -#define HASP_FONT_SIZE_3 32 -#endif -#ifndef HASP_FONT_SIZE_4 -#define HASP_FONT_SIZE_4 48 -#endif - #else #ifndef HASP_FONT_1 @@ -408,19 +395,6 @@ typedef void* lv_indev_drv_user_data_t; /*Type of user data in the in #define ROBOTOCONDENSED_REGULAR_32_LATIN1 1 #endif -#ifndef HASP_FONT_SIZE_1 -#define HASP_FONT_SIZE_1 12 -#endif -#ifndef HASP_FONT_SIZE_2 -#define HASP_FONT_SIZE_2 16 -#endif -#ifndef HASP_FONT_SIZE_3 -#define HASP_FONT_SIZE_3 24 -#endif -#ifndef HASP_FONT_SIZE_4 -#define HASP_FONT_SIZE_4 32 -#endif - #endif /* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel. diff --git a/include/user_config_override-template.h b/include/user_config_override-template.h index 9e64d0e1..fd01a783 100644 --- a/include/user_config_override-template.h +++ b/include/user_config_override-template.h @@ -88,28 +88,9 @@ #define D_HTTP_COLOR_BUTTON_RESET "#d43535" // Restart/Reset/Delete button color - Strong red */ -/*************************************************** - * Font Settings - **************************************************/ -// #define HASP_FONT_1 robotocondensed_regular_16_latin1 // Use available fonts from src/fonts directory -// #define HASP_FONT_2 robotocondensed_regular_22_latin1 -// #define HASP_FONT_3 robotocondensed_regular_40_latin1 -// #define HASP_FONT_4 robotocondensed_regular_48_latin1 - -// #define ROBOTOCONDENSED_REGULAR_16_LATIN1 1 // Enable the selected fonts -// #define ROBOTOCONDENSED_REGULAR_22_LATIN1 1 -// #define ROBOTOCONDENSED_REGULAR_40_LATIN1 1 -// #define ROBOTOCONDENSED_REGULAR_48_LATIN1 1 - -// #define HASP_FONT_SIZE_1 16 // Define used font sizes -// #define HASP_FONT_SIZE_2 22 -// #define HASP_FONT_SIZE_3 40 -// #define HASP_FONT_SIZE_4 48 - /*************************************************** * Other Settings **************************************************/ //#define HASP_USE_HA // Enable Home Assistant auto-discovery -//#define HASP_GPIO_TEMPLATE "[2360346,2491680,2623009,2097420,2097678,2097947,0,0]" // Lanbon L8-HS: 3 Relays + Moodlight GPIO config -#endif +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 3aab2a92..a73ea958 100644 --- a/platformio.ini +++ b/platformio.ini @@ -49,7 +49,6 @@ build_flags = -D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers -D LV_COMP_CONF_INCLUDE_SIMPLE ; for components -D LV_SYMBOL_DEF_H ; don't load default symbol defines - -D LV_MEM_FULL_DEFRAG_CNT=4 ; stability: run lv_mem_defrag more frequently ; -- ESP build options ------------------------------------ -D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files ; -- ArduinoJson build options ---------------------------- @@ -61,8 +60,8 @@ build_flags = ; -- Hasp build options ---------------------------- -D HASP_VER_MAJ=0 -D HASP_VER_MIN=5 - -D HASP_VER_REV=1 - -D HASP_LOG_LEVEL=LOG_LEVEL_TRACE + -D HASP_VER_REV=0 + -D HASP_LOG_LEVEL=LOG_LEVEL_OUTPUT ${override.build_flags} ; -- Shared library dependencies in all environments diff --git a/src/dev/device.cpp b/src/dev/device.cpp index 3c531343..395a6e43 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -1,19 +1,2 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ - -#include "device.h" - -#define Q(x) #x -#define QUOTE(x) Q(x) - -namespace dev { - -const char* BaseDevice::get_model() -{ -#ifdef HASP_MODEL - return QUOTE(HASP_MODEL); -#else - return PIOENV; -#endif -} -} // namespace dev \ No newline at end of file diff --git a/src/dev/device.h b/src/dev/device.h index 2cca34c7..68d1867a 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -41,7 +41,6 @@ class BaseDevice { { return ""; } - const char* get_model(); virtual void init() {} diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index 66fe647f..6cc4693a 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -37,17 +37,14 @@ const char* Esp32Device::get_hostname() { return _hostname.c_str(); } - void Esp32Device::set_hostname(const char* hostname) { _hostname = hostname; } - const char* Esp32Device::get_core_version() { return esp_get_idf_version(); // == ESP.getSdkVersion(); } - const char* Esp32Device::get_chip_model() { esp_chip_info_t chip_info; diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index f72b7831..7378e2dd 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -232,7 +232,7 @@ void my_obj_set_value_str_txt(lv_obj_t* obj, uint8_t part, lv_state_t state, con { // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); - void* value_str_p = (void*)lv_obj_get_style_value_str(obj, part); + const void* value_str_p = lv_obj_get_style_value_str(obj, part); lv_obj_invalidate(obj); if(text == NULL || text[0] == 0) { @@ -262,21 +262,36 @@ void my_obj_set_value_str_txt(lv_obj_t* obj, uint8_t part, lv_state_t state, con return; } + // lv_obj_set_style_local_value_str(obj, part, state, str_p); + if(value_str_p == text) { /*If set its own text then reallocate it (maybe its size changed)*/ LOG_DEBUG(TAG_ATTR, "%s %d", __FILE__, __LINE__); return; // don't touch the data + + // value_str_p = lv_mem_realloc(value_str_p, strlen(text) + 1); + + // LV_ASSERT_MEM(value_str_p); + // if(value_str_p == NULL) return; + } else { + /*Free the old text*/ + if(value_str_p != NULL) { + // LOG_DEBUG(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); + lv_mem_free(value_str_p); + value_str_p = NULL; + // LOG_DEBUG(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); + } + + /*Get the size of the text*/ + size_t len = strlen(text) + 1; + + /*Allocate space for the new text*/ + value_str_p = lv_mem_alloc(len); + LV_ASSERT_MEM(value_str_p); + if(value_str_p != NULL) strcpy((char*)value_str_p, text); + lv_obj_set_style_local_value_str(obj, part, state, (char*)value_str_p); } - /*Get the size of the text*/ - size_t len = strlen(text) + 1; - - /*Allocate space for the new text*/ - value_str_p = lv_mem_realloc(value_str_p, len); - LV_ASSERT_MEM(value_str_p); - if(value_str_p != NULL) strcpy((char*)value_str_p, text); - lv_obj_set_style_local_value_str(obj, part, state, (char*)value_str_p); - // LOG_VERBOSE(TAG_ATTR, F("%s %d"), __FILE__, __LINE__); } @@ -448,24 +463,24 @@ static lv_font_t* haspPayloadToFont(const char* payload) #ifndef ARDUINO_ARCH_ESP8266 #ifdef HASP_FONT_1 - case HASP_FONT_SIZE_1: + case 12: return &HASP_FONT_1; #endif #ifdef HASP_FONT_2 - case HASP_FONT_SIZE_2: + case 16: LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, HASP_FONT_2); return &HASP_FONT_2; #endif #ifdef HASP_FONT_3 - case HASP_FONT_SIZE_3: + case 22: LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, HASP_FONT_3); return &HASP_FONT_3; #endif #ifdef HASP_FONT_4 - case HASP_FONT_SIZE_4: + case 28: LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, HASP_FONT_4); return &HASP_FONT_4; #endif @@ -1777,9 +1792,6 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attr_p, const char* p } goto attribute_not_found; - case ATTR_COMMENT: - break; // attribute_found - default: hasp_local_style_attr(obj, attr, attr_hash, payload, update); } diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h index ca260c85..7a4f11f7 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -266,7 +266,6 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t) #define ATTR_BACK 57799 /* Object Attributes */ -#define ATTR_COMMENT 62559 #define ATTR_X 120 #define ATTR_Y 121 #define ATTR_W 119 diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 548b37b5..71d33185 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -887,18 +887,15 @@ void dispatch_output_statusupdate(const char*, const char*) { #if HASP_USE_MQTT > 0 - char data[512]; + char data[400]; char topic[16]; { char buffer[128]; haspGetVersion(buffer, sizeof(buffer)); dispatch_get_idle_state(hasp_sleep_state, topic); - snprintf_P(data, sizeof(data), - PSTR("{\"node\":\"%s\",\"manufacturer\":\"" D_MANUFACTURER - "\",\"model\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"), - haspDevice.get_hostname(), haspDevice.get_model(), topic, buffer, - (unsigned long)(millis() / 1000)); // \"status\":\"available\", + snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"), + haspDevice.get_hostname(), topic, buffer, long(millis() / 1000)); // \"status\":\"available\", #if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0 network_get_statusupdate(buffer, sizeof(buffer)); @@ -930,6 +927,13 @@ void dispatch_output_statusupdate(const char*, const char*) dispatch_state_subtopic(topic, data); dispatchLastMillis = millis(); + /* if(updateEspAvailable) { + mqttStatusPayload += F("\"updateEspAvailable\":true,"); + } else { + mqttStatusPayload += F("\"updateEspAvailable\":false,"); + } + */ + #endif } diff --git a/src/hasp/hasp_event.cpp b/src/hasp/hasp_event.cpp index 7e546f5f..ca254cd6 100644 --- a/src/hasp/hasp_event.cpp +++ b/src/hasp/hasp_event.cpp @@ -555,14 +555,3 @@ void cpicker_event_handler(lv_obj_t* obj, lv_event_t event) // dispatch_normalized_group_value(obj->user_data.groupid, obj, val, min, max); } - -/** - * Called when an object is deleted - * @param obj pointer to a generic object - * @param event type of event that occured - */ -void deleted_event_handler(lv_obj_t* obj, lv_event_t event) -{ - uint8_t hasp_event_id; - translate_event(obj, event, hasp_event_id); -} \ No newline at end of file diff --git a/src/hasp/hasp_event.h b/src/hasp/hasp_event.h index b113575f..9b82950a 100644 --- a/src/hasp/hasp_event.h +++ b/src/hasp/hasp_event.h @@ -18,7 +18,6 @@ void slider_event_handler(lv_obj_t* obj, lv_event_t event); void selector_event_handler(lv_obj_t* obj, lv_event_t event); void btnmatrix_event_handler(lv_obj_t* obj, lv_event_t event); void cpicker_event_handler(lv_obj_t* obj, lv_event_t event); -void deleted_event_handler(lv_obj_t* obj, lv_event_t event); #if HASP_USE_GPIO > 0 void event_gpio_input(uint8_t pin, uint8_t group, uint8_t eventid); diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index c6beef08..f1c09788 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -489,20 +489,16 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) case LV_HASP_PAGE: case HASP_OBJ_PAGE: obj = lv_page_create(parent_obj, NULL); - if(obj) { - obj->user_data.objid = LV_HASP_PAGE; - lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation - } + if(obj) obj->user_data.objid = LV_HASP_PAGE; + // No event handler for pages break; #if LV_USE_WIN && LVGL_VERSION_MAJOR == 7 case LV_HASP_WINDOW: case HASP_OBJ_WIN: obj = lv_win_create(parent_obj, NULL); - if(obj) { - obj->user_data.objid = LV_HASP_WINDOW; - lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation - } + if(obj) obj->user_data.objid = LV_HASP_WINDOW; + // No event handler for pages break; #endif @@ -554,18 +550,16 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) case LV_HASP_TILEVIEW: case HASP_OBJ_TILEVIEW: obj = lv_tileview_create(parent_obj, NULL); - if(obj) { - obj->user_data.objid = LV_HASP_TILEVIEW; - lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation - } + if(obj) obj->user_data.objid = LV_HASP_TILEVIEW; + + // No event handler for tileviews break; case LV_HASP_TABVIEW: case HASP_OBJ_TABVIEW: obj = lv_tabview_create(parent_obj, NULL); + // No event handler for tabs if(obj) { - lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation - lv_obj_t* tab; tab = lv_tabview_add_tab(obj, "tab 1"); // lv_obj_set_user_data(tab, id + 1); @@ -593,10 +587,7 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id) case LV_HASP_SPINNER: case HASP_OBJ_SPINNER: obj = lv_spinner_create(parent_obj, NULL); - if(obj) { - obj->user_data.objid = LV_HASP_SPINNER; - lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation - } + if(obj) obj->user_data.objid = LV_HASP_SPINNER; break; #endif diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 3f2b08c9..4240ceb6 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -152,13 +152,6 @@ void configRead(JsonDocument& settings, bool setupdebug = false) #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 LOG_ERROR(TAG_CONF, F(D_FILE_LOAD_FAILED), configFile.c_str()); - #ifdef HASP_GPIO_TEMPLATE - char json[100]; - snprintf(json, sizeof(json), PSTR("{\"%s\":{\"%s\":%s}}"), (char*)(FPSTR(FP_GPIO)), (char*)(FPSTR(FP_GPIO_CONFIG)), (char*)(FPSTR(HASP_GPIO_TEMPLATE))); - error = deserializeJson(settings, json); - gpioSetConfig(settings[FPSTR(FP_GPIO)]); - #endif - #endif } /* diff --git a/src/hasp_config.h b/src/hasp_config.h index 99224b06..77eb6e01 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -71,10 +71,6 @@ const char FP_HASP[] PROGMEM = "hasp"; const char FP_GUI[] PROGMEM = "gui"; const char FP_DEBUG[] PROGMEM = "debug"; -#ifdef HASP_GPIO_TEMPLATE -const char FP_GPIO_TEMPLATE[] PROGMEM = HASP_GPIO_TEMPLATE; -#endif - #endif #endif // HASP_USE_CONFIG \ No newline at end of file diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp index 83fcad2f..272fa569 100644 --- a/src/hasp_debug.cpp +++ b/src/hasp_debug.cpp @@ -338,8 +338,6 @@ static void debugPrintLvglMemory(int level, Print* _logOutput) lv_mem_monitor_t mem_mon; lv_mem_monitor(&mem_mon); - if(mem_mon.frag_pct > 20) lv_mem_defrag(); // prevents LED shadow crashing - /* Print LVGL Memory Info */ if(debugAnsiCodes) { if(mem_mon.free_biggest_size > (1024u * 2) && (mem_mon.free_size > 1024u * 2.5) && (mem_mon.frag_pct <= 10)) diff --git a/src/hasp_debug.h b/src/hasp_debug.h index 615308b8..dc1e92c2 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -85,6 +85,46 @@ void debugStopSyslog(void); std::cout << std::endl; \ fflush(stdout) +/* json keys used in the configfile */ +// const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; +// const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim"; +// const char FP_CONFIG_THEME[] PROGMEM = "theme"; +// const char FP_CONFIG_HUE[] PROGMEM = "hue"; +// const char FP_CONFIG_ZIFONT[] PROGMEM = "font"; +// const char FP_CONFIG_PAGES[] PROGMEM = "pages"; +// const char FP_CONFIG_ENABLE[] PROGMEM = "enable"; +// const char FP_CONFIG_HOST[] PROGMEM = "host"; +// const char FP_CONFIG_PORT[] PROGMEM = "port"; +// const char FP_CONFIG_NAME[] PROGMEM = "name"; +// const char FP_CONFIG_USER[] PROGMEM = "user"; +// const char FP_CONFIG_PASS[] PROGMEM = "pass"; +// const char FP_CONFIG_SSID[] PROGMEM = "ssid"; +// const char FP_CONFIG_GROUP[] PROGMEM = "group"; +// const char FP_CONFIG_BAUD[] PROGMEM = "baud"; +// const char FP_CONFIG_LOG[] PROGMEM = "log"; +// const char FP_CONFIG_PROTOCOL[] PROGMEM = "proto"; +// const char FP_GUI_ROTATION[] PROGMEM = "rotate"; +// const char FP_GUI_INVERT[] PROGMEM = "invert"; +// const char FP_GUI_TICKPERIOD[] PROGMEM = "tick"; +// const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1"; +// const char FP_GUI_IDLEPERIOD2[] PROGMEM = "idle2"; +// const char FP_GUI_CALIBRATION[] PROGMEM = "calibration"; +// const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl"; +// const char FP_GUI_POINTER[] PROGMEM = "cursor"; +// const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele"; +// const char FP_GPIO_CONFIG[] PROGMEM = "config"; + +// const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json"; + +// const char FP_WIFI[] PROGMEM = "wifi"; +// const char FP_MQTT[] PROGMEM = "mqtt"; +// const char FP_HTTP[] PROGMEM = "http"; +// const char FP_GPIO[] PROGMEM = "gpio"; +// const char FP_MDNS[] PROGMEM = "mdns"; +// const char FP_HASP[] PROGMEM = "hasp"; +// const char FP_GUI[] PROGMEM = "gui"; +// const char FP_DEBUG[] PROGMEM = "debug"; + #endif #ifdef __cplusplus diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index 17eaa93f..a89da106 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -81,16 +81,12 @@ bool mqttHAautodiscover = true; #define LWT_TOPIC "LWT" -// char mqttServer[16] = MQTT_HOST; -// char mqttUser[23] = MQTT_USER; -// char mqttPassword[32] = MQTT_PASSW; -// char mqttGroupName[16] = MQTT_GROUPNAME; -std::string mqttServer = MQTT_HOST; -std::string mqttUser = MQTT_USER; -std::string mqttPassword = MQTT_PASSW; -std::string mqttGroupName = MQTT_GROUPNAME; - -uint16_t mqttPort = MQTT_PORT; +char mqttServer[16] = MQTT_HOST; +char mqttUser[23] = MQTT_USER; +char mqttPassword[32] = MQTT_PASSW; +// char mqttNodeName[16] = MQTT_NODENAME; +char mqttGroupName[16] = MQTT_GROUPNAME; +uint16_t mqttPort = MQTT_PORT; PubSubClient mqttClient(mqttNetworkClient); int mqttPublish(const char* topic, const char* payload, size_t len, bool retain) @@ -228,7 +224,7 @@ void mqttStart() static uint8_t mqttReconnectCount = 0; // bool mqttFirstConnect = true; - mqttClient.setServer(mqttServer.c_str(), 1883); + mqttClient.setServer(mqttServer, 1883); // mqttClient.setSocketTimeout(10); //in seconds /* Construct unique Client ID*/ @@ -246,8 +242,7 @@ void mqttStart() haspProgressMsg(F(D_MQTT_CONNECTING)); haspProgressVal(mqttReconnectCount * 5); - if(!mqttClient.connect(mqttClientId, mqttUser.c_str(), mqttPassword.c_str(), buffer, 0, true, lastWillPayload, - true)) { + if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, true, lastWillPayload, true)) { // Retry until we give up and restart after connectTimeout seconds mqttReconnectCount++; @@ -292,16 +287,16 @@ void mqttStart() return; } - LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer.c_str(), mqttClientId); + LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer, mqttClientId); // Subscribe to our incoming topics const __FlashStringHelper* F_topic; F_topic = F("%scommand/#"); mqttSubscribeTo(F_topic, mqttGroupTopic); mqttSubscribeTo(F_topic, mqttNodeTopic); - F_topic = F("%sconfig/#"); - mqttSubscribeTo(F_topic, mqttGroupTopic); - mqttSubscribeTo(F_topic, mqttNodeTopic); + // F_topic = F("%sconfig/#"); + // mqttSubscribeTo(F_topic, mqttGroupTopic); + // mqttSubscribeTo(F_topic, mqttNodeTopic); // mqttSubscribeTo(F("%slight/#"), mqttNodeTopic); // mqttSubscribeTo(F("%sbrightness/#"), mqttNodeTopic); // mqttSubscribeTo(F("%s"LWT_TOPIC), mqttNodeTopic); @@ -328,9 +323,9 @@ void mqttStart() void mqttSetup() { - mqttEnabled = mqttServer.length() > 0 && mqttPort > 0; + mqttEnabled = strlen(mqttServer) > 0 && mqttPort > 0; if(mqttEnabled) { - mqttClient.setServer(mqttServer.c_str(), mqttPort); + mqttClient.setServer(mqttServer, mqttPort); mqttClient.setCallback(mqtt_message_cb); // if(!mqttClient.setBufferSize(1024)) { // LOG_ERROR(TAG_MQTT, F("Buffer allocation failed")); @@ -378,19 +373,19 @@ bool mqttGetConfig(const JsonObject& settings) if(strcmp(haspDevice.get_hostname(), settings[FPSTR(FP_CONFIG_NAME)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_NAME)] = haspDevice.get_hostname(); - if(mqttGroupName != settings[FPSTR(FP_CONFIG_GROUP)].as()) changed = true; + if(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName; - if(mqttServer != settings[FPSTR(FP_CONFIG_HOST)].as()) changed = true; + if(strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_HOST)] = mqttServer; if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true; settings[FPSTR(FP_CONFIG_PORT)] = mqttPort; - if(mqttUser != settings[FPSTR(FP_CONFIG_USER)].as().c_str()) changed = true; + if(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_USER)] = mqttUser; - if(mqttPassword != settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) changed = true; + if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true; settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword; if(changed) configOutput(settings, TAG_MQTT); @@ -428,33 +423,33 @@ bool mqttSetConfig(const JsonObject& settings) } if(!settings[FPSTR(FP_CONFIG_GROUP)].isNull()) { - changed |= mqttGroupName != settings[FPSTR(FP_CONFIG_GROUP)].as(); - mqttGroupName = settings[FPSTR(FP_CONFIG_GROUP)].as(); + changed |= strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)]) != 0; + strncpy(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)], sizeof(mqttGroupName)); } - if(mqttGroupName.length() == 0) { - mqttGroupName = String(F("plates")).c_str(); - changed = true; + if(strlen(mqttGroupName) == 0) { + strcpy_P(mqttGroupName, PSTR("plates")); + changed = true; } if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) { - changed |= mqttServer != settings[FPSTR(FP_CONFIG_HOST)].as(); - mqttServer = settings[FPSTR(FP_CONFIG_HOST)].as(); + changed |= strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)]) != 0; + strncpy(mqttServer, settings[FPSTR(FP_CONFIG_HOST)], sizeof(mqttServer)); } if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) { - changed |= mqttUser != settings[FPSTR(FP_CONFIG_USER)].as(); - mqttUser = settings[FPSTR(FP_CONFIG_USER)].as(); + changed |= strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)]) != 0; + strncpy(mqttUser, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUser)); } if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() && settings[FPSTR(FP_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) { - changed |= mqttPassword != settings[FPSTR(FP_CONFIG_PASS)].as(); - mqttPassword = settings[FPSTR(FP_CONFIG_PASS)].as(); + changed |= strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)]) != 0; + strncpy(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(mqttPassword)); } snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), haspDevice.get_hostname()); - snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName.c_str()); + snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName); return changed; } diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 506e35f1..3a861317 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -138,7 +138,7 @@ const char HTTP_SCRIPT[] PROGMEM = "