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
d5a75fa2
Commit
d5a75fa2
authored
Feb 14, 2022
by
Eric Duminil
Browse files
Config renaming
parent
aeacb867
Changes
6
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
d5a75fa2
...
...
@@ -91,7 +91,7 @@ void setup() {
csv_writer
::
initialize
(
config
::
ampel_name
());
if
(
config
::
wifi_
active
)
{
if
(
config
::
is_
wifi_
on
)
{
wifi
::
defineCommands
();
web_server
::
definePages
();
wifi
::
tryConnection
();
...
...
@@ -131,11 +131,11 @@ void loop() {
checkSerialInput
();
if
(
sensor
::
processData
())
{
if
(
config
::
csv_active
())
{
if
(
config
::
is_
csv_active
())
{
csv_writer
::
logIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
}
if
(
config
::
wifi_
active
&&
config
::
mqtt_active
())
{
if
(
config
::
is_
wifi_
on
&&
config
::
is_
mqtt_active
())
{
mqtt
::
publishIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
}
...
...
@@ -168,7 +168,7 @@ void wifiConnected() {
ntp
::
initialize
();
if
(
config
::
mqtt_active
())
{
if
(
config
::
is_
mqtt_active
())
{
mqtt
::
initialize
(
ampel
.
sensorId
);
}
...
...
@@ -221,11 +221,11 @@ void checkFlashButton() {
}
void
keepServicesAlive
()
{
if
(
config
::
wifi_
active
)
{
if
(
config
::
is_
wifi_
on
)
{
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
())
{
if
(
config
::
is_
mqtt_active
())
{
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
}
}
...
...
ampel-firmware/csv_writer.cpp
View file @
d5a75fa2
...
...
@@ -162,7 +162,7 @@ namespace csv_writer {
void
logIfTimeHasCome
(
const
char
*
timeStamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
)
{
unsigned
long
now
=
seconds
();
if
(
now
-
last_written_at
>
config
::
csv_
interval
)
{
if
(
now
-
last_written_at
>
config
::
csv_
timestep
)
{
last_written_at
=
now
;
log
(
timeStamp
,
co2
,
temperature
,
humidity
);
}
...
...
@@ -172,9 +172,9 @@ namespace csv_writer {
* Callbacks for sensor commands *
*****************************************************************/
void
setCSVinterval
(
int32_t
csv_interval
)
{
config
::
csv_
interval
=
csv_interval
;
config
::
csv_
timestep
=
csv_interval
;
Serial
.
print
(
F
(
"Setting CSV Interval to : "
));
Serial
.
print
(
config
::
csv_
interval
);
Serial
.
print
(
config
::
csv_
timestep
);
Serial
.
println
(
"s."
);
config
::
save
();
led_effects
::
showKITTWheel
(
color
::
green
,
1
);
...
...
ampel-firmware/mqtt.cpp
View file @
d5a75fa2
...
...
@@ -166,7 +166,7 @@ namespace mqtt {
void
publishIfTimeHasCome
(
const
char
*
timestamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
)
{
// Send message via MQTT according to sending interval
unsigned
long
now
=
seconds
();
if
(
now
-
last_sent_at
>
config
::
mqtt_sending_
interval
)
{
if
(
now
-
last_sent_at
>
config
::
mqtt_sending_
timestep
)
{
last_sent_at
=
now
;
publish
(
timestamp
,
co2
,
temp
,
hum
);
}
...
...
@@ -184,9 +184,9 @@ namespace mqtt {
* Callbacks for sensor commands *
*****************************************************************/
void
setMQTTinterval
(
int32_t
sending_interval
)
{
config
::
mqtt_sending_
interval
=
sending_interval
;
config
::
mqtt_sending_
timestep
=
sending_interval
;
Serial
.
print
(
F
(
"Setting MQTT sending interval to : "
));
Serial
.
print
(
config
::
mqtt_sending_
interval
);
Serial
.
print
(
config
::
mqtt_sending_
timestep
);
Serial
.
println
(
"s."
);
config
::
save
();
led_effects
::
showKITTWheel
(
color
::
green
,
1
);
...
...
ampel-firmware/web_config.cpp
View file @
d5a75fa2
...
...
@@ -237,7 +237,7 @@ namespace web_config {
},
F
(
"(resets the complete IotWeb config)"
));
sensor_console
::
defineIntCommand
(
"wifi"
,
[](
int32_t
onOff
)
{
config
::
wifi_
active
=
onOff
;
config
::
is_
wifi_
on
=
onOff
;
iotWebConf
->
saveConfig
();
Serial
.
print
(
F
(
"WiFi - "
));
Serial
.
println
(
onOff
?
F
(
"On!"
)
:
F
(
"Off!"
));
...
...
@@ -245,7 +245,7 @@ namespace web_config {
iotWebConf
->
loadConfig
();
if
(
!
config
::
wifi_
active
)
{
if
(
!
config
::
is_
wifi_
on
)
{
Serial
.
println
(
F
(
"Wifi is off : no access point or connection. Use 'wifi 1' to turn on again!"
));
return
;
}
...
...
@@ -297,7 +297,7 @@ namespace config {
return
web_config
::
iotWebConf
->
getWifiSsidParameter
()
->
valueBuffer
;
}
char
*
a
p
_password
()
{
char
*
a
mpel
_password
()
{
return
web_config
::
iotWebConf
->
getApPasswordParameter
()
->
valueBuffer
;
}
...
...
@@ -308,7 +308,7 @@ 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
();
bool
&
is_
wifi_
on
=
web_config
::
ampelWifiParam
.
value
();
uint16_t
&
wifi_timeout
=
web_config
::
wifiTimeoutParam
.
value
();
void
save
()
{
web_config
::
iotWebConf
->
saveConfig
();
...
...
@@ -325,20 +325,20 @@ namespace config {
bool
&
daylight_saving_time
=
web_config
::
dstParam
.
value
();
// CSV
bool
csv_active
()
{
bool
is_
csv_active
()
{
return
web_config
::
csvParams
.
isActive
();
}
uint16_t
&
csv_
interval
=
web_config
::
csvTimestepParam
.
value
();
uint16_t
&
csv_
timestep
=
web_config
::
csvTimestepParam
.
value
();
// MQTT
bool
mqtt_active
()
{
bool
is_
mqtt_active
()
{
return
web_config
::
mqttParams
.
isActive
();
}
char
*
mqtt_server
=
web_config
::
mqttServerParam
.
value
();
char
*
mqtt_user
=
web_config
::
mqttUserParam
.
value
();
char
*
mqtt_password
=
web_config
::
mqttPasswordParam
.
value
();
uint16_t
&
mqtt_port
=
web_config
::
mqttPortParam
.
value
();
uint16_t
&
mqtt_sending_
interval
=
web_config
::
mqttTimestepParam
.
value
();
uint16_t
&
mqtt_sending_
timestep
=
web_config
::
mqttTimestepParam
.
value
();
bool
&
mqtt_encryption
=
web_config
::
mqttEncryptionParam
.
value
();
bool
&
allow_mqtt_commands
=
web_config
::
mqttCommandsParam
.
value
();
...
...
ampel-firmware/web_config.h
View file @
d5a75fa2
...
...
@@ -13,8 +13,8 @@ namespace config {
char
*
ampel_name
();
// WiFi
char
*
selected_ssid
();
char
*
a
p
_password
();
extern
bool
&
wifi_
active
;
// [true / false]
char
*
a
mpel
_password
();
// For Access Point, and for HTML page
extern
bool
&
is_
wifi_
on
;
// [true / false]
extern
uint16_t
&
wifi_timeout
;
// [s]
// Sensor
...
...
@@ -35,16 +35,16 @@ namespace config {
extern
bool
&
daylight_saving_time
;
// [true / false]
//CSV
bool
csv_active
();
//
TODO: Find better names?
extern
uint16_t
&
csv_
interval
;
// [s]
bool
is_
csv_active
();
//
[true / false]
extern
uint16_t
&
csv_
timestep
;
// [s]
// MQTT
bool
mqtt_active
();
bool
is_
mqtt_active
();
// [true / false]
extern
char
*
mqtt_server
;
extern
char
*
mqtt_user
;
extern
char
*
mqtt_password
;
extern
uint16_t
&
mqtt_port
;
extern
uint16_t
&
mqtt_sending_
interval
;
// [s]
extern
uint16_t
&
mqtt_sending_
timestep
;
// [s]
extern
bool
&
mqtt_encryption
;
// [true / false]
extern
bool
&
allow_mqtt_commands
;
// [true / false]
...
...
ampel-firmware/web_server.cpp
View file @
d5a75fa2
...
...
@@ -175,8 +175,8 @@ namespace web_server {
* or if provided credentials match
*/
bool
shouldBeAllowed
()
{
return
wifi
::
isAccessPoint
()
||
strcmp
(
config
::
http_user
,
""
)
==
0
||
strcmp
(
config
::
a
p
_password
(),
""
)
==
0
||
web_config
::
http
.
authenticate
(
config
::
http_user
,
config
::
a
p
_password
());
return
wifi
::
isAccessPoint
()
||
strcmp
(
config
::
http_user
,
""
)
==
0
||
strcmp
(
config
::
a
mpel
_password
(),
""
)
==
0
||
web_config
::
http
.
authenticate
(
config
::
http_user
,
config
::
a
mpel
_password
());
}
void
handleWebServerRoot
()
{
...
...
@@ -208,8 +208,8 @@ namespace web_server {
// Body
snprintf_P
(
content
,
sizeof
(
content
),
body_template
,
config
::
ampel_name
(),
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
,
sensor
::
timestamp
,
config
::
measurement_timestep
,
csv_writer
::
last_successful_write
,
config
::
csv_
interval
,
csv_writer
::
getAvailableSpace
()
/
1024
,
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
,
config
::
mqtt_sending_
interval
,
config
::
csv_
timestep
,
csv_writer
::
getAvailableSpace
()
/
1024
,
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
,
config
::
mqtt_sending_
timestep
,
#if defined(ESP32)
lorawan
::
connected
?
"Yes"
:
"No"
,
config
::
lorawan_frequency_plan
,
lorawan
::
last_transmission
,
config
::
lorawan_sending_interval
,
...
...
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