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
aeacb867
Commit
aeacb867
authored
Feb 14, 2022
by
Eric Duminil
Browse files
No need to ask for password twice
parent
80e074fa
Pipeline
#5816
passed with stage
in 2 minutes and 41 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/web_server.cpp
View file @
aeacb867
...
...
@@ -169,9 +169,13 @@ namespace web_server {
web_config
::
http
.
on
(
"/delete_csv"
,
HTTP_POST
,
handleDeleteCSV
);
}
// Allow access if http_user or http_password are empty, or if provided credentials match
/*
* Allow access if Ampel is in access point mode,
* if http_user or http_password are empty,
* or if provided credentials match
*/
bool
shouldBeAllowed
()
{
return
strcmp
(
config
::
http_user
,
""
)
==
0
||
strcmp
(
config
::
ap_password
(),
""
)
==
0
return
wifi
::
isAccessPoint
()
||
strcmp
(
config
::
http_user
,
""
)
==
0
||
strcmp
(
config
::
ap_password
(),
""
)
==
0
||
web_config
::
http
.
authenticate
(
config
::
http_user
,
config
::
ap_password
());
}
...
...
@@ -196,8 +200,8 @@ namespace web_server {
snprintf_P
(
content
,
sizeof
(
content
),
header_template
,
sensor
::
co2
,
config
::
ampel_name
(),
wifi
::
local_ip
,
csv_writer
::
filename
);
Serial
.
print
(
F
(
"INFO - Header size : "
));
Serial
.
print
(
strlen
(
content
));
Serial
.
print
(
F
(
"INFO - Header size : "
));
Serial
.
print
(
strlen
(
content
));
web_config
::
http
.
setContentLength
(
CONTENT_LENGTH_UNKNOWN
);
web_config
::
http
.
send_P
(
200
,
PSTR
(
"text/html"
),
content
);
...
...
@@ -210,19 +214,20 @@ namespace web_server {
lorawan
::
connected
?
"Yes"
:
"No"
,
config
::
lorawan_frequency_plan
,
lorawan
::
last_transmission
,
config
::
lorawan_sending_interval
,
#endif
config
::
temperature_offset
,
config
::
auto_calibrate_sensor
?
"Yes"
:
"No"
,
config
::
ampel_name
(),
config
::
ampel_name
(),
wifi
::
local_ip
,
wifi
::
local_ip
,
ampel
.
macAddress
,
ESP
.
getFreeHeap
(),
esp_get_max_free_block_size
(),
esp_get_heap_fragmentation
(),
ampel
.
max_loop_duration
,
ampel
.
board
,
ampel
.
sensorId
,
ampel
.
version
,
dd
,
hh
,
mm
,
ss
);
config
::
temperature_offset
,
config
::
auto_calibrate_sensor
?
"Yes"
:
"No"
,
config
::
ampel_name
(),
config
::
ampel_name
(),
wifi
::
local_ip
,
wifi
::
local_ip
,
ampel
.
macAddress
,
ESP
.
getFreeHeap
(),
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
(
strlen
(
content
));
Serial
.
print
(
F
(
" - Body size : "
));
Serial
.
print
(
strlen
(
content
));
web_config
::
http
.
sendContent
(
content
);
// Script
snprintf_P
(
content
,
sizeof
(
content
),
script_template
,
csv_writer
::
filename
,
config
::
ampel_name
());
Serial
.
print
(
F
(
" - Script size : "
));
Serial
.
println
(
strlen
(
content
));
Serial
.
print
(
F
(
" - Script size : "
));
Serial
.
println
(
strlen
(
content
));
web_config
::
http
.
sendContent
(
content
);
}
...
...
ampel-firmware/wifi_util.cpp
View file @
aeacb867
...
...
@@ -19,6 +19,10 @@ namespace wifi {
return
WiFi
.
status
()
==
WL_CONNECTED
;
}
bool
isAccessPoint
()
{
return
WiFi
.
getMode
()
==
WIFI_AP
;
}
/*
* Connection attempt, called in blocking mode by setup(). This way, LED effects can be shown
* without needing callbacks, but only during wifi_timeout seconds.
...
...
@@ -31,7 +35,7 @@ namespace wifi {
void
tryConnection
()
{
for
(
int
i
=
0
;
i
<=
config
::
wifi_timeout
+
5
;
i
++
)
{
web_config
::
update
();
if
(
WiFi
.
getMode
()
==
WIFI_AP
)
{
if
(
isAccessPoint
())
{
led_effects
::
alert
(
0x1cff68
);
}
else
if
(
connected
())
{
break
;
...
...
ampel-firmware/wifi_util.h
View file @
aeacb867
...
...
@@ -5,6 +5,7 @@ namespace wifi {
extern
char
local_ip
[
16
];
void
defineCommands
();
bool
connected
();
bool
isAccessPoint
();
void
tryConnection
();
}
...
...
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