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
a79fc50f
Commit
a79fc50f
authored
Mar 05, 2022
by
Eric Duminil
Browse files
Some refactor
parent
accc8d0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
a79fc50f
...
...
@@ -30,8 +30,6 @@ const char wifiInitialApPassword[] = "smrtTHNG8266";
// -- Method declarations.
void
handleRoot
();
// -- Callback methods.
void
configSaved
();
DNSServer
dnsServer
;
WebServer
server
(
80
);
...
...
@@ -94,55 +92,34 @@ iotwebconf::TimeTParameter timeParam =
defaultValue
(
""
).
build
();
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
();
Serial
.
println
(
"Starting up..."
);
group1
.
addItem
(
&
intParam
);
group2
.
addItem
(
&
floatParam
);
group2
.
addItem
(
&
checkboxParam
);
group2
.
addItem
(
&
chooserParam
);
group2
.
addItem
(
&
colorParam
);
group2
.
addItem
(
&
dateParam
);
group2
.
addItem
(
&
timeParam
);
iotWebConf
.
addSystemParameter
(
&
stringParam
);
iotWebConf
.
addParameterGroup
(
&
group1
);
iotWebConf
.
addParameterGroup
(
&
group2
);
iotWebConf
.
setConfigSavedCallback
(
&
configSaved
);
iotWebConf
.
getApTimeoutParameter
()
->
visible
=
true
;
// -- Initializing the configuration.
iotWebConf
.
init
();
// -- Set up required URL handlers on the web server.
server
.
on
(
"/"
,
handleRoot
);
server
.
on
(
"/config"
,
[]{
iotWebConf
.
handleConfig
();
});
server
.
onNotFound
([](){
iotWebConf
.
handleNotFound
();
});
void
defineConsoleCommands
()
{
sensor_console
::
defineCommand
(
"reset"
,
[]()
{
ESP
.
restart
();
},
F
(
"(Restarts the ESP)"
));
sensor_console
::
defineCommand
(
"reset"
,
[](){
ESP
.
restart
();
},
F
(
"(Restarts the ESP)"
));
sensor_console
::
defineCommand
(
"save_config"
,
[]()
{
iotWebConf
.
saveConfig
();
},
F
(
"(Saves the config to EEPROM)"
));
sensor_console
::
defineCommand
(
"save_config"
,
[](){
iotWebConf
.
saveConfig
();
},
F
(
"(Saves the config to EEPROM)"
));
sensor_console
::
defineCommand
(
"reset_config"
,
[]()
{
Serial
.
println
(
F
(
"Resetting config..."
));
iotWebConf
.
getRootParameterGroup
()
->
applyDefaultValue
();
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
);
strlcpy
(
iotWebConf
.
getWifiSsidParameter
()
->
valueBuffer
,
ssid
,
iotWebConf
.
getWifiSsidParameter
()
->
getLength
());
},
F
(
"name (Sets SSID to name)"
));
sensor_console
::
defineStringCommand
(
"wifi_pwd"
,
[](
char
*
pwd
)
{
Serial
.
print
(
F
(
"Setting WiFi password to "
));
Serial
.
println
(
pwd
);
strlcpy
(
iotWebConf
.
getWifiPasswordParameter
()
->
valueBuffer
,
pwd
,
iotWebConf
.
getWifiPasswordParameter
()
->
getLength
());
},
F
(
"abc (Sets WiFi password to abc)"
));
},
F
(
"name (Sets SSID to name)"
));
sensor_console
::
defineStringCommand
(
"wifi_pwd"
,
[](
char
*
pwd
)
{
Serial
.
print
(
F
(
"Setting WiFi password to "
));
Serial
.
println
(
pwd
);
strlcpy
(
iotWebConf
.
getWifiPasswordParameter
()
->
valueBuffer
,
pwd
,
iotWebConf
.
getWifiPasswordParameter
()
->
getLength
());
},
F
(
"abc (Sets WiFi password to abc)"
));
sensor_console
::
defineStringCommand
(
"ap_pwd"
,
[](
char
*
pwd
)
{
Serial
.
print
(
F
(
"Setting AP password to "
));
...
...
@@ -150,6 +127,12 @@ void setup()
strlcpy
(
iotWebConf
.
getApPasswordParameter
()
->
valueBuffer
,
pwd
,
iotWebConf
.
getApPasswordParameter
()
->
getLength
());
},
F
(
"abc (Sets AP password to abc)"
));
sensor_console
::
defineStringCommand
(
"name"
,
[](
char
*
name
)
{
Serial
.
print
(
F
(
"Setting Thing name to "
));
Serial
.
println
(
name
);
strlcpy
(
iotWebConf
.
getThingNameParameter
()
->
valueBuffer
,
name
,
iotWebConf
.
getThingNameParameter
()
->
getLength
());
},
F
(
"abc (Sets AP password to abc)"
));
sensor_console
::
defineIntCommand
(
"ap"
,
[](
int
onOff
)
{
if
(
onOff
)
{
Serial
.
print
(
F
(
"Enable "
));
...
...
@@ -162,19 +145,43 @@ void setup()
sensor_console
::
defineIntCommand
(
"wifi"
,
[](
int
onOff
)
{
if
(
onOff
)
{
Serial
.
print
(
F
(
"Enable "
));
Serial
.
print
(
F
(
"Enable
Wifi!
"
));
iotWebConf
.
goOnLine
();
}
else
{
Serial
.
print
(
F
(
"Disable "
));
Serial
.
print
(
F
(
"Disable
Wifi!
"
));
iotWebConf
.
goOffLine
();
}
Serial
.
println
(
F
(
"Wifi!"
));
},
F
(
"0/1 (Enables/disables WiFi)"
));
//TODO: Remove fluff
//TODO: Add wifi on/off?
}
Serial
.
println
(
"Ready."
);
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
();
Serial
.
println
(
"Starting up..."
);
group1
.
addItem
(
&
intParam
);
group2
.
addItem
(
&
floatParam
);
group2
.
addItem
(
&
checkboxParam
);
group2
.
addItem
(
&
chooserParam
);
group2
.
addItem
(
&
colorParam
);
group2
.
addItem
(
&
dateParam
);
group2
.
addItem
(
&
timeParam
);
iotWebConf
.
addSystemParameter
(
&
stringParam
);
iotWebConf
.
addParameterGroup
(
&
group1
);
iotWebConf
.
addParameterGroup
(
&
group2
);
// -- Initializing the configuration.
iotWebConf
.
init
();
// -- Set up required URL handlers on the web server.
server
.
on
(
"/"
,
handleRoot
);
server
.
on
(
"/config"
,
[]{
iotWebConf
.
handleConfig
();
});
server
.
onNotFound
([](){
iotWebConf
.
handleNotFound
();
});
defineConsoleCommands
();
Serial
.
println
(
F
(
"Ready."
));
}
void
loop
()
...
...
@@ -224,11 +231,6 @@ void handleRoot()
server
.
send
(
200
,
"text/html"
,
s
);
}
void
configSaved
()
{
Serial
.
println
(
"Configuration was updated."
);
}
/***
* Sensor console
*/
...
...
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