diff --git a/docs/upload/builds.md b/docs/upload/builds.md
index 71eb511..2ea4da8 100644
--- a/docs/upload/builds.md
+++ b/docs/upload/builds.md
@@ -90,7 +90,7 @@ build_flags =
'-DMQTT_USER="mqttusername"'
'-DMQTT_PASS="mqttpassword"'
'-DMQTT_SERVER="mqttserver.local"'
- '-Dota_password="otapassword"'
+ '-Dgw_password="12345678"'
'-DLED_RECEIVE=LED_BUILTIN' ; Comment 1
'-DLED_RECEIVE_ON=LOW' ; Comment 2
'-DRF_RECEIVER_GPIO=13'
diff --git a/docs/upload/portal.md b/docs/upload/portal.md
index ffbea0a..61ca49d 100644
--- a/docs/upload/portal.md
+++ b/docs/upload/portal.md
@@ -4,7 +4,7 @@
Once loaded into your ESP, and if you don't use the manual configuration, you have to set your network parameters with WiFi Manager portal.
-From your smartphone, search for OpenMQTTGateway or OMG_ WiFi network and connect to it with the `WifiManager_password` you have defined (the default password is **"your_password"**), or if you are using a device sold by Theengs or the macro `-DWM_PWD_FROM_MAC=true`, the password will be the last eight digits of the device MAC Address with upper case.
+From your smartphone, search for OpenMQTTGateway or OMG_ WiFi network and connect to it without password, or if you are using a device sold by Theengs or the macro `-DWM_PWD_FROM_MAC=true`, the password will be the last eight digits of the device MAC Address with upper case.
Example, the password would be `CCDDEEFF` for a MAC Address `AABBCCDDEEFF`.
For the Theengs Plug, the MAC Address can be found on the device sticker, and for all the devices, it is printed on the serial monitor logs.
@@ -35,8 +35,10 @@ If the board is connected by ethernet, the Wifi and password can be empty. If yo
* Set your MQTT Server password (optional, 64 characters maximum)
* Set your MQTT base topic if you need to change it (you must keep the / at the end) (default: home/, 64 characters maximum)
* Set your gateway name if you need to change it
-* Set your Over The Air password `ota_password`, this password is used for local and remote OTA - it is also the password being used for the WebUI login. (default: OTAPASSWORD, 64 characters maximum)
-
+* Set your gateway password (default: empty, 8 characters minimum, 64 maximum), this password is used for
+ * Local and remote OTA
+ * WebUI login (login:"admin", password: "")
+ * WiFi Manager Access Point password after initial config
* Click on save

