Skip to content

Commit

Permalink
Add command Template 255
Browse files Browse the repository at this point in the history
Add command Template 255 to copy module configuration over to current active template and store as user template named Merged (arendst#5371)
  • Loading branch information
arendst authored and engrbm87 committed Mar 11, 2019
1 parent 700aafd commit b83e395
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions sonoff/_changelog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Changed webserver content handling from single String to small Chunks increasing RAM
* Changed logging message handling
* Fix additional characters in fallbacktopic, hostname and mqttclient on core 2.5.0 (#5359, #5417)
* Add command Template 255 to copy module configuration over to current active template and store as user template named Merged (#5371)
*
* 6.4.1.19 20190222
* Add command SetOption37 for RGBCW color mapping (#5326)
Expand Down
19 changes: 17 additions & 2 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ char* Format(char* output, const char* input, int size)
char tmp[size];
if (strchr(token, 'd')) {
snprintf_P(tmp, size, PSTR("%s%c0%dd"), output, '%', digits);
snprintf(output, size, tmp, ESP.getChipId() & 0x1fff); // %04d - short chip ID in dec, like in hostname
snprintf_P(output, size, tmp, ESP.getChipId() & 0x1fff); // %04d - short chip ID in dec, like in hostname
} else {
snprintf_P(tmp, size, PSTR("%s%c0%dX"), output, '%', digits);
snprintf_P(output, size, tmp, ESP.getChipId()); // %06X - full chip ID in hex
Expand Down Expand Up @@ -958,11 +958,26 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
ModuleDefault(payload -1); // Copy template module
if (USER_MODULE == Settings.module) { restart_flag = 2; }
}
else if (0 == payload) { // Copy current module with user configured GPIO
else if (0 == payload) { // Copy current template to user template
if (Settings.module != USER_MODULE) {
ModuleDefault(Settings.module);
}
}
else if (255 == payload) { // Copy current module with user configured GPIO
if (Settings.module != USER_MODULE) {
ModuleDefault(Settings.module);
}
snprintf_P(Settings.user_template.name, sizeof(Settings.user_template.name), PSTR("Merged"));
uint8_t j = 0;
for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
if (my_module.io[j] > GPIO_NONE) {
Settings.user_template.gp.io[i] = my_module.io[j];
}
j++;
}
}
}
else if (data_len > 9) { // Workaround exception if empty JSON like {} - Needs checks
if (JsonTemplate(dataBuf)) { // Free 336 bytes StaticJsonBuffer stack space by moving code to function
Expand Down

0 comments on commit b83e395

Please sign in to comment.