Stripped away bootstrap css and created a smaller boot.css as replacement. Load real bootstrap from CDN. Added HTML only (non-js) view of data

This commit is contained in:
Gunnar Skjold 2020-01-28 21:10:54 +01:00
parent 7fdedd8bcf
commit 7e4047096b
7 changed files with 375 additions and 38 deletions

View File

@ -3,7 +3,7 @@
#include "index_html.h"
#include "configuration_html.h"
#include "bootstrap_css.h"
#include "boot_css.h"
#include "application_css.h"
#include "gaugemeter_js.h"
#include "index_js.h"
@ -22,7 +22,7 @@ void AmsWebServer::setup(configuration* config, Stream* debugger) {
server.on("/", std::bind(&AmsWebServer::indexHtml, this));
server.on("/configuration", std::bind(&AmsWebServer::configurationHtml, this));
server.on("/css/bootstrap.css", std::bind(&AmsWebServer::bootstrapCss, this));
server.on("/css/boot.css", std::bind(&AmsWebServer::bootCss, this));
server.on("/css/application.css", std::bind(&AmsWebServer::applicationCss, this));
server.on("/js/gaugemeter.js", std::bind(&AmsWebServer::gaugemeterJs, this));
server.on("/js/index.js", std::bind(&AmsWebServer::indexJs, this));
@ -53,6 +53,20 @@ void AmsWebServer::loop() {
void AmsWebServer::setJson(StaticJsonDocument<500> json) {
this->json = json;
if(!json.isNull()) {
println(" json has data");
p = json["data"]["P"].as<int>();
if(json["data"].containsKey("U1")) {
u1 = json["data"]["U1"].as<double>();
u2 = json["data"]["U2"].as<double>();
u3 = json["data"]["U3"].as<double>();
i1 = json["data"]["I1"].as<double>();
i2 = json["data"]["I2"].as<double>();
i3 = json["data"]["I3"].as<double>();
}
}
}
bool AmsWebServer::checkSecurity(byte level) {
@ -91,9 +105,13 @@ void AmsWebServer::indexHtml() {
String html = String((const __FlashStringHelper*) INDEX_HTML);
html.replace("${version}", VERSION);
if(WiFi.getMode() != WIFI_AP) {
html.replace("/css/bootstrap.css", "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css");
}
html.replace("${data.P}", String(p));
html.replace("${data.U1}", String(u1, 1));
html.replace("${data.U2}", String(u2, 1));
html.replace("${data.U3}", String(u3, 1));
html.replace("${data.I1}", String(i1, 1));
html.replace("${data.I2}", String(i2, 1));
html.replace("${data.I3}", String(i3, 1));
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server.sendHeader("Pragma", "no-cache");
@ -109,9 +127,6 @@ void AmsWebServer::configurationHtml() {
String html = String((const __FlashStringHelper*) CONFIGURATION_HTML);
html.replace("${version}", VERSION);
if(WiFi.getMode() != WIFI_AP) {
html.replace("/css/bootstrap.css", "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css");
}
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server.sendHeader("Pragma", "no-cache");
@ -169,13 +184,13 @@ void AmsWebServer::configurationHtml() {
server.send(200, "text/html", html);
}
void AmsWebServer::bootstrapCss() {
println("Serving /bootstrap.css over http...");
void AmsWebServer::bootCss() {
println("Serving /boot.css over http...");
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server.sendHeader("Pragma", "no-cache");
server.sendHeader("Expires", "-1");
server.send(200, "text/css", BOOTSTRAP_CSS);
server.send(200, "text/css", BOOT_CSS);
}
void AmsWebServer::applicationCss() {

View File

@ -31,6 +31,8 @@ private:
Stream* debugger;
StaticJsonDocument<500> json;
int maxPwr;
int p;
double u1, u2, u3, i1, i2, i3;
#if defined(ESP8266)
ESP8266WebServer server;
@ -42,7 +44,7 @@ private:
void indexHtml();
void configurationHtml();
void bootstrapCss();
void bootCss();
void applicationCss();
void gaugemeterJs();
void indexJs();

327
src/boot_css.h Normal file
View File

@ -0,0 +1,327 @@
const char BOOT_CSS[] PROGMEM = R"=="==(
/* Ripped necessary style from bootstrap 4.4.1 to make the page look good without internet access. Meant to be overridden by CSS from CDN */
:root {
--blue: #007bff;
--indigo: #6610f2;
--purple: #6f42c1;
--pink: #e83e8c;
--red: #dc3545;
--orange: #fd7e14;
--yellow: #ffc107;
--green: #28a745;
--teal: #20c997;
--cyan: #17a2b8;
--white: #fff;
--gray: #6c757d;
--gray-dark: #343a40;
--primary: #007bff;
--secondary: #6c757d;
--success: #28a745;
--info: #17a2b8;
--warning: #ffc107;
--danger: #dc3545;
--light: #f8f9fa;
--dark: #343a40;
--breakpoint-xs: 0;
--breakpoint-sm: 576px;
--breakpoint-md: 768px;
--breakpoint-lg: 992px;
--breakpoint-xl: 1200px;
--font-family-sans-serif: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
--font-family-monospace: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
}
html {
font-family: sans-serif;
line-height: 1.15;
-webkit-text-size-adjust: 100%;
-webkit-tap-highlight-color: transparent;
color: -internal-root-color;
}
body {
display: block;
margin: 8px;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #212529;
text-align: left;
background-color: #fff;
}
.bg-white {
background-color: #fff!important;
}
.bg-light {
background-color: #f8f9fa!important;
}
.bg-purple {
background-color: var(--purple);
}
.text-white-50 {
color: rgba(255,255,255,.5)!important;
}
.mb-0, .my-0 {
margin-bottom: 0!important;
}
.mb-2, .my-2 {
margin-bottom: .5rem!important;
}
.mt-2, .my-2 {
margin-top: .5rem!important;
}
.pb-2, .py-2 {
padding-bottom: .5rem!important;
}
.p-3 {
padding: 1rem!important;
}
.mb-3, .my-3 {
margin-bottom: 1rem!important;
}
.mt-3, .my-3 {
margin-top: 1rem!important;
}
.mb-4, .my-4 {
margin-bottom: 1.5rem!important;
}
.shadow {
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15)!important;
}
.align-items-center {
-ms-flex-align: center!important;
align-items: center!important;
}
.border-bottom {
border-bottom: 1px solid #dee2e6!important;
}.rounded {
border-radius: .25rem!important;
}
div {
display: block;
}
.container {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
article, aside, figcaption, figure, footer, header, hgroup, main, nav, section {
display: block;
}
main {
display: block;
}
.text-white {
color: #fff!important;
}
.text-right {
text-align: right!important;
}
.text-center {
text-align: center!important;
}
.h1, .h2, .h3, .h4, .h5, .h6, h1, h2, h3, h4, h5, h6 {
margin-bottom: .5rem;
font-weight: 500;
line-height: 1.2;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 0;
margin-bottom: .5rem;
}
.h6, h6 {
font-size: 1rem;
}
.row {
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.d-flex {
display: -ms-flexbox!important;
display: flex!important;
}
.col, .col-1, .col-10, .col-11, .col-12, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-auto, .col-lg, .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-auto, .col-md, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-auto, .col-sm, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-auto, .col-xl, .col-xl-1, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-auto {
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
}
.col-2 {
-ms-flex: 0 0 16.666667%;
flex: 0 0 16.666667%;
max-width: 16.666667%;
}
.col-3 {
-ms-flex: 0 0 25%;
flex: 0 0 25%;
max-width: 25%;
}
.col-4 {
-ms-flex: 0 0 33.333333%;
flex: 0 0 33.333333%;
max-width: 33.333333%;
}
.col-5 {
-ms-flex: 0 0 41.666667%;
flex: 0 0 41.666667%;
max-width: 41.666667%;
}
.col-6 {
-ms-flex: 0 0 50%;
flex: 0 0 50%;
max-width: 50%;
}
.col-8 {
-ms-flex: 0 0 66.666667%;
flex: 0 0 66.666667%;
max-width: 66.666667%;
}
.col-9 {
-ms-flex: 0 0 75%;
flex: 0 0 75%;
max-width: 75%;
}
a {
color: #007bff;
text-decoration: none;
background-color: transparent;
}
.btn {
display: inline-block;
font-weight: 400;
color: #212529;
text-align: center;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: transparent;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.btn-outline-secondary {
color: #6c757d;
border-color: #6c757d;
}
.btn-primary {
color: #fff;
background-color: #007bff;
border-color: #007bff;
}
.form-group {
margin-bottom: 1rem;
}
.form-control {
display: block;
width: 100%;
height: calc(1.5em + .75rem + 2px);
padding: .375rem .75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
input:not([type="image" i]) {
box-sizing: border-box;
}
input {
-webkit-writing-mode: horizontal-tb !important;
text-rendering: auto;
color: -internal-light-dark-color(black, white);
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
-webkit-appearance: textfield;
background-color: -internal-light-dark-color(white, black);
-webkit-rtl-ordering: logical;
cursor: text;
margin: 0em;
font: 400 13.3333px Arial;
padding: 1px 0px;
border-width: 2px;
border-style: inset;
border-color: initial;
border-image: initial;
}
button, input {
overflow: visible;
}
button, input, optgroup, select, textarea {
margin: 0;
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
hr {
margin-top: 1rem;
margin-bottom: 1rem;
border: 0;
border-top: 1px solid rgba(0,0,0,.1);
box-sizing: content-box;
height: 0;
overflow: visible;
}
@media (min-width: 576px) {
.container, .container-sm {
max-width: 540px;
}
}
@media (min-width: 768px) {
.container, .container-md, .container-sm {
max-width: 720px;
}
.col-md-4 {
-ms-flex: 0 0 33.333333%;
flex: 0 0 33.333333%;
max-width: 33.333333%;
}
.col-md-6 {
-ms-flex: 0 0 50%;
flex: 0 0 50%;
max-width: 50%;
}
}
@media (min-width: 992px) {
.container, .container-lg, .container-md, .container-sm {
max-width: 960px;
}
.col-lg-4 {
-ms-flex: 0 0 33.333333%;
flex: 0 0 33.333333%;
max-width: 33.333333%;
}
}
@media (min-width: 1200px) {
.container, .container-lg, .container-md, .container-sm, .container-xl {
max-width: 1140px;
}
}
*, ::after, ::before {
box-sizing: border-box;
}
*, ::after, ::before {
box-sizing: border-box;
}
)=="==";

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,8 @@ const char CONFIGURATION_HTML[] PROGMEM = R"=="==(
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AMS reader - configuration</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="/css/boot.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="/css/application.css"/>
</head>
<body class="bg-light">

View File

@ -5,7 +5,8 @@ const char INDEX_HTML[] PROGMEM = R"=="==(
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AMS reader</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="/css/boot.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="/css/application.css"/>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="/js/gaugemeter.js"></script>
@ -23,7 +24,11 @@ const char INDEX_HTML[] PROGMEM = R"=="==(
<div class="row">
<div class="col-md-4">
<div class="text-center">
<div id="P" class="SimpleMeter">
${data.P} W
</div>
<div class="GaugeMeter rounded"
style="display: none;"
data-size="200px"
data-text_size="0.11"
data-width="25"
@ -40,20 +45,20 @@ const char INDEX_HTML[] PROGMEM = R"=="==(
</div>
</div>
<div class="col-md-4">
<div id="P1" class="row" style="display: none;">
<div id="P1" class="row">
<div class="col-2">P1</div>
<div class="col-5 text-right"><span id="U1">-</span> V</div>
<div class="col-5 text-right"><span id="I1">-</span> A</div>
<div class="col-5 text-right"><span id="U1">${data.U1}</span> V</div>
<div class="col-5 text-right"><span id="I1">${data.I1}</span> A</div>
</div>
<div id="P2" class="row" style="display: none;">
<div id="P2" class="row">
<div class="col-2">P2</div>
<div class="col-5 text-right"><span id="U2">-</span> V</div>
<div class="col-5 text-right"><span id="I2">-</span> A</div>
<div class="col-5 text-right"><span id="U2">${data.U2}</span> V</div>
<div class="col-5 text-right"><span id="I2">${data.I2}</span> A</div>
</div>
<div id="P3" class="row" style="display: none;">
<div id="P3" class="row">
<div class="col-2">P3</div>
<div class="col-5 text-right"><span id="U3">-</span> V</div>
<div class="col-5 text-right"><span id="I3">-</span> A</div>
<div class="col-5 text-right"><span id="U3">${data.U3}</span> V</div>
<div class="col-5 text-right"><span id="I3">${data.I3}</span> A</div>
</div>
</div>
</div>

View File

@ -8,7 +8,9 @@ var fetch = function() {
url: '/data.json',
dataType: 'json',
}).done(function(json) {
$(".SimpleMeter").hide();
var el = $(".GaugeMeter");
el.show();
var rate = 2500;
if(json.data) {
el.data('percent', json.pct);
@ -59,9 +61,6 @@ var fetch = function() {
el.data('percent', 0);
el.data('text', '-');
el.gaugeMeter();
$('#P1').hide();
$('#P2').hide();
$('#P3').hide();
nextrefresh = 2500;
}
if(!nextrefresh || nextrefresh < 500) {
@ -72,9 +71,6 @@ var fetch = function() {
el.data('percent', 0);
el.data('text', '-');
el.gaugeMeter();
$('#P1').hide();
$('#P2').hide();
$('#P3').hide();
nextrefresh = 10000;
setTimeout(fetch, nextrefresh);
});