diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c
index 1a6eae297..46d84f4c2 100644
--- a/src/cmnds/cmd_newLEDDriver.c
+++ b/src/cmnds/cmd_newLEDDriver.c
@@ -380,6 +380,9 @@ float led_gamma_correction (int color, float iVal) { // apply LED gamma and RGB
return oVal;
} //
+void LED_SaveStateToFlashVarsNow() {
+ HAL_FlashVars_SaveLED(g_lightMode, g_brightness0to100, led_temperature_current, baseColors[0], baseColors[1], baseColors[2], g_lightEnableAll);
+}
void apply_smart_light() {
int i;
int firstChannelIndex;
@@ -515,7 +518,7 @@ void apply_smart_light() {
}
if(CFG_HasFlag(OBK_FLAG_LED_REMEMBERLASTSTATE)) {
- HAL_FlashVars_SaveLED(g_lightMode, g_brightness0to100, led_temperature_current,baseColors[0],baseColors[1],baseColors[2],g_lightEnableAll);
+ LED_SaveStateToFlashVarsNow();
}
#ifndef OBK_DISABLE_ALL_DRIVERS
DRV_DGR_OnLedFinalColorsChange(baseRGBCW);
diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h
index 878d7df0f..0a66904d1 100644
--- a/src/cmnds/cmd_public.h
+++ b/src/cmnds/cmd_public.h
@@ -218,6 +218,7 @@ bool LED_IsLedDriverChipRunning();
bool LED_IsLEDRunning();
void LED_SetEnableAll(int bEnable);
int LED_GetEnableAll();
+void LED_SaveStateToFlashVarsNow();
void LED_GetBaseColorString(char* s);
void LED_SetBaseColorByIndex(int i, float f, bool bApply);
int LED_GetMode();
diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c
index 2d59c68be..ee78d0f57 100644
--- a/src/httpserver/http_fns.c
+++ b/src/httpserver/http_fns.c
@@ -1210,6 +1210,9 @@ int http_fn_cfg_wifi(http_request_t* request) {
poststr_h2(request, "Use this to connect to your WiFi");
add_label_text_field(request, "SSID", "ssid", CFG_GetWiFiSSID(), "
");
@@ -1256,29 +1259,41 @@ int http_fn_cfg_name(http_request_t* request) {
int http_fn_cfg_wifi_set(http_request_t* request) {
char tmpA[128];
+ int bChanged;
+
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "HTTP_ProcessPacket: generating cfg_wifi_set \r\n");
+ bChanged = 0;
http_setup(request, httpMimeTypeHTML);
http_html_start(request, "Saving Wifi");
if (http_getArg(request->url, "open", tmpA, sizeof(tmpA))) {
- CFG_SetWiFiSSID("");
- CFG_SetWiFiPass("");
+ bChanged |= CFG_SetWiFiSSID("");
+ bChanged |= CFG_SetWiFiPass("");
poststr(request, "WiFi mode set: open access point.");
}
else {
if (http_getArg(request->url, "ssid", tmpA, sizeof(tmpA))) {
- CFG_SetWiFiSSID(tmpA);
+ bChanged |= CFG_SetWiFiSSID(tmpA);
}
if (http_getArg(request->url, "pass", tmpA, sizeof(tmpA))) {
- CFG_SetWiFiPass(tmpA);
+ bChanged |= CFG_SetWiFiPass(tmpA);
}
poststr(request, "WiFi mode set: connect to WLAN.");
}
+ if (http_getArg(request->url, "ssid2", tmpA, sizeof(tmpA))) {
+ bChanged |= CFG_SetWiFiSSID2(tmpA);
+ }
+ if (http_getArg(request->url, "pass2", tmpA, sizeof(tmpA))) {
+ bChanged |= CFG_SetWiFiPass2(tmpA);
+ }
CFG_Save_SetupTimer();
-
- poststr(request, "Please wait for module to reset...");
- RESET_ScheduleModuleReset(3);
-
+ if (bChanged==0) {
+ poststr(request, "No changes detected.");
+ }
+ else {
+ poststr(request, "Please wait for module to reset...");
+ RESET_ScheduleModuleReset(3);
+ }
poststr(request, "
Return to WiFi settings
");
poststr(request, htmlFooterReturnToCfgLink);
http_html_end(request);
diff --git a/src/httpserver/json_interface.c b/src/httpserver/json_interface.c
index 822eae7fd..7c78b60e4 100644
--- a/src/httpserver/json_interface.c
+++ b/src/httpserver/json_interface.c
@@ -688,7 +688,7 @@ static int http_tasmota_json_status_generic(void* request, jsonCb_t printer) {
printer(request, "\"LogHost\":\"\",");
printer(request, "\"LogPort\":514,");
printer(request, "\"SSId1\":\"%s\",", CFG_GetWiFiSSID());
- printer(request, "\"SSId2\":\"\",");
+ printer(request, "\"SSId2\":\"%s\",", CFG_GetWiFiSSID2());
printer(request, "\"TelePeriod\":300,");
printer(request, "\"Resolution\":\"558180C0\",");
printer(request, "\"SetOption\":[");
diff --git a/src/new_cfg.c b/src/new_cfg.c
index 8c39ede17..45bec02fa 100644
--- a/src/new_cfg.c
+++ b/src/new_cfg.c
@@ -23,18 +23,32 @@ int g_cfg_pendingChanges = 0;
#define CFG_IDENT_1 'F'
#define CFG_IDENT_2 'G'
-#define MAIN_CFG_VERSION 3
+#define MAIN_CFG_VERSION_V3 3
+// version 4 - bumped size by 1024,
+// added alternate ssid fields
+#define MAIN_CFG_VERSION 4
static byte CFG_CalcChecksum(mainConfig_t *inf) {
int header_size;
int remaining_size;
byte crc;
+ int configSize;
header_size = ((byte*)&inf->version)-((byte*)inf);
- remaining_size = sizeof(mainConfig_t) - header_size;
+
+ if (inf->version == MAIN_CFG_VERSION_V3) {
+ configSize = MAGIC_CONFIG_SIZE_V3;
+ // quick fix for converting
+ inf->wifi_pass2[0] = 0;
+ inf->wifi_ssid2[0] = 0;
+ }
+ else {
+ configSize = sizeof(mainConfig_t);
+ }
+ remaining_size = configSize - header_size;
ADDLOG_DEBUG(LOG_FEATURE_CFG, "CFG_CalcChecksum: header size %i, total size %i, rem size %i\n",
- header_size, sizeof(mainConfig_t), remaining_size);
+ header_size, configSize, remaining_size);
// This is more flexible method and won't be affected by field offsets
crc = Tiny_CRC8((const char*)&inf->version,remaining_size);
@@ -288,14 +302,22 @@ const char *CFG_GetWiFiPass(){
wifi_pass[sizeof(g_cfg.wifi_pass)] = 0;
return wifi_pass;
}
-void CFG_SetWiFiSSID(const char *s) {
+const char *CFG_GetWiFiSSID2() {
+ return g_cfg.wifi_ssid2;
+}
+const char *CFG_GetWiFiPass2() {
+ return g_cfg.wifi_pass2;
+}
+int CFG_SetWiFiSSID(const char *s) {
// this will return non-zero if there were any changes
if(strcpy_safe_checkForChanges(g_cfg.wifi_ssid, s,sizeof(g_cfg.wifi_ssid))) {
// mark as dirty (value has changed)
g_cfg_pendingChanges++;
+ return 1;
}
+ return 0;
}
-void CFG_SetWiFiPass(const char *s) {
+int CFG_SetWiFiPass(const char *s) {
uint32_t len;
len = strlen(s) + 1;
@@ -305,7 +327,26 @@ void CFG_SetWiFiPass(const char *s) {
memcpy(g_cfg.wifi_pass, s, len);
// mark as dirty (value has changed)
g_cfg_pendingChanges++;
+ return 1;
}
+ return 0;
+}
+int CFG_SetWiFiSSID2(const char *s) {
+ // this will return non-zero if there were any changes
+ if (strcpy_safe_checkForChanges(g_cfg.wifi_ssid2, s, sizeof(g_cfg.wifi_ssid2))) {
+ // mark as dirty (value has changed)
+ g_cfg_pendingChanges++;
+ return 1;
+ }
+ return 0;
+}
+int CFG_SetWiFiPass2(const char *s) {
+ if (strcpy_safe_checkForChanges(g_cfg.wifi_pass2, s, sizeof(g_cfg.wifi_pass2))) {
+ // mark as dirty (value has changed)
+ g_cfg_pendingChanges++;
+ return 1;
+ }
+ return 0;
}
const char *CFG_GetMQTTHost() {
return g_cfg.mqtt_host;
@@ -450,6 +491,9 @@ void CFG_SetFlag(int flag, bool bValue) {
if(bValue && flag == OBK_FLAG_CMD_ENABLETCPRAWPUTTYSERVER) {
CMD_StartTCPCommandLine();
}
+ if (bValue && flag == OBK_FLAG_LED_REMEMBERLASTSTATE) {
+ LED_SaveStateToFlashVarsNow();
+ }
}
}
void CFG_SetLoggerFlag(int flag, bool bValue) {
@@ -627,9 +671,9 @@ void CFG_InitAndLoad() {
if (g_cfg.version<3) {
addLogAdv(LOG_WARN, LOG_FEATURE_CFG, "CFG_InitAndLoad: Old config version found, updating to v3.");
strcpy_safe(g_cfg.mqtt_clientId, g_cfg.shortDeviceName, sizeof(g_cfg.mqtt_clientId));
- g_cfg.version = 3;
g_cfg_pendingChanges++;
}
+ g_cfg.version = MAIN_CFG_VERSION;
if(g_cfg.buttonHoldRepeat == 0) {
// default value is 5, which means 500ms
diff --git a/src/new_cfg.h b/src/new_cfg.h
index 0513c5e95..8815ca04c 100644
--- a/src/new_cfg.h
+++ b/src/new_cfg.h
@@ -20,8 +20,10 @@ void CFG_ClearIO();
void CFG_SetDefaultConfig();
const char *CFG_GetWiFiSSID();
const char *CFG_GetWiFiPass();
-void CFG_SetWiFiSSID(const char *s);
-void CFG_SetWiFiPass(const char *s);
+const char *CFG_GetWiFiSSID2();
+const char *CFG_GetWiFiPass2();
+int CFG_SetWiFiSSID(const char *s);
+int CFG_SetWiFiPass(const char *s);
const char *CFG_GetMQTTHost();
const char *CFG_GetMQTTClientId();
const char *CFG_GetMQTTGroupTopic();
diff --git a/src/new_pins.h b/src/new_pins.h
index 5924b7826..99c0ad09e 100644
--- a/src/new_pins.h
+++ b/src/new_pins.h
@@ -1065,9 +1065,20 @@ typedef struct mainConfig_s {
int ping_seconds;
// 0x000005A0
char ping_host[64];
- char initCommandLine[512];
-} mainConfig_t; // size 0x000007E0 (2016 decimal)
-#define MAGIC_CONFIG_SIZE 2016
+ // ofs 0x000005E0 (dec 1504)
+ //char initCommandLine[512];
+ char initCommandLine[1568];
+ // offset 0x00000C00 (3072 decimal)
+ char wifi_ssid2[64];
+ // offset 0x00000C40 (3136 decimal)
+ char wifi_pass2[68];
+ // offset 0x00000C84 (3204 decimal)
+ char unused[380];
+} mainConfig_t;
+
+// one sector is 4096 so it we still have some expand possibility
+#define MAGIC_CONFIG_SIZE_V3 2016
+#define MAGIC_CONFIG_SIZE_V4 3584
extern mainConfig_t g_cfg;
diff --git a/src/win_main.c b/src/win_main.c
index 234def718..ba7af09bb 100644
--- a/src/win_main.c
+++ b/src/win_main.c
@@ -291,7 +291,7 @@ int __cdecl main(int argc, char **argv)
system("pause");
}
//printf("Offset MQTT Group: %i", OFFSETOF(mainConfig_t, mqtt_group));
- if (sizeof(mainConfig_t) != MAGIC_CONFIG_SIZE) {
+ if (sizeof(mainConfig_t) != MAGIC_CONFIG_SIZE_V4) {
printf("sizeof(mainConfig_t) != MAGIC_CONFIG_SIZE!: %i\n", sizeof(mainConfig_t));
system("pause");
}
@@ -319,6 +319,22 @@ int __cdecl main(int argc, char **argv)
printf("OFFSETOF(mainConfig_t, version) != 0x00000004: %i\n", OFFSETOF(mainConfig_t, version));
system("pause");
}
+ if (OFFSETOF(mainConfig_t, initCommandLine) != 0x000005E0) {
+ printf("OFFSETOF(mainConfig_t, initCommandLine) != 0x000005E0: %i\n", OFFSETOF(mainConfig_t, initCommandLine));
+ system("pause");
+ }
+ if (OFFSETOF(mainConfig_t, wifi_ssid2) != 0x00000C00) {
+ printf("OFFSETOF(mainConfig_t, wifi_ssid2) != 0x00000C00: %i\n", OFFSETOF(mainConfig_t, wifi_ssid2));
+ system("pause");
+ }
+ if (OFFSETOF(mainConfig_t, wifi_pass2) != 0x00000C40) {
+ printf("OFFSETOF(mainConfig_t, wifi_pass2) != 0x00000C40: %i\n", OFFSETOF(mainConfig_t, wifi_pass2));
+ system("pause");
+ }
+ if (OFFSETOF(mainConfig_t, unused) != 0x00000C84) {
+ printf("OFFSETOF(mainConfig_t, unused) != 0x00000C84: %i\n", OFFSETOF(mainConfig_t, unused));
+ system("pause");
+ }
// Test expansion
//CMD_UART_Send_Hex(0,0,"FFAA$CH1$BB",0);