From 0e0d8190fa4750c846d794aaad25f2f91b8d8259 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 12 Jan 2020 13:10:21 +0100 Subject: [PATCH] Change some commands displaying all items Change commands ``Prefix``, ``Ssid``, ``StateText``, ``NTPServer``, and ``FriendlyName`` displaying all items --- RELEASENOTES.md | 2 + tasmota/CHANGELOG.md | 1 + tasmota/settings.ino | 2 +- tasmota/support_command.ino | 69 +++++++++++++++++++++++------------ tasmota/support_tasmota.ino | 4 +- tasmota/support_wifi.ino | 2 +- tasmota/tasmota.h | 4 ++ tasmota/xdrv_01_webserver.ino | 6 +-- tasmota/xdrv_02_mqtt.ino | 35 +++++++++++------- tasmota/xdrv_10_rules.ino | 6 +-- 10 files changed, 79 insertions(+), 52 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 007b99fe2..af4aeeb73 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -55,12 +55,14 @@ The following binary downloads have been compiled with ESP8266/Arduino library c ### Version 8.1.0.3 - Change Lights: simplified gamma correction and 10 bits internal computation +- Change commands ``Prefix``, ``Ssid``, ``StateText``, ``NTPServer``, and ``FriendlyName`` displaying all items - Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging - Fix commands ``Display`` and ``Counter`` from overruling command processing (#7322) - Fix ``White`` added to light status (#7142) - Fix Improved fade linearity with gamma correction - Fix LCD line and column positioning (#7387) - Fix Display handling of hexadecimal escape characters (#7387) +- Fix ``WakeUp `` ignores provided value (#7473) - Add command ``SetOption79 0/1`` to enable reset of counters at teleperiod time by Andre Thomas (#7355) - Add command ``SetOption82 0/1`` to limit the CT range for Alexa to 200..380 - Add command ``ShutterButton `` to control shutter(s) by to-scho (#7403) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index e260285e8..f9089b818 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -2,6 +2,7 @@ ### 8.1.0.3 20200106 +- Change commands ``Prefix``, ``Ssid``, ``StateText``, ``NTPServer``, and ``FriendlyName`` displaying all items - Add support for gzipped binaries - Update IRremoteESP8266 lib updated to v2.7.2 - Fix ``WakeUp `` ignores provided value (#7473) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 0e32bc7bd..a059b71e6 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1043,7 +1043,7 @@ void SettingsDefaultSet2(void) SettingsUpdateText(SET_NTPSERVER1, NTP_SERVER1); SettingsUpdateText(SET_NTPSERVER2, NTP_SERVER2); SettingsUpdateText(SET_NTPSERVER3, NTP_SERVER3); - for (uint32_t i = 0; i < 3; i++) { + for (uint32_t i = 0; i < MAX_NTP_SERVERS; i++) { SettingsUpdateText(SET_NTPSERVER1 +i, ReplaceCommaWithDot(SettingsText(SET_NTPSERVER1 +i))); } Settings.latitude = (int)((double)LATITUDE * 1000000); diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index d754e95cc..6812085c6 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -89,6 +89,15 @@ void ResponseCmndIdxChar(const char* value) Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, value); } +void ResponseCmndAll(uint32_t text_index, uint32_t count) +{ + mqtt_data[0] = '\0'; + for (uint32_t i = 0; i < count; i++) { + ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (i) ? ',' : '{', XdrvMailbox.command, i +1, SettingsText(text_index +i)); + } + ResponseJsonEnd(); +} + /********************************************************************************************/ void ExecuteCommand(const char *cmnd, uint32_t source) @@ -1220,16 +1229,20 @@ void CmndIpAddress(void) void CmndNtpServer(void) { - if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 3)) { - uint32_t ntp_server = SET_NTPSERVER1 + XdrvMailbox.index -1; - if (XdrvMailbox.data_len > 0) { - SettingsUpdateText(ntp_server, - (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? NTP_SERVER1 : (2 == XdrvMailbox.index) ? NTP_SERVER2 : NTP_SERVER3 : XdrvMailbox.data); - SettingsUpdateText(ntp_server, ReplaceCommaWithDot(SettingsText(ntp_server))); -// restart_flag = 2; // Issue #3890 - ntp_force_sync = true; + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_NTP_SERVERS)) { + if (!XdrvMailbox.usridx) { + ResponseCmndAll(SET_NTPSERVER1, MAX_NTP_SERVERS); + } else { + uint32_t ntp_server = SET_NTPSERVER1 + XdrvMailbox.index -1; + if (XdrvMailbox.data_len > 0) { + SettingsUpdateText(ntp_server, + (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? NTP_SERVER1 : (2 == XdrvMailbox.index) ? NTP_SERVER2 : NTP_SERVER3 : XdrvMailbox.data); + SettingsUpdateText(ntp_server, ReplaceCommaWithDot(SettingsText(ntp_server))); + // restart_flag = 2; // Issue #3890 + ntp_force_sync = true; + } + ResponseCmndIdxChar(SettingsText(ntp_server)); } - ResponseCmndIdxChar(SettingsText(ntp_server)); } } @@ -1251,14 +1264,18 @@ void CmndAp(void) void CmndSsid(void) { - if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 2)) { - if (XdrvMailbox.data_len > 0) { - SettingsUpdateText(SET_STASSID1 + XdrvMailbox.index -1, - (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? STA_SSID1 : STA_SSID2 : XdrvMailbox.data); - Settings.sta_active = XdrvMailbox.index -1; - restart_flag = 2; + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_SSIDS)) { + if (!XdrvMailbox.usridx) { + ResponseCmndAll(SET_STASSID1, MAX_SSIDS); + } else { + if (XdrvMailbox.data_len > 0) { + SettingsUpdateText(SET_STASSID1 + XdrvMailbox.index -1, + (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? STA_SSID1 : STA_SSID2 : XdrvMailbox.data); + Settings.sta_active = XdrvMailbox.index -1; + restart_flag = 2; + } + ResponseCmndIdxChar(SettingsText(SET_STASSID1 + XdrvMailbox.index -1)); } - ResponseCmndIdxChar(SettingsText(SET_STASSID1 + XdrvMailbox.index -1)); } } @@ -1308,16 +1325,20 @@ void CmndWifiConfig(void) void CmndFriendlyname(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_FRIENDLYNAMES)) { - if (XdrvMailbox.data_len > 0) { - char stemp1[TOPSZ]; - if (1 == XdrvMailbox.index) { - snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME)); - } else { - snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), XdrvMailbox.index); + if (!XdrvMailbox.usridx) { + ResponseCmndAll(SET_FRIENDLYNAME1, MAX_FRIENDLYNAMES); + } else { + if (XdrvMailbox.data_len > 0) { + char stemp1[TOPSZ]; + if (1 == XdrvMailbox.index) { + snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME)); + } else { + snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), XdrvMailbox.index); + } + SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data); } - SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data); + ResponseCmndIdxChar(SettingsText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1)); } - ResponseCmndIdxChar(SettingsText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1)); } } diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d502e64c3..187c116a1 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -107,7 +107,7 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi fulltopic += F("/"); fulltopic += FPSTR(MQTT_TOKEN_PREFIX); // Need prefix for commands to handle mqtt topic loops } - for (uint32_t i = 0; i < 3; i++) { + for (uint32_t i = 0; i < MAX_MQTT_PREFIXES; i++) { if (!strlen(SettingsText(SET_MQTTPREFIX1 + i))) { char temp[TOPSZ]; SettingsUpdateText(SET_MQTTPREFIX1 + i, GetTextIndexed(temp, sizeof(temp), i, kPrefixes)); @@ -144,7 +144,7 @@ char* GetFallbackTopic_P(char *stopic, const char* subtopic) char* GetStateText(uint32_t state) { - if (state > 3) { + if (state >= MAX_STATE_TEXT) { state = 1; } return SettingsText(SET_STATE_TXT1 + state); diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 3989f8c66..954e2fb3c 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -279,7 +279,7 @@ void WifiBeginAfterScan(void) bool known = false; uint32_t j; - for (j = 0; j < 2; j++) { + for (j = 0; j < MAX_SSIDS; j++) { if (ssid_scan == SettingsText(SET_STASSID1 + j)) { // SSID match known = true; if (rssi_scan > best_network_db) { // Best network diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 32a85c80a..f0e747c27 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -73,6 +73,10 @@ const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 5 const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules // Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex +const uint8_t MAX_MQTT_PREFIXES = 3; // Max number of MQTT prefixes (cmnd, stat, tele) +const uint8_t MAX_SSIDS = 2; // Max number of SSIDs +const uint8_t MAX_STATE_TEXT = 4; // Max number of State names (OFF, ON, TOGGLE, HOLD) +const uint8_t MAX_NTP_SERVERS = 3; // Max number of NTP servers const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index eff136c7d..db0fce2a5 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -2906,11 +2906,7 @@ void CmndWebButton(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_BUTTON_TEXT)) { if (!XdrvMailbox.usridx) { - mqtt_data[0] = '\0'; - for (uint32_t i = 0; i < MAX_BUTTON_TEXT; i++) { - ResponseAppend_P(PSTR("%c\"WebButton%d\":\"%s\""), (i) ? ',' : '{', i +1, SettingsText(SET_BUTTON1 +i)); - } - ResponseJsonEnd(); + ResponseCmndAll(SET_BUTTON1, MAX_BUTTON_TEXT); } else { if (XdrvMailbox.data_len > 0) { SettingsUpdateText(SET_BUTTON1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data); diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index 5beac68f0..6096103c4 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -789,14 +789,18 @@ void CmndMqttRetry(void) void CmndStateText(void) { - if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 4)) { - if (XdrvMailbox.data_len > 0) { - for (uint32_t i = 0; i <= XdrvMailbox.data_len; i++) { - if (XdrvMailbox.data[i] == ' ') XdrvMailbox.data[i] = '_'; + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_STATE_TEXT)) { + if (!XdrvMailbox.usridx) { + ResponseCmndAll(SET_STATE_TXT1, MAX_STATE_TEXT); + } else { + if (XdrvMailbox.data_len > 0) { + for (uint32_t i = 0; i <= XdrvMailbox.data_len; i++) { + if (XdrvMailbox.data[i] == ' ') XdrvMailbox.data[i] = '_'; + } + SettingsUpdateText(SET_STATE_TXT1 + XdrvMailbox.index -1, XdrvMailbox.data); } - SettingsUpdateText(SET_STATE_TXT1 + XdrvMailbox.index -1, XdrvMailbox.data); + ResponseCmndIdxChar(GetStateText(XdrvMailbox.index -1)); } - ResponseCmndIdxChar(GetStateText(XdrvMailbox.index -1)); } } @@ -828,15 +832,18 @@ void CmndFullTopic(void) void CmndPrefix(void) { - if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 3)) { - - if (XdrvMailbox.data_len > 0) { - MakeValidMqtt(0, XdrvMailbox.data); - SettingsUpdateText(SET_MQTTPREFIX1 + XdrvMailbox.index -1, - (SC_DEFAULT == Shortcut()) ? (1==XdrvMailbox.index) ? SUB_PREFIX : (2==XdrvMailbox.index) ? PUB_PREFIX : PUB_PREFIX2 : XdrvMailbox.data); - restart_flag = 2; + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_MQTT_PREFIXES)) { + if (!XdrvMailbox.usridx) { + ResponseCmndAll(SET_MQTTPREFIX1, MAX_MQTT_PREFIXES); + } else { + if (XdrvMailbox.data_len > 0) { + MakeValidMqtt(0, XdrvMailbox.data); + SettingsUpdateText(SET_MQTTPREFIX1 + XdrvMailbox.index -1, + (SC_DEFAULT == Shortcut()) ? (1==XdrvMailbox.index) ? SUB_PREFIX : (2==XdrvMailbox.index) ? PUB_PREFIX : PUB_PREFIX2 : XdrvMailbox.data); + restart_flag = 2; + } + ResponseCmndIdxChar(SettingsText(SET_MQTTPREFIX1 + XdrvMailbox.index -1)); } - ResponseCmndIdxChar(SettingsText(SET_MQTTPREFIX1 + XdrvMailbox.index -1)); } } diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 78cb73e10..dd557a0fd 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -1812,11 +1812,7 @@ void CmndMemory(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_MEMS)) { if (!XdrvMailbox.usridx) { - mqtt_data[0] = '\0'; - for (uint32_t i = 0; i < MAX_RULE_MEMS; i++) { - ResponseAppend_P(PSTR("%c\"Mem%d\":\"%s\""), (i) ? ',' : '{', i +1, SettingsText(SET_MEM1 +i)); - } - ResponseJsonEnd(); + ResponseCmndAll(SET_MEM1, MAX_RULE_MEMS); } else { if (XdrvMailbox.data_len > 0) { #ifdef USE_EXPRESSION