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
63f78eea
Commit
63f78eea
authored
May 15, 2021
by
Eric Duminil
Browse files
Trying to use a config
parent
56f99df8
Changes
3
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
63f78eea
...
...
@@ -112,6 +112,9 @@ void setup() {
sensor
::
initialize
();
Serial
.
print
(
"JUST A CONFIG TEST : "
);
Serial
.
println
(
config
::
stringParam
.
value
());
#ifdef AMPEL_CSV
csv_writer
::
initialize
(
ampel
.
sensorId
);
#endif
...
...
ampel-firmware/web_config.cpp
View file @
63f78eea
#include "web_config.h"
namespace
config
{
iotwebconf
::
TextTParameter
<
STRING_LEN
>
stringParam
=
iotwebconf
::
Builder
<
iotwebconf
::
TextTParameter
<
STRING_LEN
>>
(
"stringParam"
).
label
(
"String param"
).
build
();
}
namespace
web_config
{
#if defined(ESP8266)
ESP8266WebServer
http
(
80
);
// Create a webserver object that listens for HTTP request on port 80
...
...
@@ -11,16 +16,12 @@ namespace web_config {
IotWebConf
*
iotWebConf
;
#define STRING_LEN 64
// -- Configuration specific key. The value should be modified if config structure was changed.
const
char
config_version
[]
=
"ampel_test_v3"
;
static
const
char
chooserValues
[][
STRING_LEN
]
=
{
"red"
,
"blue"
,
"darkYellow"
};
static
const
char
chooserNames
[][
STRING_LEN
]
=
{
"Red"
,
"Blue"
,
"Dark yellow"
};
iotwebconf
::
TextTParameter
<
STRING_LEN
>
stringParam
=
iotwebconf
::
Builder
<
iotwebconf
::
TextTParameter
<
STRING_LEN
>>
(
"stringParam"
).
label
(
"String param"
).
build
();
iotwebconf
::
ParameterGroup
group1
=
iotwebconf
::
ParameterGroup
(
"group1"
,
""
);
iotwebconf
::
IntTParameter
<
int16_t
>
intParam
=
iotwebconf
::
Builder
<
iotwebconf
::
IntTParameter
<
int16_t
>>
(
"intParam"
).
label
(
"Int param"
).
defaultValue
(
30
).
min
(
1
).
max
(
...
...
@@ -54,6 +55,27 @@ namespace web_config {
void
initialize
()
{
iotWebConf
=
new
IotWebConf
(
ampel
.
sensorId
,
&
dnsServer
,
&
http
,
HTTP_PASSWORD
,
config_version
);
group1
.
addItem
(
&
intParam
);
group2
.
addItem
(
&
floatParam
);
group2
.
addItem
(
&
checkboxParam
);
group2
.
addItem
(
&
chooserParam
);
iotWebConf
->
addSystemParameter
(
&
config
::
stringParam
);
iotWebConf
->
addParameterGroup
(
&
group1
);
iotWebConf
->
addParameterGroup
(
&
group2
);
sensor_console
::
defineCommand
(
"reset_config"
,
[]()
{
Serial
.
println
(
F
(
"Resetting config..."
));
iotWebConf
->
getSystemParameterGroup
()
->
applyDefaultValue
();
iotWebConf
->
saveConfig
();
Serial
.
println
(
F
(
"Done!"
));
},
F
(
"(resets the complete IotWeb config)"
));
#if !defined(AMPEL_WIFI)
iotWebConf
->
loadConfig
();
return
;
#endif
const
int
ONBOARD_LED_PIN
=
2
;
# ifdef ESP8266
iotWebConf
->
setStatusPin
(
ONBOARD_LED_PIN
,
LOW
);
...
...
@@ -63,20 +85,11 @@ namespace web_config {
iotWebConf
->
setWifiConnectionTimeoutMs
(
1000UL
*
WIFI_TIMEOUT
);
#if defined(ESP8266)
WiFi
.
hostname
(
ampel
.
sensorId
);
WiFi
.
hostname
(
ampel
.
sensorId
);
#elif defined(ESP32)
WiFi
.
setHostname
(
ampel
.
sensorId
);
#endif
group1
.
addItem
(
&
intParam
);
group2
.
addItem
(
&
floatParam
);
group2
.
addItem
(
&
checkboxParam
);
group2
.
addItem
(
&
chooserParam
);
iotWebConf
->
addSystemParameter
(
&
stringParam
);
iotWebConf
->
addParameterGroup
(
&
group1
);
iotWebConf
->
addParameterGroup
(
&
group2
);
iotWebConf
->
skipApStartup
();
//TODO: Add callbacks
//TODO: Add LED effects
...
...
@@ -89,23 +102,7 @@ namespace web_config {
//TODO: Save LoRaWAN key if possible?
//FIXME: Why does MQTT fail? (on ESP32)
// iotWebConf->loadConfig();
Serial
.
println
(
"<<<<<<<<<<<<<<<"
);
Serial
.
println
(
stringParam
.
value
());
Serial
.
println
(
intParam
.
value
());
Serial
.
println
(
floatParam
.
value
());
iotWebConf
->
init
();
Serial
.
println
(
stringParam
.
value
());
Serial
.
println
(
intParam
.
value
());
Serial
.
println
(
floatParam
.
value
());
Serial
.
println
(
">>>>>>>>>>>>>>>"
);
sensor_console
::
defineCommand
(
"reset_config"
,
[]()
{
Serial
.
println
(
F
(
"Resetting config..."
));
iotWebConf
->
getSystemParameterGroup
()
->
applyDefaultValue
();
iotWebConf
->
saveConfig
();
Serial
.
println
(
F
(
"Done!"
));
},
F
(
"(resets the complete IotWeb config)"
));
//TODO: Authenticate only if required?
//TODO: / captive fast return?
...
...
ampel-firmware/web_config.h
View file @
63f78eea
...
...
@@ -7,6 +7,8 @@
# include <WebServer.h>
#endif
#define STRING_LEN 64
//#include "config.h"
#include <IotWebConf.h>
...
...
@@ -15,6 +17,10 @@
#include "util.h"
//#include "sensor_console.h"
namespace
config
{
extern
iotwebconf
::
TextTParameter
<
STRING_LEN
>
stringParam
;
}
namespace
web_config
{
void
initialize
();
void
setWifiConnectionCallback
(
void
(
*
function
)());
...
...
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