Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
d6dbd593
Commit
d6dbd593
authored
May 14, 2021
by
Eric Duminil
Browse files
Let's see what happens
parent
e1f32748
Changes
2
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
d6dbd593
...
...
@@ -86,26 +86,9 @@ void setup() {
#endif
#ifdef AMPEL_WIFI
wifi
::
connect
(
ampel
.
sensorId
);
if
(
wifi
::
connected
())
{
# ifdef AMPEL_HTTP
web_server
::
initialize
();
web_server
::
initialize
();
# endif
ntp
::
initialize
();
if
(
MDNS
.
begin
(
ampel
.
sensorId
))
{
// Start the mDNS responder for SENSOR_ID.local
MDNS
.
addService
(
"http"
,
"tcp"
,
80
);
Serial
.
println
(
F
(
"mDNS responder started"
));
}
else
{
Serial
.
println
(
F
(
"Error setting up MDNS responder!"
));
}
# ifdef AMPEL_MQTT
mqtt
::
initialize
(
ampel
.
sensorId
);
# endif
}
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
...
...
@@ -200,19 +183,8 @@ void checkFlashButton() {
void
keepServicesAlive
()
{
#ifdef AMPEL_WIFI
if
(
wifi
::
connected
())
{
# if defined(ESP8266)
//NOTE: Sadly, there seems to be a bug in the current MDNS implementation.
// It stops working after 2 minutes. And forcing a restart leads to a memory leak.
MDNS
.
update
();
# endif
ntp
::
update
();
// NTP client has its own timer. It will connect to NTP server every 60s.
# ifdef AMPEL_HTTP
web_server
::
update
();
web_server
::
update
();
# endif
# ifdef AMPEL_MQTT
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
# endif
}
#endif
}
ampel-firmware/web_server.cpp
View file @
d6dbd593
...
...
@@ -21,6 +21,7 @@
#ifdef AMPEL_LORAWAN
# include "lorawan.h"
#endif
#include <IotWebConf.h>
namespace
config
{
// Values should be defined in config.h
...
...
@@ -57,11 +58,24 @@ namespace web_server {
WebServer
http
(
80
);
#endif
// -- Initial name of the Thing. Used e.g. as SSID of the own Access Point.
const
char
thingName
[]
=
"ampel_wifi"
;
// -- Initial password to connect to the Thing, when it creates an own Access Point.
const
char
wifiInitialApPassword
[]
=
"12345678"
;
DNSServer
dnsServer
;
IotWebConf
iotWebConf
(
thingName
,
&
dnsServer
,
&
http
,
wifiInitialApPassword
);
void
update
()
{
http
.
handleClient
();
// Listen for HTTP requests from clients
iotWebConf
.
doLoop
();
// http.handleClient(); // Listen for HTTP requests from clients
}
void
initialize
()
{
iotWebConf
.
init
();
header_template
=
PSTR
(
"<!doctype html><html lang=en>"
"<head>
\n
"
...
...
@@ -205,8 +219,15 @@ namespace web_server {
http
.
on
(
csv_writer
::
filename
,
handleWebServerCSV
);
//NOTE: csv_writer should have been initialized first.
http
.
on
(
"/delete_csv"
,
HTTP_POST
,
handleDeleteCSV
);
#endif
http
.
onNotFound
(
handlePageNotFound
);
http
.
begin
();
http
.
on
(
"/config"
,
[]
{
iotWebConf
.
handleConfig
();
});
http
.
onNotFound
([]()
{
iotWebConf
.
handleNotFound
();
});
// http.begin();
Serial
.
print
(
F
(
"You can access this sensor via http://"
));
Serial
.
print
(
ampel
.
sensorId
);
...
...
@@ -221,6 +242,11 @@ namespace web_server {
}
void
handleWebServerRoot
()
{
// -- Let IotWebConf test and handle captive portal requests.
if
(
iotWebConf
.
handleCaptivePortal
())
{
// -- Captive portal request were already served.
return
;
}
if
(
!
shouldBeAllowed
())
{
return
http
.
requestAuthentication
(
DIGEST_AUTH
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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