From b791af3e41394ce06c70b821bdd3450257a4e108 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 21 Apr 2021 18:00:46 +0200 Subject: [PATCH 01/15] Restore config/submodule --- platformio.ini | 2 +- src/mqtt/hasp_mqtt_pubsubclient.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 6e51741e..7a9383b3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -60,7 +60,7 @@ build_flags = ; -- Hasp build options ---------------------------- -D HASP_VER_MAJ=0 -D HASP_VER_MIN=5 - -D HASP_VER_REV=0 + -D HASP_VER_REV=1 -D HASP_LOG_LEVEL=LOG_LEVEL_TRACE ${override.build_flags} diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index a89da106..bc1e5843 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -294,9 +294,9 @@ void mqttStart() 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); From 19a1d0576ad0070f12be90ebba0fdf9107e557df Mon Sep 17 00:00:00 2001 From: arovak Date: Wed, 21 Apr 2021 22:14:58 +0200 Subject: [PATCH 02/15] Select used fonts via user_config_override --- include/lv_conf.h | 4 ++++ include/lv_conf_v7.h | 26 +++++++++++++++++++++++++ include/user_config_override-template.h | 18 +++++++++++++++++ src/hasp/hasp_attribute.cpp | 8 ++++---- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/include/lv_conf.h b/include/lv_conf.h index 7a1d57a6..c7ea9aad 100644 --- a/include/lv_conf.h +++ b/include/lv_conf.h @@ -1,3 +1,7 @@ +#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 a4d3b2eb..74897617 100644 --- a/include/lv_conf_v7.h +++ b/include/lv_conf_v7.h @@ -367,6 +367,19 @@ 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 @@ -395,6 +408,19 @@ 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 fd01a783..02290927 100644 --- a/include/user_config_override-template.h +++ b/include/user_config_override-template.h @@ -88,6 +88,24 @@ #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 **************************************************/ diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 7378e2dd..661371b2 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -463,24 +463,24 @@ static lv_font_t* haspPayloadToFont(const char* payload) #ifndef ARDUINO_ARCH_ESP8266 #ifdef HASP_FONT_1 - case 12: + case HASP_FONT_SIZE_1: return &HASP_FONT_1; #endif #ifdef HASP_FONT_2 - case 16: + case HASP_FONT_SIZE_2: LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, HASP_FONT_2); return &HASP_FONT_2; #endif #ifdef HASP_FONT_3 - case 22: + case HASP_FONT_SIZE_3: LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, HASP_FONT_3); return &HASP_FONT_3; #endif #ifdef HASP_FONT_4 - case 28: + case HASP_FONT_SIZE_4: LOG_WARNING(TAG_ATTR, "%s %d %x", __FILE__, __LINE__, HASP_FONT_4); return &HASP_FONT_4; #endif From d30038db6edbd2f2e716e788e665d4b254c0a615 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 22 Apr 2021 01:48:51 +0200 Subject: [PATCH 03/15] Small typo and don't show warning on comment attribute --- src/hasp/hasp_attribute.cpp | 3 +++ src/hasp/hasp_attribute.h | 1 + src/hasp_config.cpp | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 7378e2dd..35684aea 100644 --- a/src/hasp/hasp_attribute.cpp +++ b/src/hasp/hasp_attribute.cpp @@ -1792,6 +1792,9 @@ 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 7a4f11f7..ca260c85 100644 --- a/src/hasp/hasp_attribute.h +++ b/src/hasp/hasp_attribute.h @@ -266,6 +266,7 @@ _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_config.cpp b/src/hasp_config.cpp index 4240ceb6..05a81875 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -380,7 +380,7 @@ void configSetup() //#if HASP_USE_SPIFFS > 0 LOG_INFO(TAG_DEBG, F("Loading debug settings")); debugSetConfig(settings[FPSTR(FP_DEBUG)]); - LOG_INFO(TAG_GPIO, F("Loading GUI settings")); + LOG_INFO(TAG_GUI, F("Loading GUI settings")); guiSetConfig(settings[FPSTR(FP_GUI)]); LOG_INFO(TAG_HASP, F("Loading HASP settings")); haspSetConfig(settings[FPSTR(FP_HASP)]); From e018baed090fceacef1432a9644706c3c2abcaab Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 22 Apr 2021 04:46:02 +0200 Subject: [PATCH 04/15] Update tests --- test/{config.yaml => config_template.yaml} | 8 +- test/test_colors.tavern.yaml | 66 +++++---- test/test_cpicker.tavern.yaml | 161 +++++++++++++++++++++ test/test_label.tavern.yaml | 35 ++--- test/test_mqtt.tavern.yaml | 4 - test/test_obj.tavern.yaml | 43 ++++-- test/test_value_str.tavern.yaml | 42 ++++-- 7 files changed, 281 insertions(+), 78 deletions(-) rename test/{config.yaml => config_template.yaml} (53%) create mode 100644 test/test_cpicker.tavern.yaml diff --git a/test/config.yaml b/test/config_template.yaml similarity index 53% rename from test/config.yaml rename to test/config_template.yaml index 8e75a5fc..af9cee27 100644 --- a/test/config.yaml +++ b/test/config_template.yaml @@ -1,11 +1,11 @@ -# config.yaml +# Copy and rename this file to config.yaml --- name: Common test information description: Connection information for MQTT Client variables: host: homeassistant.local - username: hasp - password: hasp + username: + password: port: 1883 - plate: plate35 + plate: diff --git a/test/test_colors.tavern.yaml b/test/test_colors.tavern.yaml index 32e07ac0..017fe246 100644 --- a/test/test_colors.tavern.yaml +++ b/test/test_colors.tavern.yaml @@ -1,6 +1,35 @@ # test_value_str.tavern.yaml --- -test_name: Obj Standard Properties +test_name: Colors setup + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +stages: + - name: Page 1 + mqtt_publish: + topic: hasp/{plate}/command + payload: "page 1" + mqtt_response: + topic: hasp/{plate}/state/page + payload: "1" + timeout: 1 + delay_after: 0 + +--- +test_name: Colors loop includes: - !include config.yaml @@ -77,27 +106,10 @@ marks: - btn stages: - - name: Page 1 - mqtt_publish: - topic: hasp/{plate}/command - payload: "page 1" - mqtt_response: - topic: hasp/{plate}/state/page - payload: "1" - timeout: 1 - delay_after: 0 - - name: Set bg_color mqtt_publish: - topic: hasp/{plate}/command - payload: "p[1].b[0].bg_color={color}" - delay_after: 0.02 - - - name: Clear page - mqtt_publish: - topic: hasp/{plate}/command/clearpage - payload: "" - delay_after: 0.02 + topic: hasp/{plate}/command/json + payload: '["p1b0.bg_color={color}","clearpage"]' - name: Create object mqtt_publish: @@ -109,18 +121,16 @@ stages: r: !int "{r:d}" g: !int "{g:d}" b: !int "{b:d}" - delay_after: 0.02 - name: Set bg_color mqtt_publish: topic: hasp/{plate}/command payload: "p[1].b[0].bg_color={rgb565}" - delay_after: 0.02 - name: Test named COLOR mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].text_color={color}","p[1].b[1].text_color"]' + payload: '["p1b1.text_color={color}","p1b1.text_color"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -133,13 +143,12 @@ stages: - name: Reset mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].text_color=123" - delay_after: 0.02 + payload: "p1b1.text_color=123" - name: Test hex COLOR mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].text_color={hex}","p[1].b[1].text_color"]' + payload: '["p1b1.text_color={hex}","p1b1.text_color"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -152,13 +161,12 @@ stages: - name: Reset mqtt_publish: topic: hasp/{plate}/command - payload: "p[1].b[1].text_color=529" - delay_after: 0.02 + payload: "p1b1.text_color=529" - name: Test rgb565 COLOR mqtt_publish: topic: hasp/{plate}/command/json - payload: '["p[1].b[1].text_color={rgb565}","p[1].b[1].text_color"]' + payload: '["p1b1.text_color={rgb565}","p1b1.text_color"]' mqtt_response: topic: hasp/{plate}/state/p1b1 json: diff --git a/test/test_cpicker.tavern.yaml b/test/test_cpicker.tavern.yaml new file mode 100644 index 00000000..b2568403 --- /dev/null +++ b/test/test_cpicker.tavern.yaml @@ -0,0 +1,161 @@ +# test_page.tavern.yaml +--- +test_name: Cpicker setup + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +stages: + - name: Page 1 + mqtt_publish: + topic: hasp/{plate}/command + payload: "page 1" + mqtt_response: + topic: hasp/{plate}/state/page + payload: "1" + timeout: 1 + + - name: Clear page + mqtt_publish: + topic: hasp/{plate}/command/clearpage + payload: "" + +--- +test_name: Cpicker loop + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +marks: + - parametrize: + key: + - color + - hex + - r + - g + - b + - rgb565 + vals: + - ["red", "#ff0000", 255, 0, 0, 63488] + - ["tan", "#d2b48c", 213, 182, 139, 54705] + - ["aqua", "#00ffff", 0, 255, 255, 2047] + - ["blue", "#0000ff", 0, 0, 255, 31] + - ["cyan", "#00ffff", 0, 255, 255, 2047] + - ["gold", "#ffd600", 255, 214, 0, 65184] + - ["gray", "#838183", 131, 129, 131, 33808] + - ["grey", "#838183", 131, 129, 131, 33808] + - ["lime", "#00ff00", 0, 255, 0, 2016] + - ["navy", "#000083", 0, 0, 131, 16] + - ["peru", "#cd8139", 205, 129, 57, 52263] + - ["pink", "#ffc2cd", 255, 194, 205, 65049] + - ["plum", "#dea1de", 222, 161, 222, 56603] + - ["snow", "#fffaff", 255, 250, 255, 65503] + - ["teal", "#008183", 0, 129, 131, 1040] + - ["azure", "#f6ffff", 246, 255, 255, 63487] + - ["beige", "#f6f6de", 246, 246, 222, 63419] + - ["black", "#000000", 0, 0, 0, 0] + - ["blush", "#b50000", 181, 0, 0, 45056] + - ["brown", "#a42829", 164, 40, 41, 41285] + - ["coral", "#ff7d52", 255, 125, 82, 64490] + - ["green", "#008100", 0, 129, 0, 1024] + - ["ivory", "#fffff6", 255, 255, 246, 65534] + - ["khaki", "#f6e28b", 246, 226, 139, 63281] + - ["linen", "#fff2ee", 255, 242, 238, 65436] + - ["olive", "#837d00", 131, 125, 0, 33792] + - ["wheat", "#f6dab5", 246, 218, 181, 63222] + - ["white", "#ffffff", 255, 255, 255, 65535] + - ["bisque", "#ffe6c5", 255, 230, 197, 65336] + - ["indigo", "#4a0083", 74, 0, 131, 18448] + - ["maroon", "#830000", 131, 0, 0, 32768] + - ["orange", "#ffa500", 255, 165, 0, 64800] + - ["orchid", "#de71d5", 222, 113, 213, 56218] + - ["purple", "#7b0083", 123, 0, 131, 32784] + - ["salmon", "#ff8173", 255, 129, 115, 64526] + - ["sienna", "#a44c29", 164, 76, 41, 41605] + - ["tomato", "#ff6141", 255, 97, 65, 64264] + - ["violet", "#ee81ee", 230, 129, 238, 60445] + - ["yellow", "#ffff00", 255, 255, 0, 65504] + - ["fuchsia", "#f600ff", 246, 0, 255, 63519] + - ["magenta", "#f600ff", 246, 0, 255, 63519] + - ["silver", "#c5c2c5", 197, 194, 197, 50712] + +stages: + - name: Set bg_color + mqtt_publish: + topic: hasp/{plate}/command + payload: "p[1].b[0].bg_color={color}" + + - name: Create cpicker + mqtt_publish: + topic: hasp/{plate}/command/jsonl + json: + obj: "cpicker" + id: 1 + color: "{color}" + + - name: Test named COLOR + mqtt_publish: + topic: hasp/{plate}/command + payload: "p1b1.color" + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + color: "{hex}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" + timeout: 1 + + - name: Test hex COLOR + mqtt_publish: + topic: hasp/{plate}/command/json + payload: '["p1b1.color={hex}","p1b1.color"]' + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + color: "{hex}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" + timeout: 1 + - name: Reset + mqtt_publish: + topic: hasp/{plate}/command + payload: "p1b1.color=529" + + - name: Test rgb565 COLOR + mqtt_publish: + topic: hasp/{plate}/command/json + payload: '["p1b1.color={rgb565}","p1b1.color"]' + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + color: "{hex}" + r: !int "{r:d}" + g: !int "{g:d}" + b: !int "{b:d}" + timeout: 1 diff --git a/test/test_label.tavern.yaml b/test/test_label.tavern.yaml index 207baafe..77c3ce15 100644 --- a/test/test_label.tavern.yaml +++ b/test/test_label.tavern.yaml @@ -26,13 +26,11 @@ stages: topic: hasp/{plate}/state/page payload: "1" timeout: 1 - delay_after: 0.02 - name: Clear page mqtt_publish: topic: hasp/{plate}/command/clearpage payload: "" - delay_after: 0.02 - name: Create object mqtt_publish: @@ -40,13 +38,12 @@ stages: json: objid: 12 id: 1 - delay_after: 0.02 - name: Set x mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.x=50" - delay_after: 0.02 + - name: Get x mqtt_publish: topic: hasp/{plate}/command @@ -74,7 +71,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.y=50" - delay_after: 0.02 + - name: Get y mqtt_publish: topic: hasp/{plate}/command @@ -88,7 +85,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.y=25" - delay_after: 0.02 + - name: Get y mqtt_publish: topic: hasp/{plate}/command @@ -103,7 +100,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.w=50" - delay_after: 0.02 + - name: Get w mqtt_publish: topic: hasp/{plate}/command @@ -131,7 +128,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=50" - delay_after: 0.02 + - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -145,7 +142,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=25" - delay_after: 0.02 + - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -160,7 +157,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.mode=crop" - delay_after: 0.02 + - name: Get mode mqtt_publish: topic: hasp/{plate}/command @@ -170,7 +167,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.w=50" - delay_after: 0.02 + - name: Get w mqtt_publish: topic: hasp/{plate}/command @@ -198,7 +195,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=50" - delay_after: 0.02 + - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -212,7 +209,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.h=45" - delay_after: 0.02 + - name: Get h mqtt_publish: topic: hasp/{plate}/command @@ -227,7 +224,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.enabled=0" - delay_after: 0.02 + - name: Get enabled mqtt_publish: topic: hasp/{plate}/command @@ -241,7 +238,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.enabled=1" - delay_after: 0.02 + - name: Get enabled mqtt_publish: topic: hasp/{plate}/command @@ -256,7 +253,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.hidden=1" - delay_after: 0.02 + - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -280,7 +277,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.hidden=0" - delay_after: 0.02 + - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -304,7 +301,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.vis=0" - delay_after: 0.02 + - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -328,7 +325,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.vis=1" - delay_after: 0.02 + - name: Get hidden mqtt_publish: topic: hasp/{plate}/command diff --git a/test/test_mqtt.tavern.yaml b/test/test_mqtt.tavern.yaml index c0aa526a..43c0825c 100644 --- a/test/test_mqtt.tavern.yaml +++ b/test/test_mqtt.tavern.yaml @@ -88,7 +88,6 @@ stages: topic: hasp/{plate}/LWT payload: "offline" timeout: 20 - delay_after: 0 --- test_name: Idle States @@ -114,7 +113,6 @@ stages: topic: hasp/{plate}/state/idle payload: "long" timeout: 190 - delay_after: 0 - name: Test idle mqtt_publish: @@ -124,7 +122,6 @@ stages: topic: hasp/{plate}/state/idle payload: "short" timeout: 70 - delay_after: 0 - name: Test idle mqtt_publish: @@ -134,4 +131,3 @@ stages: topic: hasp/{plate}/state/idle payload: "off" timeout: 1 - delay_after: 0 diff --git a/test/test_obj.tavern.yaml b/test/test_obj.tavern.yaml index 8f2cd522..44fada5a 100644 --- a/test/test_obj.tavern.yaml +++ b/test/test_obj.tavern.yaml @@ -1,6 +1,34 @@ # test_page.tavern.yaml --- -test_name: Obj Standard Properties +test_name: Objects Standard Properties Setup + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +stages: + - name: Page 1 + mqtt_publish: + topic: hasp/{plate}/command + payload: "page 1" + mqtt_response: + topic: hasp/{plate}/state/page + payload: "1" + timeout: 1 + +--- +test_name: Objects Standard Properties Loop includes: - !include config.yaml @@ -90,13 +118,11 @@ stages: topic: hasp/{plate}/state/page payload: "1" timeout: 1 - delay_after: 0 - name: Clear page mqtt_publish: topic: hasp/{plate}/command/clearpage payload: "" - delay_after: 0.2 - name: Create object mqtt_publish: @@ -106,7 +132,6 @@ stages: id: 1 x: 128 y: 128 - delay_after: 0 - name: Test y mqtt_publish: @@ -142,7 +167,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command/json payload: '["p1b1.h={h}","p1b1.h"]' - delay_after: 0 + mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -153,7 +178,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command/json payload: '["p1b1.enabled={hidden}","p1b1.enabled"]' - delay_after: 0 + mqtt_response: topic: hasp/{plate}/state/p1b1 json: @@ -164,7 +189,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.vis={hidden}" - delay_after: 0 + - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -188,7 +213,7 @@ stages: mqtt_publish: topic: hasp/{plate}/command payload: "p1b1.hidden={hidden}" - delay_after: 0 + - name: Get hidden mqtt_publish: topic: hasp/{plate}/command @@ -233,7 +258,7 @@ stages: mqtt_publish: topic: "hasp/{plate}/command/p1b1.value_str" payload: "{str1}{str2}" - delay_after: 0.05 + - name: Get value_str mqtt_publish: topic: hasp/{plate}/command diff --git a/test/test_value_str.tavern.yaml b/test/test_value_str.tavern.yaml index ec85b53d..7c8654cd 100644 --- a/test/test_value_str.tavern.yaml +++ b/test/test_value_str.tavern.yaml @@ -1,6 +1,34 @@ # test_value_str.tavern.yaml --- -test_name: Obj Standard Properties +test_name: Value String Setup + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +stages: + - name: Page 1 + mqtt_publish: + topic: hasp/{plate}/command/json + payload: '["page 1","clearpage"]' + mqtt_response: + topic: hasp/{plate}/state/page + payload: "1" + timeout: 1 + +--- +test_name: Value String Loop includes: - !include config.yaml @@ -74,16 +102,6 @@ marks: - "" stages: - - name: Page 1 - mqtt_publish: - topic: hasp/{plate}/command - payload: "page 1" - mqtt_response: - topic: hasp/{plate}/state/page - payload: "1" - timeout: 1 - delay_after: 0 - - name: Create object mqtt_publish: topic: hasp/{plate}/command/jsonl @@ -94,13 +112,11 @@ stages: y: 0 w: 240 h: 240 - delay_after: 0 - name: Set value_str mqtt_publish: topic: "hasp/{plate}/command/p[1].b[1].value_str" payload: "{str1}{str2}" - delay_after: 0 - name: Get value_str mqtt_publish: topic: hasp/{plate}/command From 0aece4f29f34c58e76edc8b2f90b668ec88a3e7f Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 22 Apr 2021 05:18:58 +0200 Subject: [PATCH 05/15] Update tests --- .gitignore | 3 +- test/test_cpicker.tavern.yaml | 66 +++++++++++++++++++++++++++++++++ test/test_label.tavern.yaml | 66 +++++++++++++++++++++++++++++++++ test/test_mqtt.tavern.yaml | 40 ++++++++++++-------- test/test_value_str.tavern.yaml | 9 ++++- 5 files changed, 166 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index eac47ff6..ab6f693b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,12 +5,13 @@ .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/test/test_cpicker.tavern.yaml b/test/test_cpicker.tavern.yaml index b2568403..143636bf 100644 --- a/test/test_cpicker.tavern.yaml +++ b/test/test_cpicker.tavern.yaml @@ -159,3 +159,69 @@ stages: g: !int "{g:d}" b: !int "{b:d}" timeout: 1 + +--- +test_name: Value String Loop + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +marks: + - parametrize: + key: str1 + vals: + - "Test 123456 longer strings work too" + - "The cat stretched." + - "Jacob stood on his tiptoes." + - "The car turned the corner." + - "Kelly twirled in circles." + - "She opened the door." + - "Aaron made a picture." + - "I'm sorry." + - huey + - dewey + - "" + + - parametrize: + key: str2 + vals: + - louie + - " I danced." + - " Oak is strong and also gives shade." + - " Cats and dogs each hate the other." + - " The pipe began to rust while new." + - " Open the crate but don't break the glass." + - " Add the sum to the product of these three." + - " Thieves who rob friends deserve jail." + - " The ripe taste of cheese improves with age." + - " Act on these orders with great speed." + - " The hog crawled under the high fence." + - " Move the vat over the hot fire." + - "" + +stages: + - name: Set value_str + mqtt_publish: + topic: "hasp/{plate}/command/p1b1.value_str" + payload: "{str1}{str2}" + - name: Get value_str + mqtt_publish: + topic: hasp/{plate}/command + payload: "p1b1.value_str" + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + value_str: "{str1}{str2}" + timeout: 1 diff --git a/test/test_label.tavern.yaml b/test/test_label.tavern.yaml index 77c3ce15..0d564d17 100644 --- a/test/test_label.tavern.yaml +++ b/test/test_label.tavern.yaml @@ -344,3 +344,69 @@ stages: json: vis: 1 timeout: 1 + +--- +test_name: Value String Loop + +includes: + - !include config.yaml + +paho-mqtt: + client: + transport: tcp + client_id: tavern-tester + connect: + host: "{host}" + port: !int "{port:d}" + timeout: 3 + auth: + username: "{username}" + password: "{password}" + +marks: + - parametrize: + key: str1 + vals: + - "Test 123456 longer strings work too" + - "The cat stretched." + - "Jacob stood on his tiptoes." + - "The car turned the corner." + - "Kelly twirled in circles." + - "She opened the door." + - "Aaron made a picture." + - "I'm sorry." + - huey + - dewey + - "" + + - parametrize: + key: str2 + vals: + - louie + - " I danced." + - " Oak is strong and also gives shade." + - " Cats and dogs each hate the other." + - " The pipe began to rust while new." + - " Open the crate but don't break the glass." + - " Add the sum to the product of these three." + - " Thieves who rob friends deserve jail." + - " The ripe taste of cheese improves with age." + - " Act on these orders with great speed." + - " The hog crawled under the high fence." + - " Move the vat over the hot fire." + - "" + +stages: + - name: Set value_str + mqtt_publish: + topic: "hasp/{plate}/command/p1b1.value_str" + payload: "{str1}{str2}" + - name: Get value_str + mqtt_publish: + topic: hasp/{plate}/command + payload: "p1b1.value_str" + mqtt_response: + topic: hasp/{plate}/state/p1b1 + json: + value_str: "{str1}{str2}" + timeout: 1 diff --git a/test/test_mqtt.tavern.yaml b/test/test_mqtt.tavern.yaml index 43c0825c..d3bba97c 100644 --- a/test/test_mqtt.tavern.yaml +++ b/test/test_mqtt.tavern.yaml @@ -26,7 +26,7 @@ stages: topic: hasp/{plate}/state/page payload: "1" timeout: 1 - delay_after: 0 + - name: step 2 - Page test mqtt_publish: topic: hasp/{plate}/command @@ -35,7 +35,7 @@ stages: topic: hasp/{plate}/state/page payload: "2" timeout: 1 - delay_after: 0 + - name: step 3 - Page test mqtt_publish: topic: hasp/{plate}/command @@ -44,7 +44,7 @@ stages: topic: hasp/{plate}/state/page payload: "3" timeout: 1 - delay_after: 0 + - name: step 4 - Page test mqtt_publish: topic: hasp/{plate}/command/json @@ -53,7 +53,7 @@ stages: topic: hasp/{plate}/state/page payload: "1" timeout: 1 - delay_after: 0 + - name: step 5 - Page test mqtt_publish: topic: hasp/{plate}/command/json @@ -62,7 +62,6 @@ stages: topic: hasp/{plate}/state/page payload: "1" timeout: 1 - delay_after: 0 --- test_name: Reboot Command @@ -77,9 +76,18 @@ paho-mqtt: connect: host: "{host}" port: !int "{port:d}" - timeout: 1 + timeout: 3 + auth: + username: "{username}" + password: "{password}" stages: + - name: Lower idle values + mqtt_publish: + topic: hasp/{plate}/config/gui + json: + idle1: 6 + idle2: 13 - name: Test reboot command mqtt_publish: topic: hasp/{plate}/command/reboot @@ -103,6 +111,9 @@ paho-mqtt: host: "{host}" port: !int "{port:d}" timeout: 3 + auth: + username: "{username}" + password: "{password}" stages: - name: Test idle @@ -111,17 +122,16 @@ stages: payload: "wakeup" mqtt_response: topic: hasp/{plate}/state/idle - payload: "long" - timeout: 190 - - - name: Test idle - mqtt_publish: - topic: hasp/{plate}/command - payload: "wakeup" + payload: "off" + timeout: 5 mqtt_response: topic: hasp/{plate}/state/idle payload: "short" - timeout: 70 + timeout: 15 + mqtt_response: + topic: hasp/{plate}/state/idle + payload: "long" + timeout: 30 - name: Test idle mqtt_publish: @@ -130,4 +140,4 @@ stages: mqtt_response: topic: hasp/{plate}/state/idle payload: "off" - timeout: 1 + timeout: 5 diff --git a/test/test_value_str.tavern.yaml b/test/test_value_str.tavern.yaml index 7c8654cd..0db2e70f 100644 --- a/test/test_value_str.tavern.yaml +++ b/test/test_value_str.tavern.yaml @@ -49,13 +49,13 @@ marks: - parametrize: key: obj vals: - - cpicker + # - cpicker - table - tabview - chart - gauge - btn - - label + # - label - slider - checkbox - switch @@ -102,6 +102,11 @@ marks: - "" stages: + - name: Clear page + mqtt_publish: + topic: hasp/{plate}/command + payload: clearpage + - name: Create object mqtt_publish: topic: hasp/{plate}/command/jsonl From b3e7f6d0e37ec681e522cfd79108c9ab9a3917c2 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 23 Apr 2021 00:41:53 +0200 Subject: [PATCH 06/15] Patch memory leak --- src/hasp/hasp_event.cpp | 11 +++++++++++ src/hasp/hasp_event.h | 1 + src/hasp/hasp_object.cpp | 27 ++++++++++++++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/hasp/hasp_event.cpp b/src/hasp/hasp_event.cpp index ca254cd6..7e546f5f 100644 --- a/src/hasp/hasp_event.cpp +++ b/src/hasp/hasp_event.cpp @@ -555,3 +555,14 @@ 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 9b82950a..b113575f 100644 --- a/src/hasp/hasp_event.h +++ b/src/hasp/hasp_event.h @@ -18,6 +18,7 @@ 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 f1c09788..c6beef08 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -489,16 +489,20 @@ 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; - // No event handler for pages + if(obj) { + obj->user_data.objid = LV_HASP_PAGE; + lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation + } 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; - // No event handler for pages + if(obj) { + obj->user_data.objid = LV_HASP_WINDOW; + lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation + } break; #endif @@ -550,16 +554,18 @@ 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; - - // No event handler for tileviews + if(obj) { + obj->user_data.objid = LV_HASP_TILEVIEW; + lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation + } 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); @@ -587,7 +593,10 @@ 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; + if(obj) { + obj->user_data.objid = LV_HASP_SPINNER; + lv_obj_set_event_cb(obj, deleted_event_handler); // Needed for memory dealocation + } break; #endif From 761b3f02f31415095e08699e63b3d4dc256b2cb5 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 23 Apr 2021 17:53:44 +0200 Subject: [PATCH 07/15] Improved reliability when creating/removing lots of value_str or objects --- platformio.ini | 1 + src/hasp/hasp_attribute.cpp | 35 ++++++++++------------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7a9383b3..3aab2a92 100644 --- a/platformio.ini +++ b/platformio.ini @@ -49,6 +49,7 @@ 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 ---------------------------- diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp index 547a0a8e..f72b7831 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__); - const void* value_str_p = lv_obj_get_style_value_str(obj, part); + void* value_str_p = (void*)lv_obj_get_style_value_str(obj, part); lv_obj_invalidate(obj); if(text == NULL || text[0] == 0) { @@ -262,36 +262,21 @@ 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__); } From 489a3214734c7925b9ea11d2fcb7e9e8381b12e4 Mon Sep 17 00:00:00 2001 From: arovak Date: Fri, 23 Apr 2021 20:43:58 +0200 Subject: [PATCH 08/15] allow gpio template via user_config_override --- src/hasp_config.cpp | 9 ++++++++- src/hasp_config.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 05a81875..3f2b08c9 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -152,6 +152,13 @@ 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 } /* @@ -380,7 +387,7 @@ void configSetup() //#if HASP_USE_SPIFFS > 0 LOG_INFO(TAG_DEBG, F("Loading debug settings")); debugSetConfig(settings[FPSTR(FP_DEBUG)]); - LOG_INFO(TAG_GUI, F("Loading GUI settings")); + LOG_INFO(TAG_GPIO, F("Loading GUI settings")); guiSetConfig(settings[FPSTR(FP_GUI)]); LOG_INFO(TAG_HASP, F("Loading HASP settings")); haspSetConfig(settings[FPSTR(FP_HASP)]); diff --git a/src/hasp_config.h b/src/hasp_config.h index 77eb6e01..99224b06 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -71,6 +71,10 @@ 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 From a8c40ab7e1ffc00ba45bc4723351192528bc1120 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 23 Apr 2021 21:11:48 +0200 Subject: [PATCH 09/15] Code clean-up --- src/hasp_debug.h | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/src/hasp_debug.h b/src/hasp_debug.h index dc1e92c2..615308b8 100644 --- a/src/hasp_debug.h +++ b/src/hasp_debug.h @@ -85,46 +85,6 @@ 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 From 84e0e45b90727a0cd5c1a54d59494511194bd915 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Fri, 23 Apr 2021 22:58:29 +0200 Subject: [PATCH 10/15] Allow for longer mqtt configuration strings #150 --- src/mqtt/hasp_mqtt_pubsubclient.cpp | 59 ++++++++++++++++------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index bc1e5843..17eaa93f 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -81,12 +81,16 @@ bool mqttHAautodiscover = true; #define LWT_TOPIC "LWT" -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; +// 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; PubSubClient mqttClient(mqttNetworkClient); int mqttPublish(const char* topic, const char* payload, size_t len, bool retain) @@ -224,7 +228,7 @@ void mqttStart() static uint8_t mqttReconnectCount = 0; // bool mqttFirstConnect = true; - mqttClient.setServer(mqttServer, 1883); + mqttClient.setServer(mqttServer.c_str(), 1883); // mqttClient.setSocketTimeout(10); //in seconds /* Construct unique Client ID*/ @@ -242,7 +246,8 @@ void mqttStart() haspProgressMsg(F(D_MQTT_CONNECTING)); haspProgressVal(mqttReconnectCount * 5); - if(!mqttClient.connect(mqttClientId, mqttUser, mqttPassword, buffer, 0, true, lastWillPayload, true)) { + if(!mqttClient.connect(mqttClientId, mqttUser.c_str(), mqttPassword.c_str(), buffer, 0, true, lastWillPayload, + true)) { // Retry until we give up and restart after connectTimeout seconds mqttReconnectCount++; @@ -287,7 +292,7 @@ void mqttStart() return; } - LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer, mqttClientId); + LOG_INFO(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer.c_str(), mqttClientId); // Subscribe to our incoming topics const __FlashStringHelper* F_topic; @@ -323,9 +328,9 @@ void mqttStart() void mqttSetup() { - mqttEnabled = strlen(mqttServer) > 0 && mqttPort > 0; + mqttEnabled = mqttServer.length() > 0 && mqttPort > 0; if(mqttEnabled) { - mqttClient.setServer(mqttServer, mqttPort); + mqttClient.setServer(mqttServer.c_str(), mqttPort); mqttClient.setCallback(mqtt_message_cb); // if(!mqttClient.setBufferSize(1024)) { // LOG_ERROR(TAG_MQTT, F("Buffer allocation failed")); @@ -373,19 +378,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(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as().c_str()) != 0) changed = true; + if(mqttGroupName != settings[FPSTR(FP_CONFIG_GROUP)].as()) changed = true; settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName; - if(strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true; + if(mqttServer != settings[FPSTR(FP_CONFIG_HOST)].as()) 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(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true; + if(mqttUser != settings[FPSTR(FP_CONFIG_USER)].as().c_str()) changed = true; settings[FPSTR(FP_CONFIG_USER)] = mqttUser; - if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true; + if(mqttPassword != settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) changed = true; settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword; if(changed) configOutput(settings, TAG_MQTT); @@ -423,33 +428,33 @@ bool mqttSetConfig(const JsonObject& settings) } if(!settings[FPSTR(FP_CONFIG_GROUP)].isNull()) { - changed |= strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)]) != 0; - strncpy(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)], sizeof(mqttGroupName)); + changed |= mqttGroupName != settings[FPSTR(FP_CONFIG_GROUP)].as(); + mqttGroupName = settings[FPSTR(FP_CONFIG_GROUP)].as(); } - if(strlen(mqttGroupName) == 0) { - strcpy_P(mqttGroupName, PSTR("plates")); - changed = true; + if(mqttGroupName.length() == 0) { + mqttGroupName = String(F("plates")).c_str(); + changed = true; } if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) { - changed |= strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)]) != 0; - strncpy(mqttServer, settings[FPSTR(FP_CONFIG_HOST)], sizeof(mqttServer)); + changed |= mqttServer != settings[FPSTR(FP_CONFIG_HOST)].as(); + mqttServer = settings[FPSTR(FP_CONFIG_HOST)].as(); } if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) { - changed |= strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)]) != 0; - strncpy(mqttUser, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUser)); + changed |= mqttUser != settings[FPSTR(FP_CONFIG_USER)].as(); + mqttUser = settings[FPSTR(FP_CONFIG_USER)].as(); } if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() && settings[FPSTR(FP_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) { - changed |= strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)]) != 0; - strncpy(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(mqttPassword)); + changed |= mqttPassword != settings[FPSTR(FP_CONFIG_PASS)].as(); + mqttPassword = settings[FPSTR(FP_CONFIG_PASS)].as(); } snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), haspDevice.get_hostname()); - snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName); + snprintf_P(mqttGroupTopic, sizeof(mqttGroupTopic), PSTR(MQTT_PREFIX "/%s/"), mqttGroupName.c_str()); return changed; } From 2fdf8d4e473e6aba34571621d1151e62dd1f5fcc Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 24 Apr 2021 04:41:13 +0200 Subject: [PATCH 11/15] Add Model --- src/dev/device.cpp | 14 ++++++++++++++ src/dev/device.h | 1 + src/dev/esp32/esp32.cpp | 3 +++ src/hasp/hasp_dispatch.cpp | 6 ++++-- src/sys/svc/hasp_http.cpp | 3 +++ user_setups/darwin_sdl/darwin_sdl_64bits.ini | 2 ++ user_setups/esp32/arduitouch-esp32_ili9341.ini | 1 + user_setups/esp32/esp32-touchdown.ini | 1 + user_setups/esp32/freetouchdeck.ini | 1 + user_setups/esp32/huzzah32-featherwing-24.ini | 2 ++ user_setups/esp32/huzzah32-featherwing-35.ini | 2 ++ user_setups/esp32/lanbon_l8.ini | 1 + user_setups/esp32/m5stack_core2.ini | 1 + user_setups/esp32/ttgo-esp32-lilygo-pi.ini | 1 + user_setups/esp32/wt32-sc01.ini | 1 + user_setups/linux_sdl/linux_sdl_64bits.ini | 2 ++ user_setups/win32/windows_sdl_64bits.ini | 2 ++ 17 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/dev/device.cpp b/src/dev/device.cpp index 395a6e43..cf7deb75 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -1,2 +1,16 @@ /* MIT License - Copyright (c) 2019-2021 Francis Van Roie For full license information read the LICENSE file in the project folder */ + +#include "device.h" + +namespace dev { + +const char* BaseDevice::get_model() +{ +#ifdef HASP_MODEL + return 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 68d1867a..2cca34c7 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -41,6 +41,7 @@ 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 6cc4693a..66fe647f 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -37,14 +37,17 @@ 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_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index f26e7b72..2fdeaaf7 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -926,8 +926,10 @@ void dispatch_output_statusupdate(const char*, const char*) haspGetVersion(buffer, sizeof(buffer)); dispatch_get_idle_state(hasp_sleep_state, topic); - snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"), - haspDevice.get_hostname(), topic, buffer, long(millis() / 1000)); // \"status\":\"available\", + snprintf_P(data, sizeof(data), + PSTR("{\"node\":\"%s\",\"model\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"), + haspDevice.get_hostname(), haspDevice.get_model(), topic, buffer, + (unsigned long)(millis() / 1000)); // \"status\":\"available\", #if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0 network_get_statusupdate(buffer, sizeof(buffer)); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 7a74d919..cedad49f 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -528,6 +528,9 @@ void webHandleInfo() httpMessage += haspDevice.get_hostname(); httpMessage += F("
"); + httpMessage += F("HASP Model: "); + httpMessage += haspDevice.get_model(); + /* HASP Stats */ httpMessage += F("HASP Version: "); { diff --git a/user_setups/darwin_sdl/darwin_sdl_64bits.ini b/user_setups/darwin_sdl/darwin_sdl_64bits.ini index 65b99594..d26c7676 100644 --- a/user_setups/darwin_sdl/darwin_sdl_64bits.ini +++ b/user_setups/darwin_sdl/darwin_sdl_64bits.ini @@ -6,6 +6,8 @@ extra_scripts = tools/linux_build_extra.py build_flags = ${env.build_flags} + -D HASP_MODEL="MacOS X" + ; ----- Monitor -D TFT_WIDTH=240 -D TFT_HEIGHT=320 diff --git a/user_setups/esp32/arduitouch-esp32_ili9341.ini b/user_setups/esp32/arduitouch-esp32_ili9341.ini index aa540645..f822bb65 100644 --- a/user_setups/esp32/arduitouch-esp32_ili9341.ini +++ b/user_setups/esp32/arduitouch-esp32_ili9341.ini @@ -12,6 +12,7 @@ board = esp32dev build_flags = ${env.build_flags} ${esp32.build_flags} + -D HASP_MODEL="Arduitouch" ;region -- TFT_eSPI build options ------------------------ ${lcd.lolin24} diff --git a/user_setups/esp32/esp32-touchdown.ini b/user_setups/esp32/esp32-touchdown.ini index 61ae1322..d8bb6c3c 100644 --- a/user_setups/esp32/esp32-touchdown.ini +++ b/user_setups/esp32/esp32-touchdown.ini @@ -12,6 +12,7 @@ build_flags = ${env.build_flags} ${esp32.build_flags} ${esp32.vspi} ; Use VSPI hardware SPI bus + -D HASP_MODEL="ESP32-Touchdown" ;region -- TFT_eSPI build options ------------------------ -D USER_SETUP_LOADED=1 diff --git a/user_setups/esp32/freetouchdeck.ini b/user_setups/esp32/freetouchdeck.ini index 9bd6aebf..de662271 100644 --- a/user_setups/esp32/freetouchdeck.ini +++ b/user_setups/esp32/freetouchdeck.ini @@ -11,6 +11,7 @@ board = esp32dev build_flags = ${env.build_flags} ${esp32.build_flags} + -D HASP_MODEL="FreeTouchDeck" ;region -- TFT_eSPI build options ------------------------ -D USER_SETUP_LOADED=1 diff --git a/user_setups/esp32/huzzah32-featherwing-24.ini b/user_setups/esp32/huzzah32-featherwing-24.ini index 2c1d23fc..ed93df51 100644 --- a/user_setups/esp32/huzzah32-featherwing-24.ini +++ b/user_setups/esp32/huzzah32-featherwing-24.ini @@ -12,6 +12,8 @@ board = featheresp32 build_flags = ${env.build_flags} ${esp32.build_flags} + -D HASP_MODEL="Featherwing 2.4" + ;region -- TFT_eSPI build options ------------------------ ${lcd.featherwing-24} -D TFT_MISO=19 diff --git a/user_setups/esp32/huzzah32-featherwing-35.ini b/user_setups/esp32/huzzah32-featherwing-35.ini index 0555d4b4..1734b376 100644 --- a/user_setups/esp32/huzzah32-featherwing-35.ini +++ b/user_setups/esp32/huzzah32-featherwing-35.ini @@ -12,6 +12,8 @@ board = featheresp32 build_flags = ${env.build_flags} ${esp32.build_flags} + -D HASP_MODEL="Featherwing 3.5" + ;region -- TFT_eSPI build options ------------------------ ${lcd.featherwing-35} -D TFT_MISO=19 diff --git a/user_setups/esp32/lanbon_l8.ini b/user_setups/esp32/lanbon_l8.ini index 780fb0ab..0fad7ef0 100644 --- a/user_setups/esp32/lanbon_l8.ini +++ b/user_setups/esp32/lanbon_l8.ini @@ -17,6 +17,7 @@ build_flags = ${env.build_flags} ${esp32.build_flags} ${esp32.ps_ram} + -D HASP_MODEL="Lanbon L8" ;region -- TFT_eSPI build options ------------------------ ${lcd.st7789v} diff --git a/user_setups/esp32/m5stack_core2.ini b/user_setups/esp32/m5stack_core2.ini index 7eaa0427..9ca1a8b4 100644 --- a/user_setups/esp32/m5stack_core2.ini +++ b/user_setups/esp32/m5stack_core2.ini @@ -17,6 +17,7 @@ build_flags = ${env.build_flags} ${esp32.build_flags} ${esp32.ps_ram} + -D HASP_MODEL="M5Stack core2" ;region -- TFT_eSPI build options ------------------------ ${lcd.m5stack} diff --git a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini index d6bffca3..13420a45 100644 --- a/user_setups/esp32/ttgo-esp32-lilygo-pi.ini +++ b/user_setups/esp32/ttgo-esp32-lilygo-pi.ini @@ -17,6 +17,7 @@ build_flags = ${env.build_flags} ${esp32.build_flags} ${esp32.ps_ram} + -D HASP_MODEL="TTGO Lilygo Pi" ;region -- TFT_eSPI build options ------------------------ -D ILI9481_DRIVER=1 diff --git a/user_setups/esp32/wt32-sc01.ini b/user_setups/esp32/wt32-sc01.ini index 7b489c3f..6dfeb9db 100644 --- a/user_setups/esp32/wt32-sc01.ini +++ b/user_setups/esp32/wt32-sc01.ini @@ -13,6 +13,7 @@ build_flags = ${env.build_flags} ${esp32.build_flags} ${esp32.ps_ram} + -D HASP_MODEL="WT32-SC01" ;region -- TFT_eSPI build options ------------------------ ${lcd.wt32-sc01} diff --git a/user_setups/linux_sdl/linux_sdl_64bits.ini b/user_setups/linux_sdl/linux_sdl_64bits.ini index 33fb9537..7750398d 100644 --- a/user_setups/linux_sdl/linux_sdl_64bits.ini +++ b/user_setups/linux_sdl/linux_sdl_64bits.ini @@ -5,6 +5,8 @@ extra_scripts = tools/linux_build_extra.py build_flags = ${env.build_flags} + -D HASP_MODEL="Posix Linux" + ; ----- Monitor -D TFT_WIDTH=240 -D TFT_HEIGHT=320 diff --git a/user_setups/win32/windows_sdl_64bits.ini b/user_setups/win32/windows_sdl_64bits.ini index a679a63d..40de8761 100644 --- a/user_setups/win32/windows_sdl_64bits.ini +++ b/user_setups/win32/windows_sdl_64bits.ini @@ -5,6 +5,8 @@ extra_scripts = tools/windows_build_extra.py build_flags = ${env.build_flags} + -D HASP_MODEL="Windows" + ; ----- Monitor -D TFT_WIDTH=240 -D TFT_HEIGHT=320 From 5e4316cd3e9792e36c31ead42e8ddaf7a7196850 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 24 Apr 2021 05:00:11 +0200 Subject: [PATCH 12/15] Add manufacturer --- src/hasp/hasp_dispatch.cpp | 12 +++--------- src/sys/svc/hasp_http.cpp | 6 +++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 2fdeaaf7..1d5a0cd9 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -919,7 +919,7 @@ void dispatch_output_statusupdate(const char*, const char*) { #if HASP_USE_MQTT > 0 - char data[400]; + char data[512]; char topic[16]; { char buffer[128]; @@ -927,7 +927,8 @@ void dispatch_output_statusupdate(const char*, const char*) haspGetVersion(buffer, sizeof(buffer)); dispatch_get_idle_state(hasp_sleep_state, topic); snprintf_P(data, sizeof(data), - PSTR("{\"node\":\"%s\",\"model\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"), + 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\", @@ -961,13 +962,6 @@ 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/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index cedad49f..de87977b 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -138,7 +138,7 @@ const char HTTP_SCRIPT[] PROGMEM = "