connect to configured mqtt broker

This commit is contained in:
technyon
2022-03-27 10:20:23 +02:00
parent 5941a98f7e
commit ba864e0b67
7 changed files with 52 additions and 23 deletions

View File

@@ -1,8 +1,10 @@
#include "WebCfgServer.h"
#include <WiFiClient.h>
#include "PreferencesKeys.h"
WebCfgServer::WebCfgServer()
: _wifiServer(80)
WebCfgServer::WebCfgServer(Preferences* preferences)
: _wifiServer(80),
_preferences(preferences)
{}
@@ -13,6 +15,8 @@ void WebCfgServer::initialize()
void WebCfgServer::update()
{
bool configChanged = false;
// Create a client connections
WiFiClient client = _wifiServer.available();
@@ -60,22 +64,26 @@ void WebCfgServer::update()
if(lastTokenType == TokenType::MQTT_SERVER && tokenType == TokenType::NONE)
{
configChanged = true;
Serial.print("### ");
Serial.println(token);
// strcpy(_configuration->mqttServerAddress, token);
_preferences->putString(preference_mqtt_broker, token);
configChanged = true;
}
}
lastToken = token;
token = strtok(NULL, "?=&");
}
//
// if(configChanged)
// {
// _configuration->writeEeprom();
// _enabled = false;
// }
if(configChanged)
{
_enabled = false;
_preferences->end();
Serial.println(F("Restarting"));
vTaskDelay( 200 / portTICK_PERIOD_MS);
ESP.restart();
}
}
vTaskDelay(200 / portTICK_PERIOD_MS);
}
void WebCfgServer::serveHtml(WiFiClient &client)
@@ -93,7 +101,7 @@ void WebCfgServer::serveHtml(WiFiClient &client)
client.println("<FORM ACTION=method=get >");
client.print("MQTT Server: <INPUT TYPE=TEXT VALUE=\"");
client.print("");
client.print(_preferences->getString(preference_mqtt_broker));
client.println("\" NAME=\"MQTTSERVER\" SIZE=\"25\" MAXLENGTH=\"40\"><BR>");
// client.print("DNS Server: <INPUT TYPE=TEXT VALUE=\"");