adjust directory structure
This commit is contained in:
parent
f0672d3d72
commit
ff595af755
@ -1,273 +0,0 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "configuration.h"
|
||||
|
||||
|
||||
tConfigBlock configBlock;
|
||||
const uint32_t MAGIC = 0xC0DE0006;
|
||||
extern ESP8266WebServer webServer;
|
||||
|
||||
bool configSaved = false;
|
||||
|
||||
void configServeIndex() {
|
||||
bool configValid = (configBlock.magic == MAGIC);
|
||||
|
||||
if (! configValid) {
|
||||
strcpy(configBlock.wifiSsid, "TV_WLAN");
|
||||
strcpy(configBlock.wifiKey, "ioweishauhodohtheexairiedaihohbiethiihahchietoovieziajuboneecai");
|
||||
strcpy(configBlock.mqttBroker, "172.16.2.15");
|
||||
strcpy(configBlock.mqttUser, "esp2");
|
||||
strcpy(configBlock.mqttPass, "geheim");
|
||||
strcpy(configBlock.mqttClientId, "Kitchen");
|
||||
strcpy(configBlock.mqttTopic, "IoT/espThermometer2/measurement");
|
||||
configBlock.mqttPort = 8883;
|
||||
configBlock.measurePeriod = 300;
|
||||
}
|
||||
|
||||
String buffer =
|
||||
"<!doctype html"
|
||||
"<html lang=\"en\">"
|
||||
" <head>"
|
||||
" <title>ESP8266 Thermometer Configuration Page</title>"
|
||||
" </head>"
|
||||
" <body>"
|
||||
" <h1>ESP8266 Configuration Page</h1>";
|
||||
|
||||
if (configSaved) {
|
||||
configSaved = false;
|
||||
buffer += "<h2>Configuration saved</h2>";
|
||||
}
|
||||
|
||||
buffer +=
|
||||
" <form action=\"/config\" method=\"GET\">"
|
||||
" <table>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"wifiSsid\">Wifi SSID</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"wifiSsid\" id=\"wifiSsid\" ";
|
||||
|
||||
buffer += " size=\"32\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.wifiSsid;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"wifiKey\">Wifi Key</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"wifiKey\" id=\"wifiKey\" ";
|
||||
|
||||
buffer += " size=\"64\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.wifiKey;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"mqttBroker\">MQTT Broker</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"mqttBroker\" id=\"mqttBroker\" ";
|
||||
|
||||
buffer += " size=\"64\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.mqttBroker;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"mqttUser\">MQTT Username</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"mqttUser\" id=\"mqttUser\" ";
|
||||
|
||||
buffer += " size=\"32\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.mqttUser;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"mqttPass\">MQTT Password</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"mqttPass\" id=\"mqttPass\" ";
|
||||
|
||||
buffer += " size=\"32\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.mqttPass;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"mqttClientId\">MQTT ClientId</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"mqttClientId\" id=\"mqttClientId\" ";
|
||||
|
||||
buffer += " size=\"32\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.mqttClientId;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"mqttTopic\">MQTT Topic</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"mqttTopic\" id=\"mqttTopic\" ";
|
||||
|
||||
buffer += " size=\"64\" ";
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.mqttTopic;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"mqttPort\">MQTT Port</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"mqttPort\" id=\"mqttPort\" ";
|
||||
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.mqttPort;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"measurePeriod\">Measure Period</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"measurePeriod\" id=\"measurePeriod\" ";
|
||||
|
||||
buffer += " value=\"";
|
||||
buffer += configBlock.measurePeriod;
|
||||
buffer += "\"";
|
||||
|
||||
buffer +=
|
||||
" />"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" <tr>"
|
||||
" <td colspan=\"2\">"
|
||||
" <button type=\"submit\">Save</button>"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" </table>"
|
||||
" </form>"
|
||||
" </body>"
|
||||
"</html>";
|
||||
|
||||
webServer.send(200, "text/html", buffer);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("indexHtml request served");
|
||||
#endif
|
||||
}
|
||||
|
||||
void configServeGetConfiguration() {
|
||||
String arg;
|
||||
|
||||
arg = webServer.arg("wifiSsid");
|
||||
strcpy(configBlock.wifiSsid, arg.c_str());
|
||||
arg = webServer.arg("wifiKey");
|
||||
strcpy(configBlock.wifiKey, arg.c_str());
|
||||
arg = webServer.arg("mqttBroker");
|
||||
strcpy(configBlock.mqttBroker, arg.c_str());
|
||||
arg = webServer.arg("mqttUser");
|
||||
strcpy(configBlock.mqttUser, arg.c_str());
|
||||
arg = webServer.arg("mqttPass");
|
||||
strcpy(configBlock.mqttPass, arg.c_str());
|
||||
arg = webServer.arg("mqttClientId");
|
||||
strcpy(configBlock.mqttClientId, arg.c_str());
|
||||
arg = webServer.arg("mqttTopic");
|
||||
strcpy(configBlock.mqttTopic, arg.c_str());
|
||||
arg = webServer.arg("mqttPort");
|
||||
configBlock.mqttPort = atoi(arg.c_str());
|
||||
arg = webServer.arg("measurePeriod");
|
||||
configBlock.measurePeriod = atoi(arg.c_str());
|
||||
|
||||
configBlock.magic = MAGIC;
|
||||
|
||||
showConfiguration();
|
||||
|
||||
EEPROM.begin(512);
|
||||
EEPROM.put(EEPROM_ADDR, configBlock);
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println("EEPROM saved");
|
||||
|
||||
configSaved = true;
|
||||
webServer.sendHeader("Location", String("/"), true);
|
||||
webServer.send(302, "text/plain", "");
|
||||
//webServer.send(200, "text/html", "configuration saved");
|
||||
}
|
||||
|
||||
void showConfiguration() {
|
||||
Serial.println("Configuration is");
|
||||
|
||||
Serial.print("magic = ");
|
||||
Serial.println(configBlock.magic);
|
||||
|
||||
Serial.print("wifiSsid = ");
|
||||
Serial.println(configBlock.wifiSsid);
|
||||
|
||||
Serial.print("wifiKey = ");
|
||||
Serial.println(configBlock.wifiKey);
|
||||
|
||||
Serial.print("mqttBroker = ");
|
||||
Serial.println(configBlock.mqttBroker);
|
||||
|
||||
Serial.print("mqttUser = ");
|
||||
Serial.println(configBlock.mqttUser);
|
||||
|
||||
Serial.print("mqttPass = ");
|
||||
Serial.println(configBlock.mqttPass);
|
||||
|
||||
Serial.print("mqttClientId = ");
|
||||
Serial.println(configBlock.mqttClientId);
|
||||
|
||||
Serial.print("mqttTopic = ");
|
||||
Serial.println(configBlock.mqttTopic);
|
||||
|
||||
Serial.print("mqttPort = ");
|
||||
Serial.println(configBlock.mqttPort);
|
||||
|
||||
Serial.print("measurePeriod = ");
|
||||
Serial.println(configBlock.measurePeriod);
|
||||
|
||||
|
||||
Serial.println("---");
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
char wifiSsid[32];
|
||||
char wifiKey[64];
|
||||
char mqttBroker[64];
|
||||
char mqttUser[32];
|
||||
char mqttPass[32];
|
||||
char mqttClientId[32];
|
||||
char mqttTopic[64];
|
||||
uint32_t mqttPort;
|
||||
uint32_t measurePeriod;
|
||||
} tConfigBlock;
|
||||
|
||||
extern const uint32_t MAGIC;
|
||||
extern tConfigBlock configBlock;
|
||||
|
||||
void configServeIndex();
|
||||
void configServeGetConfiguration();
|
||||
void showConfiguration();
|
Loading…
x
Reference in New Issue
Block a user