Enable config page on runtime with populated form

This commit is contained in:
Gunnar Skjold
2020-01-15 20:17:06 +01:00
parent 568180d7b2
commit aeb161455e
5 changed files with 303 additions and 24 deletions

File diff suppressed because one or more lines are too long

View File

@@ -27,6 +27,7 @@
class HanConfigAp {
public:
void setup(int accessPointButtonPin, Stream* debugger);
void enableWeb();
bool loop();
bool hasConfig();
configuration config;
@@ -46,6 +47,7 @@ private:
// Web server
static void handleRoot();
static void handleStyle();
static void handleSave();
#if defined(ESP8266)
static ESP8266WebServer server;

View File

@@ -0,0 +1,72 @@
const char CONFIG_HTML[] PROGMEM = R"=="==(
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/style.css">
<title>AMS2MQTT - configuration</title>
</head>
<body>
<form method='post' action='/save'>
<div class="wrapper">
<div class="inner-wrapper">
<div>
<h2>WiFi</h2>
</div>
<div>
<input type='text' name='ssid' value="${config.ssid}" placeholder="SSID">
</div>
<div>
<input type='password' name='ssidPassword' value="${config.ssidPassword}" placeholder="Password">
</div>
</div>
<div class="inner-wrapper">
<div>
<h2>Meter Type</h2>
</div>
<div class="select-style">
<select name="meterType">
<option value="0" ${config.meterType0} disabled class="disabled-option"> SELECT TYPE </option>
<option value="1" ${config.meterType1}>Kaifa</option>
<option value="2" ${config.meterType2}>Aidon</option>
<option value="3" ${config.meterType3}>Kamstrup</option>
</select>
</div>
</div>
<div class="inner-wrapper">
<div>
<h2>MQTT</h2>
</div>
<div>
<label>Server & port:</label>
<input type='text' name='mqtt' value="${config.mqtt}" placeholder="server">
<input type='number' name='mqttPort' value="${config.mqttPort}" placeholder="port">
</div>
<div>
<label>Client ID:</label>
<input type='text' name='mqttClientID' value="${config.mqttClientID}" placeholder="client id">
</div>
<div>
<label>Publish topic: </label>
<input type='text' name='mqttPublishTopic' value="${config.mqttPublishTopic}" placeholder="topic">
</div>
<div>
<label>Username:</label>
<input type='text' name='mqttUser' value="${config.mqttUser}" placeholder="Blank for insecure">
</div>
<div>
<label>Password:</label>
<input type='password' name='mqttPass' value="${config.mqttPass}" placeholder="Blank for insecure">
</div>
<div>
<input class="submit-button" type='submit' value='save'>
</div>
</div>
</div>
</form>
<body>
</html>
)=="==";

View File

@@ -0,0 +1,135 @@
const char STYLE_CSS[] PROGMEM = R"=="==(
body,div,input {
font-family: "Roboto", Arial, Lucida Grande;
}
.wrapper {
width: 500px;
position: absolute;
padding: 30px;
background-color: #FFF;
border-radius: 1px;
color: #333;
border-color: rgba(0, 0, 0, 0.03);
box-shadow: 0 2px 2px rgba(0, 0, 0, .24), 0 0 2px rgba(0, 0, 0, .12);
margin-left: 20px;
margin-top: 20px;
}
div {
padding-bottom: 5px;
}
label {
font-family: "Roboto", "Helvetica Neue", sans-serif;
font-size: 14px;
line-height: 16px;
width: 100px;
display: inline-block;
}
input {
font-family: "Roboto", "Helvetica Neue", sans-serif;
font-size: 14px;
line-height: 16px;
bottom: 30px;
border: none;
border-bottom: 1px solid #d4d4d4;
padding: 10px;
background: transparent;
transition: all .25s ease;
}
input[type=number] {
width: 70px;
margin-left: 5px;
}
input:focus {
outline: none;
border-bottom: 1px solid #3f51b5;
}
h2 {
text-align: left;
font-size: 20px;
font-weight: bold;
letter-spacing: 3px;
line-height: 28px;
}
.submit-button {
position: absolute;
text-align: right;
border-radius: 20px;
border-bottom-right-radius: 0;
border-top-right-radius: 0;
background-color: #3f51b5;
color: #FFF;
padding: 12px 25px;
display: inline-block;
font-size: 12px;
font-weight: bold;
letter-spacing: 2px;
right: 0px;
bottom: 10px;
cursor: pointer;
transition: all .25s ease;
box-shadow: 0 2px 2px rgba(0, 0, 0, .24), 0 0 2px rgba(0, 0, 0, .12);
width: 100px;
}
.select-style {
border-top: 10px solid white;
border-bottom: 1px solid #d4d4d4;
color: #ffffff;
cursor: pointer;
display: block;
font-family: Roboto, "Helvetica Neue", sans-serif;
font-size: 14px;
font-weight: 400;
height: 16px;
line-height: 14px;
min-width: 200px;
padding-bottom: 7px;
padding-left: 0px;
padding-right: 0px;
position: relative;
text-align: left;
width: 80%;
-webkit-box-direction: normal;
overflow: hidden;
background: #ffffff url("data:image/png;base64,R0lGODlhDwAUAIABAAAAAP///yH5BAEAAAEALAAAAAAPABQAAAIXjI+py+0Po5wH2HsXzmw//lHiSJZmUAAAOw==") no-repeat 98% 50%;
}
.disabled-option {
color: #d4d4d4;
}
.select-style select {
padding: 5px 8px;
width: 100%;
border: none;
box-shadow: none;
background: transparent;
background-image: none;
-webkit-appearance: none;
}
.select-style select:focus {
outline: none;
border: none;
}
@media only screen and (max-width: 1000px) {
.wrapper {
width: 80%;
}
}
@media only screen and (max-width: 300px) {
.wrapper {
width: 75%;
}
}
@media only screen and (max-width: 600px) {
.wrapper {
width: 80%;
margin-left: 0px;
margin-top: 0px;
}
.submit-button {
bottom: 0px;
width: 70px;
}
input {
width: 100%;
}
}
)=="==";