mirror of https://github.com/arendst/Tasmota.git
Fix handling deafult names
Fix handling use of default names when using names starting with shortcut character (#3392, #3600)
This commit is contained in:
parent
d69e88b50b
commit
9978381c94
|
@ -1,5 +1,7 @@
|
|||
/* 6.1.1.12 20180827
|
||||
* Add commands ButtonDebounce 40..1000 and SwitchDebounce 40..1000 to have more control over debounce timing. Default is 50mS (#3594)
|
||||
* Add commands ButtonDebounce 40..1000 and SwitchDebounce 40..1000 to have user control over debounce timing. Default is 50mS (#3594)
|
||||
* Add rule variables %sunrise%, %sunset%, %uptime% and %time% (#3608)
|
||||
* Fix handling use of default names when using names starting with shortcut character (#3392, #3600)
|
||||
*
|
||||
* 6.1.1.11 20180826
|
||||
* Change scheduler phase 1/3 - Fixed when sleep is enabled: Uptime, Delay, PulseTime and TelePeriod (#3581)
|
||||
|
|
|
@ -612,8 +612,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
}
|
||||
else if (CMND_OTAURL == command_code) {
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.ota_url)))
|
||||
strlcpy(Settings.ota_url, (1 == payload) ? OTA_URL : dataBuf, sizeof(Settings.ota_url));
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.ota_url))) {
|
||||
strlcpy(Settings.ota_url, (1 == Shortcut(dataBuf)) ? OTA_URL : dataBuf, sizeof(Settings.ota_url));
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.ota_url);
|
||||
}
|
||||
else if (CMND_SERIALLOG == command_code) {
|
||||
|
@ -953,13 +954,13 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
else if (CMND_BUTTONDEBOUNCE == command_code) {
|
||||
if ((payload > 39) && (payload < 1001)) {
|
||||
Settings.button_debounce = payload16;
|
||||
Settings.button_debounce = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.button_debounce);
|
||||
}
|
||||
else if (CMND_SWITCHDEBOUNCE == command_code) {
|
||||
if ((payload > 39) && (payload < 1001)) {
|
||||
Settings.switch_debounce = payload16;
|
||||
Settings.switch_debounce = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.switch_debounce);
|
||||
}
|
||||
|
@ -1013,12 +1014,14 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
else if (CMND_LOGHOST == command_code) {
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.syslog_host))) {
|
||||
strlcpy(Settings.syslog_host, (1 == payload) ? SYS_LOG_HOST : dataBuf, sizeof(Settings.syslog_host));
|
||||
strlcpy(Settings.syslog_host, (1 == Shortcut(dataBuf)) ? SYS_LOG_HOST : dataBuf, sizeof(Settings.syslog_host));
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.syslog_host);
|
||||
}
|
||||
else if (CMND_LOGPORT == command_code) {
|
||||
if (payload16 > 0) Settings.syslog_port = (1 == payload16) ? SYS_LOG_PORT : payload16;
|
||||
if (payload16 > 0) {
|
||||
Settings.syslog_port = (1 == payload16) ? SYS_LOG_PORT : payload16;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.syslog_port);
|
||||
}
|
||||
else if ((CMND_IPADDRESS == command_code) && (index > 0) && (index <= 4)) {
|
||||
|
@ -1031,7 +1034,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
else if ((CMND_NTPSERVER == command_code) && (index > 0) && (index <= 3)) {
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.ntp_server[0]))) {
|
||||
strlcpy(Settings.ntp_server[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1==index)?NTP_SERVER1:(2==index)?NTP_SERVER2:NTP_SERVER3 : dataBuf, sizeof(Settings.ntp_server[0]));
|
||||
strlcpy(Settings.ntp_server[index -1], (0 == Shortcut(dataBuf)) ? "" : (1 == Shortcut(dataBuf)) ? (1==index)?NTP_SERVER1:(2==index)?NTP_SERVER2:NTP_SERVER3 : dataBuf, sizeof(Settings.ntp_server[0]));
|
||||
for (i = 0; i < strlen(Settings.ntp_server[index -1]); i++) {
|
||||
if (Settings.ntp_server[index -1][i] == ',') Settings.ntp_server[index -1][i] = '.';
|
||||
}
|
||||
|
@ -1055,7 +1058,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
else if ((CMND_SSID == command_code) && (index > 0) && (index <= 2)) {
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.sta_ssid[0]))) {
|
||||
strlcpy(Settings.sta_ssid[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1 == index) ? STA_SSID1 : STA_SSID2 : dataBuf, sizeof(Settings.sta_ssid[0]));
|
||||
strlcpy(Settings.sta_ssid[index -1], (0 == Shortcut(dataBuf)) ? "" : (1 == Shortcut(dataBuf)) ? (1 == index) ? STA_SSID1 : STA_SSID2 : dataBuf, sizeof(Settings.sta_ssid[0]));
|
||||
Settings.sta_active = index -1;
|
||||
restart_flag = 2;
|
||||
}
|
||||
|
@ -1063,7 +1066,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
else if ((CMND_PASSWORD == command_code) && (index > 0) && (index <= 2)) {
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.sta_pwd[0]))) {
|
||||
strlcpy(Settings.sta_pwd[index -1], (!strcmp(dataBuf,"0")) ? "" : (1 == payload) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0]));
|
||||
strlcpy(Settings.sta_pwd[index -1], (0 == Shortcut(dataBuf)) ? "" : (1 == Shortcut(dataBuf)) ? (1 == index) ? STA_PASS1 : STA_PASS2 : dataBuf, sizeof(Settings.sta_pwd[0]));
|
||||
Settings.sta_active = index -1;
|
||||
restart_flag = 2;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.sta_pwd[index -1]);
|
||||
|
@ -1073,7 +1076,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
else if ((CMND_HOSTNAME == command_code) && !grpflg) {
|
||||
if ((data_len > 0) && (data_len < sizeof(Settings.hostname))) {
|
||||
strlcpy(Settings.hostname, (1 == payload) ? WIFI_HOSTNAME : dataBuf, sizeof(Settings.hostname));
|
||||
strlcpy(Settings.hostname, (1 == Shortcut(dataBuf)) ? WIFI_HOSTNAME : dataBuf, sizeof(Settings.hostname));
|
||||
if (strstr(Settings.hostname,"%")) {
|
||||
strlcpy(Settings.hostname, WIFI_HOSTNAME, sizeof(Settings.hostname));
|
||||
}
|
||||
|
@ -1103,12 +1106,14 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
} else {
|
||||
snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), index);
|
||||
}
|
||||
strlcpy(Settings.friendlyname[index -1], (1 == payload) ? stemp1 : dataBuf, sizeof(Settings.friendlyname[index -1]));
|
||||
strlcpy(Settings.friendlyname[index -1], (1 == Shortcut(dataBuf)) ? stemp1 : dataBuf, sizeof(Settings.friendlyname[index -1]));
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.friendlyname[index -1]);
|
||||
}
|
||||
else if ((CMND_SWITCHMODE == command_code) && (index > 0) && (index <= MAX_SWITCHES)) {
|
||||
if ((payload >= 0) && (payload < MAX_SWITCH_OPTION)) Settings.switchmode[index -1] = payload;
|
||||
if ((payload >= 0) && (payload < MAX_SWITCH_OPTION)) {
|
||||
Settings.switchmode[index -1] = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, index, Settings.switchmode[index-1]);
|
||||
}
|
||||
else if (CMND_TELEPERIOD == command_code) {
|
||||
|
@ -1135,7 +1140,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
}
|
||||
}
|
||||
else if (CMND_TIMEZONE == command_code) {
|
||||
if ((data_len > 0) && (((payload >= -13) && (payload <= 14)) || (99 == payload))) Settings.timezone = payload;
|
||||
if ((data_len > 0) && (((payload >= -13) && (payload <= 14)) || (99 == payload))) {
|
||||
Settings.timezone = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.timezone);
|
||||
}
|
||||
else if ((CMND_TIMESTD == command_code) || (CMND_TIMEDST == command_code)) {
|
||||
|
@ -1180,7 +1187,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
command, Settings.tflag[ts].hemis, Settings.tflag[ts].week, Settings.tflag[ts].month, Settings.tflag[ts].dow, Settings.tflag[ts].hour, Settings.toffset[ts]);
|
||||
}
|
||||
else if (CMND_ALTITUDE == command_code) {
|
||||
if ((data_len > 0) && ((payload >= -30000) && (payload <= 30000))) Settings.altitude = payload;
|
||||
if ((data_len > 0) && ((payload >= -30000) && (payload <= 30000))) {
|
||||
Settings.altitude = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.altitude);
|
||||
}
|
||||
else if (CMND_LEDPOWER == command_code) {
|
||||
|
|
|
@ -309,6 +309,23 @@ char* NoAlNumToUnderscore(char* dest, const char* source)
|
|||
return dest;
|
||||
}
|
||||
|
||||
uint8_t Shortcut(const char* str)
|
||||
{
|
||||
uint8_t result = 10;
|
||||
|
||||
if ('\0' == str[1]) { // Only allow single character input for shortcut
|
||||
if (('"' == str[0]) || ('0' == str[0])) {
|
||||
result = 0; // 0 = Empty or clear parameter
|
||||
} else {
|
||||
result = atoi(str); // 1 = Default parameter
|
||||
if (0 == result) {
|
||||
result = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean ParseIp(uint32_t* addr, const char* str)
|
||||
{
|
||||
uint8_t *part = (uint8_t*)addr;
|
||||
|
@ -1186,6 +1203,7 @@ void WiFiSetSleepMode()
|
|||
* See https://github.com/arendst/Sonoff-Tasmota/issues/2559
|
||||
*/
|
||||
|
||||
//#ifdef ARDUINO_ESP8266_RELEASE_2_4_1
|
||||
#if defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
||||
#else // Enabled in 2.3.0, 2.4.0 and stage
|
||||
if (sleep) {
|
||||
|
|
|
@ -2019,7 +2019,7 @@ bool WebCommand()
|
|||
}
|
||||
else if (CMND_WEBPASSWORD == command_code) {
|
||||
if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.web_password))) {
|
||||
strlcpy(Settings.web_password, (!strcmp(XdrvMailbox.data,"0")) ? "" : (1 == XdrvMailbox.payload) ? WEB_PASSWORD : XdrvMailbox.data, sizeof(Settings.web_password));
|
||||
strlcpy(Settings.web_password, (0 == Shortcut(XdrvMailbox.data)) ? "" : (1 == Shortcut(XdrvMailbox.data)) ? WEB_PASSWORD : XdrvMailbox.data, sizeof(Settings.web_password));
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, Settings.web_password);
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_ASTERIX, command);
|
||||
|
|
|
@ -540,13 +540,13 @@ boolean RulesCommand()
|
|||
}
|
||||
else if ((CMND_VAR == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
strlcpy(vars[index -1], ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data, sizeof(vars[index -1]));
|
||||
strlcpy(vars[index -1], (0 == Shortcut(XdrvMailbox.data)) ? "" : XdrvMailbox.data, sizeof(vars[index -1]));
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]);
|
||||
}
|
||||
else if ((CMND_MEM == command_code) && (index > 0) && (index <= MAX_RULE_MEMS)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
strlcpy(Settings.mems[index -1], ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data, sizeof(Settings.mems[index -1]));
|
||||
strlcpy(Settings.mems[index -1], (0 == Shortcut(XdrvMailbox.data)) ? "" : XdrvMailbox.data, sizeof(Settings.mems[index -1]));
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.mems[index -1]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue