#include "WebCfgServer.h" #include WebCfgServer::WebCfgServer() : _wifiServer(80) {} void WebCfgServer::initialize() { _wifiServer.begin(); } void WebCfgServer::update() { // Create a client connections WiFiClient client = _wifiServer.available(); if (client) { int index = 0; char message[200]; while (client.connected()) { if (client.available()) { char c = client.read(); //read char by char HTTP request if (index < sizeof(message) - 1) { message[index] = c; index++; } message[index] = 0; //if HTTP request has ended if (c == '\n') { serveHtml(client); vTaskDelay( 5 / portTICK_PERIOD_MS); //stopping client client.stop(); } } } char *token = strtok(message, "?=&"); char *lastToken = NULL; bool configChanged = false; while (token != NULL) { if(lastToken != NULL) { TokenType lastTokenType = getParameterType(lastToken); TokenType tokenType = getParameterType(token); if(lastTokenType == TokenType::MQTT_SERVER && tokenType == TokenType::NONE) { configChanged = true; Serial.print("### "); Serial.println(token); // strcpy(_configuration->mqttServerAddress, token); } } lastToken = token; token = strtok(NULL, "?=&"); } // // if(configChanged) // { // _configuration->writeEeprom(); // _enabled = false; // } } } void WebCfgServer::serveHtml(WiFiClient &client) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println(""); client.println(""); client.println("NUKI Hub"); client.println(""); client.println(""); client.println("
"); client.print("MQTT Server:
"); // client.print("DNS Server: dnsServerAddress); // client.println("\" NAME=\"DNSSERVER\" SIZE=\"25\" MAXLENGTH=\"16\">
"); // // client.print("Gateway: gatewayAddress); // client.println("\" NAME=\"GATEWAY\" SIZE=\"25\" MAXLENGTH=\"16\">
"); // // client.print("IP Address: ipAddress); // client.println("\" NAME=\"IPADDRESS\" SIZE=\"25\" MAXLENGTH=\"16\">
"); // // client.print("Subnet mask: subnetMask); // client.println("\" NAME=\"SUBNET\" SIZE=\"25\" MAXLENGTH=\"16\">
"); // // client.print("MQTT publish interval (ms): mqttPublishInterval); // client.println("\" NAME=\"INTERVAL\" SIZE=\"25\" MAXLENGTH=\"6\">
"); client.println(""); client.println("
"); client.println("
"); client.println(""); client.println(""); } TokenType WebCfgServer::getParameterType(char *&token) { if (strcmp(token, "MQTTSERVER") == 0) { return TokenType::MQTT_SERVER; } return TokenType::NONE; }