diff --git a/docs/use/gateway.md b/docs/use/gateway.md
index e4184e9..385526f 100644
--- a/docs/use/gateway.md
+++ b/docs/use/gateway.md
@@ -54,6 +54,12 @@ This command can also be used with other controllers that does not support the i
If the new connection fails the gateway will fallback to the previous connection.
:::
+## Change the Gateway password
+
+The password must be 8 characters minimum.
+
+`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"gw_pass":"12345678"}'`
+
## Change the MQTT broker credentials
```
mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m
diff --git a/docs/use/webui.md b/docs/use/webui.md
index 260b1dd..24198c0 100644
--- a/docs/use/webui.md
+++ b/docs/use/webui.md
@@ -10,7 +10,7 @@ For ESP32 based environments a WebUI is available to provide basic configuration
# Login Authentication
-By default access to the WebUI uses basic authentication to control access to your OpenMQTTGateway Device. The login is `admin` and the password is your ota_password (if unchanged, the default ota_password is `OTAPASSWORD`).
+By default access to the WebUI uses basic authentication to control access to your OpenMQTTGateway Device. The login is `admin` and the password is your `gateway password` (if unchanged during onboarding there is no password).
::: warning
The communication with the WebUI is not encrypted, which means that your data may be visible on your local network.
diff --git a/main/User_config.h b/main/User_config.h
index 3d06c11..7bd7348 100644
--- a/main/User_config.h
+++ b/main/User_config.h
@@ -121,9 +121,6 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
#endif
//#define WM_PWD_FROM_MAC true // enable to set the password from the last 8 digits of the ESP MAC address for enhanced security, enabling this option requires to have access to the MAC address, either through a sticker or with serial monitoring
-#ifndef WifiManager_password
-# define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
-#endif
#ifndef WifiManager_ssid
# define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point
#endif
@@ -407,8 +404,8 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
#ifndef ota_hostname
# define ota_hostname Gateway_Name
#endif
-#ifndef ota_password
-# define ota_password "OTAPASSWORD"
+#ifndef gw_password
+# define gw_password ""
#endif
#ifndef ota_port
# define ota_port 8266
@@ -733,7 +730,7 @@ char gateway_name[parameters_size + 1] = Gateway_Name;
void connectMQTT();
#ifndef ESPWifiManualSetup
-void saveMqttConfig();
+void saveConfig();
#endif
unsigned long uptime();
diff --git a/main/ZwebUI.ino b/main/ZwebUI.ino
index a11a0a0..ba47d64 100644
--- a/main/ZwebUI.ino
+++ b/main/ZwebUI.ino
@@ -768,18 +768,18 @@ void handleMQ() {
# ifndef ESPWifiManualSetup
if (update) {
- Log.warning(F("[WebUI] Save MQTT and Restart" CR));
+ Log.warning(F("[WebUI] Save MQTT and Reconnect" CR));
char jsonChar[100];
serializeJson(modules, jsonChar, measureJson(modules) + 1);
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
- snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save MQTT and Restart").c_str());
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save MQTT and Reconnect").c_str());
String response = String(buffer);
response += String(restart_script);
response += String(script);
response += String(style);
- snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save MQTT and Restart");
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save MQTT and Reconnect");
response += String(buffer);
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
response += String(buffer);
@@ -816,6 +816,75 @@ void handleMQ() {
server.send(200, "text/html", response);
}
+/**
+ * @brief /CG - Configure Gateway Page
+ * T: handleCG: uri: /gw, args: 2, method: 1
+ * T: handleCG Arg: 0, gp=1234
+ * T: handleCG Arg: 1, save=
+ */
+
+void handleCG() {
+ WEBUI_TRACE_LOG(F("handleCG: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
+ WEBUI_SECURE
+ bool update = false;
+ StaticJsonDocument jsonBuffer;
+ JsonObject WEBtoSYS = jsonBuffer.to();
+
+ if (server.args()) {
+ for (uint8_t i = 0; i < server.args(); i++) {
+ WEBUI_TRACE_LOG(F("handleCG Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
+ }
+ if (server.hasArg("save") && server.hasArg("gp") && strcmp(ota_pass, server.arg("gp").c_str())) {
+ strncpy(ota_pass, server.arg("gp").c_str(), parameters_size);
+ WEBtoSYS["gw_pass"] = ota_pass;
+ update = true;
+ }
+ }
+
+ if (update) {
+ Log.warning(F("[WebUI] Save Password and Restart" CR));
+
+ char jsonChar[100];
+ serializeJson(modules, jsonChar, measureJson(modules) + 1);
+ char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
+
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save Password and Restart").c_str());
+ String response = String(buffer);
+ response += String(restart_script);
+ response += String(script);
+ response += String(style);
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save Password and Restart");
+ response += String(buffer);
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
+ response += String(buffer);
+ server.send(200, "text/html", response);
+
+ delay(2000); // Wait for web page to be sent before
+ String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSset);
+ String output;
+ serializeJson(WEBtoSYS, output);
+ Log.notice(F("[WebUI] MQTTtoSYS %s" CR), output.c_str());
+ MQTTtoSYS((char*)topic.c_str(), WEBtoSYS);
+ } else {
+ Log.warning(F("[WebUI] No changes" CR));
+ }
+
+ char jsonChar[100];
+ serializeJson(modules, jsonChar, measureJson(modules) + 1);
+
+ char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
+
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure Gateway").c_str());
+ String response = String(buffer);
+ response += String(script);
+ response += String(style);
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_gateway_body, jsonChar, gateway_name, ota_pass);
+ response += String(buffer);
+ snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
+ response += String(buffer);
+ server.send(200, "text/html", response);
+}
+
/**
* @brief /LO - Configure Logging Page
* T: handleLO: uri: /lo, args: 2, method: 1
@@ -1419,6 +1488,7 @@ void WebUISetup() {
server.on("/cn", handleCN); // Configuration
server.on("/wi", handleWI); // Configure Wifi
server.on("/mq", handleMQ); // Configure MQTT
+ server.on("/cg", handleCG); // Configure Gateway"
server.on("/wu", handleWU); // Configure WebUI
# ifdef ZgatewayLORA
server.on("/la", handleLA); // Configure LORA
diff --git a/main/config_WebContent.h b/main/config_WebContent.h
index 90a7b2f..5aa9652 100644
--- a/main/config_WebContent.h
+++ b/main/config_WebContent.h
@@ -43,11 +43,12 @@
#define configure_1 "