diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index d87aba99b..741743618 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -978,8 +978,11 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) if (strstr(dataBuf, "{") == nullptr) { // If no JSON it must be parameter if ((payload > 0) && (payload <= MAXMODULE)) { - ModuleDefault(payload -1); // Copy template module - if (USER_MODULE == Settings.module) { restart_flag = 2; } + payload--; + if (ValidModule(payload)) { + ModuleDefault(payload); // Copy template module + if (USER_MODULE == Settings.module) { restart_flag = 2; } + } } else if (0 == payload) { // Copy current template to user template if (Settings.module != USER_MODULE) { diff --git a/sonoff/support.ino b/sonoff/support.ino index d9fe3ed7a..51c895905 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1023,8 +1023,8 @@ bool JsonTemplate(const char* dataBuf) } if (obj[D_JSON_BASE].success()) { uint8_t base = obj[D_JSON_BASE]; - if ((0 == base) || (base >= MAXMODULE)) { base = 17; } else { base--; } - Settings.user_template_base = base; // Default WEMOS + if ((0 == base) || !ValidModule(base -1)) { base = 18; } + Settings.user_template_base = base -1; // Default WEMOS } return true; }