Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
a747a34d
Commit
a747a34d
authored
Feb 17, 2022
by
Eric Duminil
Browse files
Trying to split html in 4 parts
parent
71c2cc97
Pipeline
#5855
passed with stage
in 2 minutes and 35 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/web_server.cpp
View file @
a747a34d
...
...
@@ -19,7 +19,8 @@
namespace
web_server
{
const
char
*
header_template
;
const
char
*
body_template
;
const
char
*
body1_template
;
const
char
*
body2_template
;
const
char
*
script_template
;
void
handleWebServerRoot
();
void
handlePageNotFound
();
...
...
@@ -68,30 +69,37 @@ namespace web_server {
"<div class='pure-g'>"
"<table id='table' class='pure-table-striped pure-u-1 pure-u-md-1-2'>"
);
body_template
=
PSTR
(
"<tr><th colspan='2'>%s</th></tr>"
"<tr><td>CO<sub>2</sub></td><td>%5d ppm</td></tr>"
"<tr><td>Temperature</td><td>%.1f℃</td></tr>"
"<tr><td>Humidity</td><td>%.1f%%</td></tr>"
"<tr><td>Last measurement</td><td>%s</td></tr>"
"<tr><td>Timestep</td><td>%5d s</td></tr>"
"<tr><th colspan='2'>CSV</th></tr>"
//TODO: Gray out if !config::csv_active
"<tr><td>Last write</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"<tr><td>Available space</td><td>%d kB</td></tr>"
"<tr><th colspan='2'>MQTT</th></tr>"
//TODO: Gray out if !config::mqtt_active
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Last publish</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
body1_template
=
PSTR
(
"<tr><th colspan='2'>%s</th></tr>"
"<tr><td>CO<sub>2</sub></td><td>%5d ppm</td></tr>"
"<tr><td>Temperature</td><td>%.1f℃</td></tr>"
"<tr><td>Humidity</td><td>%.1f%%</td></tr>"
"<tr><td>Last measurement</td><td>%s</td></tr>"
"<tr><td>Timestep</td><td>%5d s</td></tr>"
"<tbody>"
"<tr><th colspan='2'>CSV</th></tr>"
//TODO: Gray out if !config::csv_active
"<tr><td>Last write</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"<tr><td>Available space</td><td>%d kB</td></tr>"
"</tbody>"
"<tbody>"
"<tr><th colspan='2'>MQTT</th></tr>"
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Last publish</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>"
);
body2_template
=
PSTR
(
#if defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>"
//TODO: Gray out if !config::lora_active
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Frequency</td><td>%s MHz</td></tr>"
"<tr><td>Last transmission</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"<tbody>"
"<tr><th colspan='2'>LoRaWAN</th></tr>"
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Frequency</td><td>%s MHz</td></tr>"
"<tr><td>Last transmission</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>"
#endif
"<tr><th colspan='2'>Sensor</th></tr>"
"<tr><td>Temperature offset</td><td>%.1fK</td></tr>"
//TODO: Read it from sensor?
"<tr><td>Temperature offset</td><td>%.1fK</td></tr>"
"<tr><td>Auto-calibration?</td><td>%s</td></tr>"
"<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>"
"<tr><td>Local IP</td><td><a href='http://%s'>%s</a></td></tr>"
...
...
@@ -195,7 +203,6 @@ namespace web_server {
char
content
[
2000
];
// Current size (with Lorawan):
// INFO - Header size : 1826 - Body size : 2005 - Script size : 1904
//FIXME: Body too long with Lorawan! Split in 4 parts?
snprintf_P
(
content
,
sizeof
(
content
),
header_template
,
sensor
::
co2
,
config
::
ampel_name
(),
wifi
::
local_ip
,
csv_writer
::
filename
);
...
...
@@ -206,10 +213,16 @@ namespace web_server {
web_config
::
http
.
send_P
(
200
,
PSTR
(
"text/html"
),
content
);
// Body
snprintf_P
(
content
,
sizeof
(
content
),
body_template
,
config
::
ampel_name
(),
sensor
::
co2
,
sensor
::
temperature
,
snprintf_P
(
content
,
sizeof
(
content
),
body
1
_template
,
config
::
ampel_name
(),
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
,
sensor
::
timestamp
,
config
::
measurement_timestep
,
csv_writer
::
last_successful_write
,
config
::
csv_interval
,
csv_writer
::
getAvailableSpace
()
/
1024
,
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
,
config
::
mqtt_sending_interval
,
mqtt
::
last_successful_publish
,
config
::
mqtt_sending_interval
);
Serial
.
print
(
F
(
" - Body1 size : "
));
Serial
.
print
(
strlen
(
content
));
web_config
::
http
.
sendContent
(
content
);
snprintf_P
(
content
,
sizeof
(
content
),
body2_template
,
#if defined(ESP32)
lorawan
::
connected
?
"Yes"
:
"No"
,
config
::
lorawan_frequency_plan
,
lorawan
::
last_transmission
,
config
::
lorawan_sending_interval
,
...
...
@@ -219,7 +232,7 @@ namespace web_server {
esp_get_max_free_block_size
(),
esp_get_heap_fragmentation
(),
ampel
.
max_loop_duration
,
ampel
.
board
,
ampel
.
sensorId
,
ampel
.
version
,
dd
,
hh
,
mm
,
ss
);
Serial
.
print
(
F
(
" - Body size : "
));
Serial
.
print
(
F
(
" - Body
2
size : "
));
Serial
.
print
(
strlen
(
content
));
web_config
::
http
.
sendContent
(
content
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment