diff --git a/data/settings.html b/data/settings.html index 7594866..e52a856 100644 --- a/data/settings.html +++ b/data/settings.html @@ -69,6 +69,14 @@ +
+ +
+ + Leave empty if you want to use the default port (1833). +
+
+
diff --git a/src/SettingsManager.cpp b/src/SettingsManager.cpp index 7f9177f..de10050 100644 --- a/src/SettingsManager.cpp +++ b/src/SettingsManager.cpp @@ -18,6 +18,7 @@ bool SettingsManager::loadAppSettings() { Preferences preferences; if (preferences.begin("appSettings", true)) { appSettings.mqttServer = preferences.getString("mqttServer", String("")); + appSettings.mqttPort = preferences.getUShort("mqttPort", (uint16_t) 1883); appSettings.mqttUsername = preferences.getString("mqttUsername", String("")); appSettings.mqttPassword = preferences.getString("mqttPassword", String("")); appSettings.mqttRootTopic = preferences.getString("mqttRootTopic", String("fingerprintDoorbell")); @@ -45,6 +46,7 @@ void SettingsManager::saveAppSettings() { Preferences preferences; preferences.begin("appSettings", false); preferences.putString("mqttServer", appSettings.mqttServer); + preferences.putUShort("mqttPort", appSettings.mqttPort); preferences.putString("mqttUsername", appSettings.mqttUsername); preferences.putString("mqttPassword", appSettings.mqttPassword); preferences.putString("mqttRootTopic", appSettings.mqttRootTopic); diff --git a/src/SettingsManager.h b/src/SettingsManager.h index 17952f1..abc4c33 100644 --- a/src/SettingsManager.h +++ b/src/SettingsManager.h @@ -14,6 +14,7 @@ struct AppSettings { String mqttServer = ""; String mqttUsername = ""; String mqttPassword = ""; + uint16_t mqttPort = 11883; String mqttRootTopic = "fingerprintDoorbell"; String ntpServer = "pool.ntp.org"; String sensorPin = "00000000"; diff --git a/src/main.cpp b/src/main.cpp index 8d7db21..36a467a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -353,6 +353,7 @@ void startWebserver(){ Serial.println("Save settings"); AppSettings settings = settingsManager.getAppSettings(); settings.mqttServer = request->arg("mqtt_server"); + settings.mqttPort = (uint16_t) request->arg("mqtt_port").toInt(); settings.mqttUsername = request->arg("mqtt_username"); settings.mqttPassword = request->arg("mqtt_password"); settings.mqttRootTopic = request->arg("mqtt_rootTopic"); @@ -662,8 +663,8 @@ void setup() if (WiFi.hostByName(settingsManager.getAppSettings().mqttServer.c_str(), mqttServerIp)) { mqttConfigValid = true; - Serial.println("IP used for MQTT server: " + mqttServerIp.toString()); - mqttClient.setServer(mqttServerIp , 1883); + Serial.println("IP used for MQTT server: " + mqttServerIp.toString() + " | Port: " + String(settingsManager.getAppSettings().mqttPort)); + mqttClient.setServer(mqttServerIp , settingsManager.getAppSettings().mqttPort); mqttClient.setCallback(mqttCallback); connectMqttClient(); }