mirror of https://github.com/arendst/Tasmota.git
Refactor GUI save settings (prt2)
This commit is contained in:
parent
bacc07b2de
commit
1a2addfc16
|
@ -306,6 +306,7 @@
|
||||||
#define D_WCFG_7_WIFIMANAGER_RESET_ONLY "ManagerRst"
|
#define D_WCFG_7_WIFIMANAGER_RESET_ONLY "ManagerRst"
|
||||||
#define D_CMND_DEVICENAME "DeviceName"
|
#define D_CMND_DEVICENAME "DeviceName"
|
||||||
#define D_CMND_FRIENDLYNAME "FriendlyName"
|
#define D_CMND_FRIENDLYNAME "FriendlyName"
|
||||||
|
#define D_CMND_FN "FN"
|
||||||
#define D_CMND_SWITCHMODE "SwitchMode"
|
#define D_CMND_SWITCHMODE "SwitchMode"
|
||||||
#define D_CMND_INTERLOCK "Interlock"
|
#define D_CMND_INTERLOCK "Interlock"
|
||||||
#define D_CMND_TELEPERIOD "TelePeriod"
|
#define D_CMND_TELEPERIOD "TelePeriod"
|
||||||
|
|
|
@ -26,7 +26,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix
|
||||||
D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|"
|
D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|"
|
||||||
D_CMND_SERIALBUFFER "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALCONFIG "|" D_CMND_SERIALDELIMITER "|"
|
D_CMND_SERIALBUFFER "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" D_CMND_SERIALCONFIG "|" D_CMND_SERIALDELIMITER "|"
|
||||||
D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" D_CMND_WIFICONFIG "|"
|
D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" D_CMND_WIFICONFIG "|"
|
||||||
D_CMND_DEVICENAME "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|"
|
D_CMND_DEVICENAME "|" D_CMND_FN "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|"
|
||||||
D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_LEDPWM_ON "|" D_CMND_LEDPWM_OFF "|" D_CMND_LEDPWM_MODE "|"
|
D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_LEDPWM_ON "|" D_CMND_LEDPWM_OFF "|" D_CMND_LEDPWM_MODE "|"
|
||||||
D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" D_CMND_HUMOFFSET "|" D_CMND_SPEEDUNIT "|" D_CMND_GLOBAL_TEMP "|" D_CMND_GLOBAL_HUM"|" D_CMND_SWITCHTEXT "|"
|
D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" D_CMND_HUMOFFSET "|" D_CMND_SPEEDUNIT "|" D_CMND_GLOBAL_TEMP "|" D_CMND_GLOBAL_HUM"|" D_CMND_SWITCHTEXT "|"
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
|
@ -54,7 +54,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = {
|
||||||
&CmndButtonDebounce, &CmndSwitchDebounce, &CmndSyslog, &CmndLoghost, &CmndLogport,
|
&CmndButtonDebounce, &CmndSwitchDebounce, &CmndSyslog, &CmndLoghost, &CmndLogport,
|
||||||
&CmndSerialBuffer, &CmndSerialSend, &CmndBaudrate, &CmndSerialConfig, &CmndSerialDelimiter,
|
&CmndSerialBuffer, &CmndSerialSend, &CmndBaudrate, &CmndSerialConfig, &CmndSerialDelimiter,
|
||||||
&CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig,
|
&CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig,
|
||||||
&CmndDevicename, &CmndFriendlyname, &CmndSwitchMode, &CmndInterlock, &CmndTeleperiod, &CmndReset, &CmndTime, &CmndTimezone, &CmndTimeStd,
|
&CmndDevicename, &CmndFriendlyname, &CmndFriendlyname, &CmndSwitchMode, &CmndInterlock, &CmndTeleperiod, &CmndReset, &CmndTime, &CmndTimezone, &CmndTimeStd,
|
||||||
&CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, &CmndLedPwmOn, &CmndLedPwmOff, &CmndLedPwmMode,
|
&CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, &CmndLedPwmOn, &CmndLedPwmOff, &CmndLedPwmMode,
|
||||||
&CmndWifiPower, &CmndTempOffset, &CmndHumOffset, &CmndSpeedUnit, &CmndGlobalTemp, &CmndGlobalHum, &CmndSwitchText,
|
&CmndWifiPower, &CmndTempOffset, &CmndHumOffset, &CmndSpeedUnit, &CmndGlobalTemp, &CmndGlobalHum, &CmndSwitchText,
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
|
@ -237,7 +237,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
|
||||||
type[i] = '\0';
|
type[i] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("CMD: " D_GROUP " %d, " D_INDEX " %d, " D_COMMAND " \"%s\", " D_DATA " \"%s\""), grpflg, index, type, dataBuf);
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CMD: " D_GROUP " %d, " D_INDEX " %d, " D_COMMAND " \"%s\", " D_DATA " \"%s\""), grpflg, index, type, dataBuf);
|
||||||
|
|
||||||
if (type != nullptr) {
|
if (type != nullptr) {
|
||||||
Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}"));
|
Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}"));
|
||||||
|
@ -1657,14 +1657,23 @@ void CmndSsid(void)
|
||||||
|
|
||||||
void CmndPassword(void)
|
void CmndPassword(void)
|
||||||
{
|
{
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 2)) {
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 4)) {
|
||||||
|
bool show_asterisk = (XdrvMailbox.index > 2);
|
||||||
|
if (show_asterisk) {
|
||||||
|
XdrvMailbox.index -= 2;
|
||||||
|
}
|
||||||
if ((XdrvMailbox.data_len > 4) || (SC_CLEAR == Shortcut()) || (SC_DEFAULT == Shortcut())) {
|
if ((XdrvMailbox.data_len > 4) || (SC_CLEAR == Shortcut()) || (SC_DEFAULT == Shortcut())) {
|
||||||
SettingsUpdateText(SET_STAPWD1 + XdrvMailbox.index -1,
|
SettingsUpdateText(SET_STAPWD1 + XdrvMailbox.index -1,
|
||||||
(SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? STA_PASS1 : STA_PASS2 : XdrvMailbox.data);
|
(SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? STA_PASS1 : STA_PASS2 : XdrvMailbox.data);
|
||||||
Settings.sta_active = XdrvMailbox.index -1;
|
Settings.sta_active = XdrvMailbox.index -1;
|
||||||
TasmotaGlobal.restart_flag = 2;
|
TasmotaGlobal.restart_flag = 2;
|
||||||
ResponseCmndIdxChar(SettingsText(SET_STAPWD1 + XdrvMailbox.index -1));
|
if (!show_asterisk) {
|
||||||
|
ResponseCmndIdxChar(SettingsText(SET_STAPWD1 + XdrvMailbox.index -1));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
show_asterisk = true;
|
||||||
|
}
|
||||||
|
if (show_asterisk) {
|
||||||
Response_P(S_JSON_COMMAND_INDEX_ASTERISK, XdrvMailbox.command, XdrvMailbox.index);
|
Response_P(S_JSON_COMMAND_INDEX_ASTERISK, XdrvMailbox.command, XdrvMailbox.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1708,6 +1717,7 @@ void CmndDevicename(void)
|
||||||
|
|
||||||
void CmndFriendlyname(void)
|
void CmndFriendlyname(void)
|
||||||
{
|
{
|
||||||
|
snprintf_P(XdrvMailbox.command, CMDSZ, PSTR(D_CMND_FRIENDLYNAME)); // Rename result shortcut command FN to FriendlyName
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_FRIENDLYNAMES)) {
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_FRIENDLYNAMES)) {
|
||||||
if (!XdrvMailbox.usridx && !XdrvMailbox.data_len) {
|
if (!XdrvMailbox.usridx && !XdrvMailbox.data_len) {
|
||||||
ResponseCmndAll(SET_FRIENDLYNAME1, MAX_FRIENDLYNAMES);
|
ResponseCmndAll(SET_FRIENDLYNAME1, MAX_FRIENDLYNAMES);
|
||||||
|
|
|
@ -1403,8 +1403,7 @@ void WSContentSendAdcNiceList(uint32_t option) {
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void HandleTemplateConfiguration(void)
|
void HandleTemplateConfiguration(void) {
|
||||||
{
|
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
if (Webserver->hasArg(F("save"))) {
|
if (Webserver->hasArg(F("save"))) {
|
||||||
|
@ -1504,12 +1503,11 @@ uint16_t WebGetGpioArg(uint32_t i) {
|
||||||
return gpio;
|
return gpio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemplateSaveSettings(void)
|
void TemplateSaveSettings(void) {
|
||||||
{
|
char tmp[TOPSZ]; // WebGetArg NAME and GPIO/BASE/FLAG byte value
|
||||||
char tmp[TOPSZ]; // WebGetArg NAME and GPIO/BASE/FLAG byte value
|
char svalue[300]; // Template command string
|
||||||
char svalue[300]; // Template command string
|
|
||||||
|
|
||||||
WebGetArg(PSTR("s1"), tmp, sizeof(tmp)); // NAME
|
WebGetArg(PSTR("s1"), tmp, sizeof(tmp)); // NAME
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
|
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
|
||||||
|
|
||||||
uint32_t j = 0;
|
uint32_t j = 0;
|
||||||
|
@ -1521,13 +1519,13 @@ void TemplateSaveSettings(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flag = 0;
|
uint32_t flag = 0;
|
||||||
char webindex[5]; // WebGetArg name
|
char webindex[5]; // WebGetArg name
|
||||||
for (uint32_t i = 0; i < GPIO_FLAG_USED; i++) {
|
for (uint32_t i = 0; i < GPIO_FLAG_USED; i++) {
|
||||||
snprintf_P(webindex, sizeof(webindex), PSTR("c%d"), i);
|
snprintf_P(webindex, sizeof(webindex), PSTR("c%d"), i);
|
||||||
uint32_t state = Webserver->hasArg(webindex) << i; // FLAG
|
uint32_t state = Webserver->hasArg(webindex) << i; // FLAG
|
||||||
flag += state;
|
flag += state;
|
||||||
}
|
}
|
||||||
WebGetArg(PSTR("g99"), tmp, sizeof(tmp)); // BASE
|
WebGetArg(PSTR("g99"), tmp, sizeof(tmp)); // BASE
|
||||||
uint32_t base = atoi(tmp) +1;
|
uint32_t base = atoi(tmp) +1;
|
||||||
|
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), svalue, flag, base);
|
snprintf_P(svalue, sizeof(svalue), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), svalue, flag, base);
|
||||||
|
@ -1536,8 +1534,7 @@ void TemplateSaveSettings(void)
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void HandleModuleConfiguration(void)
|
void HandleModuleConfiguration(void) {
|
||||||
{
|
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
if (Webserver->hasArg(F("save"))) {
|
if (Webserver->hasArg(F("save"))) {
|
||||||
|
@ -1603,30 +1600,27 @@ void HandleModuleConfiguration(void)
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleSaveSettings(void)
|
void ModuleSaveSettings(void) {
|
||||||
{
|
|
||||||
char tmp[8]; // WebGetArg numbers only
|
char tmp[8]; // WebGetArg numbers only
|
||||||
|
WebGetArg(PSTR("g99"), tmp, sizeof(tmp)); // Module
|
||||||
WebGetArg(PSTR("g99"), tmp, sizeof(tmp));
|
|
||||||
uint32_t new_module = (!strlen(tmp)) ? MODULE : atoi(tmp);
|
uint32_t new_module = (!strlen(tmp)) ? MODULE : atoi(tmp);
|
||||||
Settings.last_module = Settings.module;
|
Settings.last_module = Settings.module;
|
||||||
Settings.module = new_module;
|
Settings.module = new_module;
|
||||||
SetModuleType();
|
SetModuleType();
|
||||||
myio template_gp;
|
myio template_gp;
|
||||||
TemplateGpios(&template_gp);
|
TemplateGpios(&template_gp);
|
||||||
String gpios = "";
|
|
||||||
for (uint32_t i = 0; i < nitems(template_gp.io); i++) {
|
for (uint32_t i = 0; i < nitems(template_gp.io); i++) {
|
||||||
if (Settings.last_module != new_module) {
|
if (Settings.last_module != new_module) {
|
||||||
Settings.my_gp.io[i] = GPIO_NONE;
|
Settings.my_gp.io[i] = GPIO_NONE;
|
||||||
} else {
|
} else {
|
||||||
if (ValidGPIO(i, template_gp.io[i])) {
|
if (ValidGPIO(i, template_gp.io[i])) {
|
||||||
Settings.my_gp.io[i] = WebGetGpioArg(i);
|
Settings.my_gp.io[i] = WebGetGpioArg(i); // Gpio
|
||||||
gpios += F(", IO"); gpios += String(i); gpios += F(" "); gpios += String(Settings.my_gp.io[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
char command[32];
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MODULE "%s " D_CMND_MODULE "%s"), ModuleName().c_str(), gpios.c_str());
|
snprintf_P(command, sizeof(command), PSTR(D_CMND_BACKLOG "0 " D_CMND_MODULE ";" D_CMND_GPIO));
|
||||||
|
ExecuteWebCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
@ -1653,8 +1647,7 @@ String HtmlEscape(const String unescaped) {
|
||||||
// Indexed by enum wl_enc_type in file wl_definitions.h starting from -1
|
// Indexed by enum wl_enc_type in file wl_definitions.h starting from -1
|
||||||
const char kEncryptionType[] PROGMEM = "|||" D_WPA_PSK "||" D_WPA2_PSK "|" D_WEP "||" D_NONE "|" D_AUTO;
|
const char kEncryptionType[] PROGMEM = "|||" D_WPA_PSK "||" D_WPA2_PSK "|" D_WEP "||" D_NONE "|" D_AUTO;
|
||||||
|
|
||||||
void HandleWifiConfiguration(void)
|
void HandleWifiConfiguration(void) {
|
||||||
{
|
|
||||||
if (!HttpCheckPriviledgedAccess(!WifiIsInManagerMode())) { return; }
|
if (!HttpCheckPriviledgedAccess(!WifiIsInManagerMode())) { return; }
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_WIFI));
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_WIFI));
|
||||||
|
@ -1806,33 +1799,33 @@ void HandleWifiConfiguration(void)
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiSaveSettings(void)
|
void WifiSaveSettings(void) {
|
||||||
{
|
char tmp1[CMDSZ];
|
||||||
char tmp[TOPSZ]; // Max length is currently 150
|
WebGetArg(PSTR("h"), tmp1, sizeof(tmp1)); // Host name
|
||||||
|
char tmp2[CMDSZ];
|
||||||
WebGetArg(PSTR("h"), tmp, sizeof(tmp));
|
WebGetArg(PSTR("c"), tmp2, sizeof(tmp2)); // Cors domain
|
||||||
SettingsUpdateText(SET_HOSTNAME, (!strlen(tmp)) ? WIFI_HOSTNAME : tmp);
|
char tmp3[CMDSZ];
|
||||||
if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) {
|
WebGetArg(PSTR("s1"), tmp3, sizeof(tmp3)); // Ssid1
|
||||||
SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME);
|
char tmp4[CMDSZ];
|
||||||
}
|
WebGetArg(PSTR("s2"), tmp4, sizeof(tmp4)); // Ssid2
|
||||||
WebGetArg(PSTR("c"), tmp, sizeof(tmp));
|
char tmp5[CMDSZ];
|
||||||
SettingsUpdateText(SET_CORS, (!strlen(tmp)) ? CORS_DOMAIN : tmp);
|
WebGetArg(PSTR("p1"), tmp5, sizeof(tmp5)); // Password1
|
||||||
WebGetArg(PSTR("s1"), tmp, sizeof(tmp));
|
char tmp6[CMDSZ];
|
||||||
SettingsUpdateText(SET_STASSID1, (!strlen(tmp)) ? STA_SSID1 : tmp);
|
WebGetArg(PSTR("p2"), tmp6, sizeof(tmp6)); // Password2
|
||||||
WebGetArg(PSTR("s2"), tmp, sizeof(tmp));
|
char command[300];
|
||||||
SettingsUpdateText(SET_STASSID2, (!strlen(tmp)) ? STA_SSID2 : tmp);
|
snprintf_P(command, sizeof(command), PSTR(D_CMND_BACKLOG "0 " D_CMND_HOSTNAME " %s;" D_CMND_CORS " %s;" D_CMND_SSID "1 %s;" D_CMND_SSID "2 %s;" D_CMND_PASSWORD "3 %s;" D_CMND_PASSWORD "4 %s"),
|
||||||
WebGetArg(PSTR("p1"), tmp, sizeof(tmp));
|
(!strlen(tmp1)) ? "1" : tmp1,
|
||||||
SettingsUpdateText(SET_STAPWD1, (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? SettingsText(SET_STAPWD1) : tmp);
|
(!strlen(tmp2)) ? "1" : tmp2,
|
||||||
WebGetArg(PSTR("p2"), tmp, sizeof(tmp));
|
(!strlen(tmp3)) ? "1" : tmp3,
|
||||||
SettingsUpdateText(SET_STAPWD2, (!strlen(tmp)) ? "" : (strlen(tmp) < 5) ? SettingsText(SET_STAPWD2) : tmp);
|
(!strlen(tmp4)) ? "1" : tmp4,
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_WIFI D_CMND_HOSTNAME " %s, " D_CMND_SSID "1 %s, " D_CMND_SSID "2 %s, " D_CMND_CORS " %s"),
|
(!strlen(tmp5)) ? "\"" : (strlen(tmp5) < 5) ? "" : tmp5,
|
||||||
SettingsText(SET_HOSTNAME), SettingsText(SET_STASSID1), SettingsText(SET_STASSID2), SettingsText(SET_CORS));
|
(!strlen(tmp6)) ? "\"" : (strlen(tmp6) < 5) ? "" : tmp6);
|
||||||
|
ExecuteWebCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void HandleLoggingConfiguration(void)
|
void HandleLoggingConfiguration(void) {
|
||||||
{
|
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_LOGGING));
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_LOGGING));
|
||||||
|
@ -1869,22 +1862,21 @@ void HandleLoggingConfiguration(void)
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggingSaveSettings(void)
|
void LoggingSaveSettings(void) {
|
||||||
{
|
|
||||||
char tmp1[CMDSZ];
|
char tmp1[CMDSZ];
|
||||||
WebGetArg(PSTR("l0"), tmp1, sizeof(tmp1));
|
WebGetArg(PSTR("l0"), tmp1, sizeof(tmp1)); // Serial log level
|
||||||
char tmp2[CMDSZ];
|
char tmp2[CMDSZ];
|
||||||
WebGetArg(PSTR("l1"), tmp2, sizeof(tmp2));
|
WebGetArg(PSTR("l1"), tmp2, sizeof(tmp2)); // Web log level
|
||||||
char tmp3[CMDSZ];
|
char tmp3[CMDSZ];
|
||||||
WebGetArg(PSTR("l2"), tmp3, sizeof(tmp3));
|
WebGetArg(PSTR("l2"), tmp3, sizeof(tmp3)); // Mqtt log level
|
||||||
char tmp4[CMDSZ];
|
char tmp4[CMDSZ];
|
||||||
WebGetArg(PSTR("l3"), tmp4, sizeof(tmp4));
|
WebGetArg(PSTR("l3"), tmp4, sizeof(tmp4)); // Syslog level
|
||||||
char tmp5[CMDSZ];
|
char tmp5[CMDSZ];
|
||||||
WebGetArg(PSTR("lh"), tmp5, sizeof(tmp5));
|
WebGetArg(PSTR("lh"), tmp5, sizeof(tmp5)); // Syslog host name
|
||||||
char tmp6[CMDSZ];
|
char tmp6[CMDSZ];
|
||||||
WebGetArg(PSTR("lp"), tmp6, sizeof(tmp6));
|
WebGetArg(PSTR("lp"), tmp6, sizeof(tmp6)); // Syslog port number
|
||||||
char tmp7[CMDSZ];
|
char tmp7[CMDSZ];
|
||||||
WebGetArg(PSTR("lt"), tmp7, sizeof(tmp7));
|
WebGetArg(PSTR("lt"), tmp7, sizeof(tmp7)); // Teleperiod
|
||||||
char command[200];
|
char command[200];
|
||||||
snprintf_P(command, sizeof(command),PSTR(D_CMND_BACKLOG "0 " D_CMND_SERIALLOG " %s;" D_CMND_WEBLOG " %s;" D_CMND_MQTTLOG " %s;" D_CMND_SYSLOG " %s;" D_CMND_LOGHOST " %s;" D_CMND_LOGPORT " %s;" D_CMND_TELEPERIOD " %s"),
|
snprintf_P(command, sizeof(command),PSTR(D_CMND_BACKLOG "0 " D_CMND_SERIALLOG " %s;" D_CMND_WEBLOG " %s;" D_CMND_MQTTLOG " %s;" D_CMND_SYSLOG " %s;" D_CMND_LOGHOST " %s;" D_CMND_LOGPORT " %s;" D_CMND_TELEPERIOD " %s"),
|
||||||
(!strlen(tmp1)) ? STR(SERIAL_LOG_LEVEL) : tmp1,
|
(!strlen(tmp1)) ? STR(SERIAL_LOG_LEVEL) : tmp1,
|
||||||
|
@ -1899,8 +1891,7 @@ void LoggingSaveSettings(void)
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void HandleOtherConfiguration(void)
|
void HandleOtherConfiguration(void) {
|
||||||
{
|
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_OTHER));
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_OTHER));
|
||||||
|
@ -1962,42 +1953,36 @@ void HandleOtherConfiguration(void)
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtherSaveSettings(void)
|
void OtherSaveSettings(void) {
|
||||||
{
|
char tmp1[300]; // Needs to hold complete ESP32 template of minimal 230 chars
|
||||||
char tmp[300]; // Needs to hold complete ESP32 template of minimal 230 chars
|
WebGetArg(PSTR("dn"), tmp1, sizeof(tmp1)); // Device name
|
||||||
char webindex[5];
|
char tmp2[100];
|
||||||
char friendlyname[TOPSZ];
|
WebGetArg(PSTR("wp"), tmp2, sizeof(tmp2)); // Web password
|
||||||
char message[MAX_LOGSZ];
|
char command[600];
|
||||||
|
snprintf_P(command, sizeof(command),PSTR(D_CMND_BACKLOG "0 " D_CMND_WEBPASSWORD "2 %s;" D_CMND_SO "3 %d;" D_CMND_DEVICENAME " %s"),
|
||||||
|
(!strlen(tmp2)) ? "\"" : (strlen(tmp2) < 5) ? "" : tmp2,
|
||||||
|
Webserver->hasArg(F("b1")), // SetOption3 - Enable MQTT
|
||||||
|
(!strlen(tmp1)) ? "\"" : tmp1);
|
||||||
|
|
||||||
|
char webindex[5];
|
||||||
|
for (uint32_t i = 0; i < MAX_FRIENDLYNAMES; i++) {
|
||||||
|
snprintf_P(webindex, sizeof(webindex), PSTR("a%d"), i);
|
||||||
|
WebGetArg(webindex, tmp1, sizeof(tmp1)); // Friendly name 1 to 8
|
||||||
|
snprintf_P(command, sizeof(command), PSTR("%s;" D_CMND_FN"%d %s"), command, i +1, (!strlen(tmp1)) ? "\"" : tmp1);
|
||||||
|
}
|
||||||
|
|
||||||
WebGetArg(PSTR("dn"), tmp, sizeof(tmp));
|
|
||||||
SettingsUpdateText(SET_DEVICENAME, (!strlen(tmp)) ? "" : (!strcmp(tmp,"1")) ? SettingsText(SET_FRIENDLYNAME1) : tmp);
|
|
||||||
WebGetArg(PSTR("wp"), tmp, sizeof(tmp));
|
|
||||||
SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp);
|
|
||||||
Settings.flag.mqtt_enabled = Webserver->hasArg(F("b1")); // SetOption3 - Enable MQTT
|
|
||||||
#ifdef USE_EMULATION
|
#ifdef USE_EMULATION
|
||||||
UdpDisconnect();
|
|
||||||
#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE)
|
#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE)
|
||||||
WebGetArg(PSTR("b2"), tmp, sizeof(tmp));
|
WebGetArg(PSTR("b2"), tmp1, sizeof(tmp1)); // Emulation
|
||||||
Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp);
|
snprintf_P(command, sizeof(command), PSTR("%s;" D_CMND_EMULATION " %s"), command, (!strlen(tmp1)) ? "0" : tmp1);
|
||||||
#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE
|
#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE
|
||||||
#endif // USE_EMULATION
|
#endif // USE_EMULATION
|
||||||
|
|
||||||
snprintf_P(message, sizeof(message), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_DEVICENAME " %s, " D_CMND_FRIENDLYNAME),
|
WebGetArg(PSTR("t1"), tmp1, sizeof(tmp1)); // Template
|
||||||
GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation, SettingsText(SET_DEVICENAME));
|
if (strlen(tmp1)) { // {"NAME":"12345678901234","GPIO":[255,255,255,255,255,255,255,255,255,255,255,255,255],"FLAG":255,"BASE":255}
|
||||||
for (uint32_t i = 0; i < MAX_FRIENDLYNAMES; i++) {
|
snprintf_P(command, sizeof(command), PSTR("%s;" D_CMND_TEMPLATE " %s%s"), command, tmp1, (Webserver->hasArg(F("t2"))) ? PSTR("; " D_CMND_MODULE " 0") : "");
|
||||||
snprintf_P(webindex, sizeof(webindex), PSTR("a%d"), i);
|
|
||||||
WebGetArg(webindex, tmp, sizeof(tmp));
|
|
||||||
snprintf_P(friendlyname, sizeof(friendlyname), PSTR(FRIENDLY_NAME"%d"), i +1);
|
|
||||||
SettingsUpdateText(SET_FRIENDLYNAME1 +i, (!strlen(tmp)) ? (i) ? friendlyname : PSTR(FRIENDLY_NAME) : tmp);
|
|
||||||
snprintf_P(message, sizeof(message), PSTR("%s%s %s"), message, (i) ? "," : "", SettingsText(SET_FRIENDLYNAME1 +i));
|
|
||||||
}
|
|
||||||
AddLogData(LOG_LEVEL_INFO, message);
|
|
||||||
|
|
||||||
WebGetArg(PSTR("t1"), tmp, sizeof(tmp));
|
|
||||||
if (strlen(tmp)) { // {"NAME":"12345678901234","GPIO":[255,255,255,255,255,255,255,255,255,255,255,255,255],"FLAG":255,"BASE":255}
|
|
||||||
snprintf_P(message, sizeof(message), PSTR(D_CMND_BACKLOG " " D_CMND_TEMPLATE " %s%s"), tmp, (Webserver->hasArg(F("t2"))) ? PSTR("; " D_CMND_MODULE " 0") : "");
|
|
||||||
ExecuteWebCommand(message);
|
|
||||||
}
|
}
|
||||||
|
ExecuteWebCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
@ -3018,10 +3003,16 @@ void CmndWebServer(void)
|
||||||
|
|
||||||
void CmndWebPassword(void)
|
void CmndWebPassword(void)
|
||||||
{
|
{
|
||||||
|
bool show_asterisk = (2 == XdrvMailbox.index);
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
SettingsUpdateText(SET_WEBPWD, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? WEB_PASSWORD : XdrvMailbox.data);
|
SettingsUpdateText(SET_WEBPWD, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? WEB_PASSWORD : XdrvMailbox.data);
|
||||||
ResponseCmndChar(SettingsText(SET_WEBPWD));
|
if (!show_asterisk) {
|
||||||
|
ResponseCmndChar(SettingsText(SET_WEBPWD));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
show_asterisk = true;
|
||||||
|
}
|
||||||
|
if (show_asterisk) {
|
||||||
Response_P(S_JSON_COMMAND_ASTERISK, XdrvMailbox.command);
|
Response_P(S_JSON_COMMAND_ASTERISK, XdrvMailbox.command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3105,7 +3096,7 @@ void CmndWebButton(void)
|
||||||
void CmndCors(void)
|
void CmndCors(void)
|
||||||
{
|
{
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
SettingsUpdateText(SET_CORS, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? WEB_PASSWORD : XdrvMailbox.data);
|
SettingsUpdateText(SET_CORS, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? CORS_DOMAIN : XdrvMailbox.data);
|
||||||
}
|
}
|
||||||
ResponseCmndChar(SettingsText(SET_CORS));
|
ResponseCmndChar(SettingsText(SET_CORS));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue