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
00750138
Commit
00750138
authored
Feb 17, 2022
by
Eric Duminil
Browse files
Defining ssid and password via console
parent
ac8ed954
Pipeline
#5865
passed with stage
in 2 minutes and 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/sensor_console.cpp
View file @
00750138
#include
"sensor_console.h"
namespace
sensor_console
{
const
uint8_t
MAX_COMMANDS
=
2
5
;
const
uint8_t
MAX_COMMANDS
=
2
6
;
const
uint8_t
MAX_COMMAND_SIZE
=
20
;
// Should be enough for "set_time 1618829570\n"
uint8_t
commands_count
=
0
;
...
...
ampel-firmware/web_config.cpp
View file @
00750138
...
...
@@ -164,10 +164,7 @@ namespace web_config {
iotWebConf
->
setWifiConnectionFailedHandler
(
fail_and_return_null
);
}
void
initialize
()
{
iotWebConf
=
new
IotWebConf
(
strlen
(
AMPEL_NAME
)
==
0
?
ampel
.
sensorId
:
AMPEL_NAME
,
&
dnsServer
,
&
http
,
""
,
config_version
);
void
defineStructure
()
{
iotWebConf
->
setHtmlFormatProvider
(
&
optionalGroupHtmlFormatProvider
);
iotWebConf
->
addSystemParameter
(
&
ampelWifiParam
);
...
...
@@ -219,10 +216,9 @@ namespace web_config {
#if defined(ESP32)
iotWebConf
->
addParameterGroup
(
&
loraParams
);
#endif
}
//TODO: Add "ap" command?
//TODO: Add "wifi_ssid" command?
//TODO: Add "wifi_password" command?
void
defineCommands
()
{
sensor_console
::
defineCommand
(
"save_config"
,
config
::
save
,
F
(
"(Saves the config to EEPROM)"
));
sensor_console
::
defineCommand
(
"reset_config"
,
[]()
{
...
...
@@ -232,12 +228,35 @@ namespace web_config {
Serial
.
println
(
F
(
"Done!"
));
},
F
(
"(Resets the complete IotWeb config)"
));
sensor_console
::
defineStringCommand
(
"ssid"
,
[](
char
*
ssid
)
{
Serial
.
print
(
F
(
"Setting WiFi ssid to "
));
Serial
.
println
(
ssid
);
strncpy
(
iotWebConf
->
getWifiSsidParameter
()
->
valueBuffer
,
ssid
,
iotWebConf
->
getWifiSsidParameter
()
->
getLength
());
iotWebConf
->
saveConfig
();
},
F
(
" name (Sets SSID to name)"
));
sensor_console
::
defineStringCommand
(
"pwd"
,
[](
char
*
ssid
)
{
Serial
.
print
(
F
(
"Setting WiFi password to "
));
Serial
.
println
(
ssid
);
strncpy
(
iotWebConf
->
getWifiPasswordParameter
()
->
valueBuffer
,
ssid
,
iotWebConf
->
getWifiPasswordParameter
()
->
getLength
());
iotWebConf
->
saveConfig
();
},
F
(
" abc (Sets WiFi password to abc)"
));
sensor_console
::
defineIntCommand
(
"wifi"
,
[](
int32_t
onOff
)
{
config
::
is_wifi_on
=
onOff
;
iotWebConf
->
saveConfig
();
Serial
.
print
(
F
(
"WiFi - "
));
Serial
.
println
(
onOff
?
F
(
"On!"
)
:
F
(
"Off!"
));
},
F
(
"0/1 (Turns Wifi on/off)"
));
}
void
initialize
()
{
iotWebConf
=
new
IotWebConf
(
strlen
(
AMPEL_NAME
)
==
0
?
ampel
.
sensorId
:
AMPEL_NAME
,
&
dnsServer
,
&
http
,
""
,
config_version
);
defineStructure
();
defineCommands
();
iotWebConf
->
loadConfig
();
...
...
@@ -246,6 +265,12 @@ namespace web_config {
return
;
}
//NOTE: Can only work if wifi is on.
sensor_console
::
defineCommand
(
"ap!"
,
[]()
{
Serial
.
println
(
F
(
"Forcing AP mode!"
));
iotWebConf
->
forceApMode
(
true
);
},
F
(
"(Forces access point mode)"
));
const
int
ONBOARD_LED_PIN
=
2
;
# ifdef ESP8266
iotWebConf
->
setStatusPin
(
ONBOARD_LED_PIN
,
LOW
);
...
...
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