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
d1200037
Commit
d1200037
authored
Feb 11, 2022
by
Eric Duminil
Browse files
Turn wifi on/off
parent
01724c50
Pipeline
#5787
passed with stage
in 2 minutes and 24 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.h
View file @
d1200037
...
...
@@ -11,12 +11,10 @@
#include
"csv_writer.h"
#ifdef AMPEL_WIFI
# include "wifi_util.h"
# include "mqtt.h"
# ifdef AMPEL_HTTP
# include "web_server.h"
# endif
#include
"wifi_util.h"
#include
"mqtt.h"
#ifdef AMPEL_HTTP
# include "web_server.h"
#endif
#include
"lorawan.h"
...
...
ampel-firmware/ampel-firmware.ino
View file @
d1200037
...
...
@@ -72,35 +72,35 @@ void setup() {
web_config
::
initialize
();
#ifdef AMPEL_WIFI // TODO: What to do with those? Replace with web
conf::wifi_active
?
web_config
::
setWifiConnectionCallback
([]()
{
//TODO: Move somewhere else
led_effects
::
showKITTWheel
(
color
::
green
);
Serial
.
println
();
Serial
.
print
(
F
(
"WiFi - Connected! IP address: "
));
IPAddress
address
=
WiFi
.
localIP
();
snprintf
(
wifi
::
local_ip
,
sizeof
(
wifi
::
local_ip
),
"%d.%d.%d.%d"
,
address
[
0
],
address
[
1
],
address
[
2
],
address
[
3
]);
Serial
.
println
(
wifi
::
local_ip
);
ntp
::
initialize
();
if
(
config
::
mqtt_active
())
{
mqtt
::
initialize
(
ampel
.
sensorId
);
}
if
(
conf
ig
::
wifi_active
)
{
web_config
::
setWifiConnectionCallback
([]()
{
//TODO: Move somewhere else
led_effects
::
showKITTWheel
(
color
::
green
);
Serial
.
println
();
Serial
.
print
(
F
(
"WiFi - Connected! IP address: "
));
IPAddress
address
=
WiFi
.
localIP
();
snprintf
(
wifi
::
local_ip
,
sizeof
(
wifi
::
local_ip
),
"%d.%d.%d.%d"
,
address
[
0
],
address
[
1
],
address
[
2
],
address
[
3
]);
Serial
.
println
(
wifi
::
local_ip
);
ntp
::
initialize
();
if
(
config
::
mqtt_active
())
{
mqtt
::
initialize
(
ampel
.
sensorId
);
}
Serial
.
print
(
F
(
"You can access this sensor via http://"
));
Serial
.
print
(
ampel
.
sensorId
);
Serial
.
print
(
F
(
".local (might be unstable) or http://"
));
Serial
.
println
(
WiFi
.
localIP
());
});
Serial
.
print
(
F
(
"You can access this sensor via http://"
));
Serial
.
print
(
ampel
.
sensorId
);
Serial
.
print
(
F
(
".local (might be unstable) or http://"
));
Serial
.
println
(
WiFi
.
localIP
());
});
web_config
::
setWifiFailCallback
(
failedConnection
);
web_config
::
setWifiFailCallback
(
failedConnection
);
// web_config::setWifiConnectionFailedCallback([]() {
// led_effects::showKITTWheel(color::red);
// Serial.println(F("Connection to WiFi failed"));
// });
#endif
}
pinMode
(
0
,
INPUT
);
// Flash button (used for forced calibration)
...
...
@@ -120,14 +120,14 @@ void setup() {
csv_writer
::
initialize
(
ampel
.
sensorId
);
#ifdef AMPEL_WIFI
wifi
::
defineCommands
();
if
(
config
::
wifi_active
)
{
wifi
::
defineCommands
();
# ifdef AMPEL_HTTP
web_server
::
definePages
();
//TODO: Rename. Not just web_server
// web_server::initialize();
web_server
::
definePages
();
//TODO: Rename. Not just web_server
// web_server::initialize();
# endif
#endif
}
#if defined(ESP32)
if
(
config
::
lorawan_active
())
{
...
...
@@ -175,11 +175,9 @@ void loop() {
csv_writer
::
logIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
}
#if defined(AMPEL_WIFI)
if
(
config
::
mqtt_active
())
{
if
(
config
::
wifi_active
&&
config
::
mqtt_active
())
{
mqtt
::
publishIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
}
#endif
#if defined(ESP32)
if
(
config
::
lorawan_active
())
{
...
...
@@ -229,13 +227,13 @@ void checkFlashButton() {
}
void
keepServicesAlive
()
{
#ifdef AMPEL_WIFI
web_config
::
update
();
if
(
wifi
::
connected
())
{
ntp
::
update
();
// NTP client has its own timer. It will connect to NTP server every 60s.
if
(
config
::
mqtt_active
())
{
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
if
(
config
::
wifi_active
)
{
web_config
::
update
();
if
(
wifi
::
connected
())
{
ntp
::
update
();
// NTP client has its own timer. It will connect to NTP server every 60s.
if
(
config
::
mqtt_active
())
{
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
}
}
}
#endif
}
ampel-firmware/web_config.cpp
View file @
d1200037
...
...
@@ -228,10 +228,19 @@ namespace web_config {
Serial
.
println
(
F
(
"Done!"
));
},
F
(
"(resets the complete IotWeb config)"
));
#if !defined(AMPEL_WIFI)
sensor_console
::
defineIntCommand
(
"wifi"
,
[](
int32_t
onOff
)
{
config
::
wifi_active
=
onOff
;
iotWebConf
->
saveConfig
();
Serial
.
print
(
F
(
"WiFi - "
));
Serial
.
println
(
onOff
?
F
(
"On!"
)
:
F
(
"Off!"
));
},
F
(
"0/1 (Wifi On?)"
));
iotWebConf
->
loadConfig
();
return
;
#endif
if
(
!
config
::
wifi_active
)
{
Serial
.
println
(
F
(
"Wifi is off : no access point or connection. Use 'wifi 1' to turn on again!"
));
return
;
}
const
int
ONBOARD_LED_PIN
=
2
;
# ifdef ESP8266
...
...
@@ -251,12 +260,6 @@ namespace web_config {
//TODO: Remove AP Password config?
//TODO: Save LoRaWAN key if possible?
Serial
.
print
(
"WIFI ? : "
);
Serial
.
println
(
ampelWifiParam
.
value
());
iotWebConf
->
loadConfig
();
Serial
.
print
(
"WIFI ? : "
);
Serial
.
println
(
ampelWifiParam
.
value
());
iotWebConf
->
init
();
//TODO: Authenticate only if required?
...
...
@@ -288,6 +291,8 @@ namespace config {
bool
&
auto_calibrate_sensor
=
web_config
::
autoCalibrateParam
.
value
();
// [true / false]
float
&
temperature_offset
=
web_config
::
temperatureOffsetParam
.
value
();
// [K] Sign isn't relevant.
bool
&
wifi_active
=
web_config
::
ampelWifiParam
.
value
();
// LEDs
uint8_t
&
max_brightness
=
web_config
::
maxBrightnessParam
.
value
();
uint8_t
&
min_brightness
=
web_config
::
minBrightnessParam
.
value
();
...
...
ampel-firmware/web_config.h
View file @
d1200037
...
...
@@ -18,6 +18,8 @@ namespace config {
extern
bool
&
auto_calibrate_sensor
;
// [true / false]
extern
float
&
temperature_offset
;
// [K] Sign isn't relevant.
extern
bool
&
wifi_active
;
// [true / false]
// LED
extern
uint8_t
&
max_brightness
;
extern
uint8_t
&
min_brightness
;
...
...
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