Fix some exceptions and watchdogs

* Fix some exceptions and watchdogs due to lack of stack space - part 2
 * Add command SetOption62 0/1 to disable retain on Button or Swith hold messages (#5299)
 * Add option WifiConfig 7 to allow reset of device in AP mode without admin password (#5297)
This commit is contained in:
Theo Arends 2019-02-22 12:04:05 +01:00
parent 8df6bb76d1
commit 49f0b514eb
3 changed files with 21 additions and 20 deletions

View File

@ -1,5 +1,8 @@
/* 6.4.1.18 20191221
* Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
* Fix some exceptions and watchdogs due to lack of stack space - part 2
* Add command SetOption62 0/1 to disable retain on Button or Swith hold messages (#5299)
* Add option WifiConfig 7 to allow reset of device in AP mode without admin password (#5297)
*
* 6.4.1.17 20190214
* Change template update by removing possibility to add user module config keeping template as defined (#5222)

View File

@ -866,9 +866,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
restart_flag = 2;
}
uint8_t module = Settings.module;
if (USER_MODULE == Settings.module) { module = 0; } else { module++; }
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SVALUE, command, module, ModuleName().c_str());
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str());
}
else if (CMND_MODULES == command_code) {
for (uint8_t i = 0; i <= MAXMODULE; i++) {
@ -1566,8 +1564,6 @@ void StopAllPowerBlink(void)
void ExecuteCommand(char *cmnd, int source)
{
char stopic[CMDSZ];
char svalue[INPUT_BUFFER_SIZE];
char *start;
char *token;
@ -1579,9 +1575,13 @@ void ExecuteCommand(char *cmnd, int source)
start = strrchr(token, '/'); // Skip possible cmnd/sonoff/ preamble
if (start) { token = start +1; }
}
uint16_t size = (token != NULL) ? strlen(token) : 0;
char stopic[size +2]; // / + \0
snprintf_P(stopic, sizeof(stopic), PSTR("/%s"), (token == NULL) ? "" : token);
token = strtok(NULL, "");
// snprintf_P(svalue, sizeof(svalue), (token == NULL) ? "" : token); // Fails with command FullTopic home/%prefix%/%topic% as it processes %p of %prefix%
size = (token != NULL) ? strlen(token) : 0;
char svalue[size +1];
strlcpy(svalue, (token == NULL) ? "" : token, sizeof(svalue)); // Fixed 5.8.0b
MqttDataHandler(stopic, (uint8_t*)svalue, strlen(svalue));
}
@ -1610,7 +1610,7 @@ void PublishStatus(uint8_t payload)
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%s%d" ), stemp2, (i > 0 ? "," : ""), Settings.switchmode[i]);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS "\":{\"" D_CMND_MODULE "\":%d,\"" D_CMND_FRIENDLYNAME "\":[%s],\"" D_CMND_TOPIC "\":\"%s\",\"" D_CMND_BUTTONTOPIC "\":\"%s\",\"" D_CMND_POWER "\":%d,\"" D_CMND_POWERONSTATE "\":%d,\"" D_CMND_LEDSTATE "\":%d,\"" D_CMND_SAVEDATA "\":%d,\"" D_JSON_SAVESTATE "\":%d,\"" D_CMND_SWITCHTOPIC "\":\"%s\",\"" D_CMND_SWITCHMODE "\":[%s],\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_SWITCHRETAIN "\":%d,\"" D_CMND_SENSORRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
(USER_MODULE == Settings.module)?0:Settings.module +1, stemp, mqtt_topic, Settings.button_topic, power, Settings.poweronstate, Settings.ledstate, Settings.save_data, Settings.flag.save_state, Settings.switch_topic, stemp2, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_switch_retain, Settings.flag.mqtt_sensor_retain, Settings.flag.mqtt_power_retain);
ModuleNr(), stemp, mqtt_topic, Settings.button_topic, power, Settings.poweronstate, Settings.ledstate, Settings.save_data, Settings.flag.save_state, Settings.switch_topic, stemp2, Settings.flag.mqtt_button_retain, Settings.flag.mqtt_switch_retain, Settings.flag.mqtt_sensor_retain, Settings.flag.mqtt_power_retain);
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS));
}

View File

@ -1956,8 +1956,6 @@ void HandleHttpCommand(void)
{
if (!HttpCheckPriviledgedAccess(false)) { return; }
char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
uint8_t valid = 1;
@ -1972,9 +1970,9 @@ void HandleHttpCommand(void)
String message = F("{\"" D_RSLT_WARNING "\":\"");
if (valid) {
uint8_t curridx = web_log_index;
WebGetArg("cmnd", svalue, sizeof(svalue));
if (strlen(svalue)) {
ExecuteWebCommand(svalue, SRC_WEBCOMMAND);
String svalue = WebServer->arg("cmnd");
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE);
if (web_log_index != curridx) {
uint8_t counter = curridx;
@ -2032,19 +2030,19 @@ void HandleAjaxConsoleRefresh(void)
{
if (!HttpCheckPriviledgedAccess()) { return; }
char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
bool cflg = true;
uint8_t counter = 0; // Initial start, should never be 0 again
WebGetArg("c1", svalue, sizeof(svalue));
if (strlen(svalue)) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue);
String svalue = WebServer->arg("c1");
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_COMMAND "%s"), svalue.c_str());
AddLog(LOG_LEVEL_INFO);
ExecuteWebCommand(svalue, SRC_WEBCONSOLE);
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE);
}
WebGetArg("c2", svalue, sizeof(svalue));
if (strlen(svalue)) { counter = atoi(svalue); }
char stmp[10];
WebGetArg("c2", stmp, sizeof(stmp));
if (strlen(stmp)) { counter = atoi(stmp); }
bool last_reset_web_log_flag = reset_web_log_flag;
// mqtt_data used as scratch space