Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to configure mqtt port #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label" for="mqtt_port">MQTT Port</label>
<div class="col-md-4">
<input id="mqtt_port" name="mqtt_port" type="text" placeholder="Port for connecting to your MQTT Broker" class="form-control input-md" value="%MQTT_PORT%">
<small class="text-muted">Leave empty if you want to use the default port (1833).</small>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label" for="mqtt_username">MQTT Username</label>
<div class="col-md-4">
Expand Down
2 changes: 2 additions & 0 deletions src/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}
Expand Down