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
1a2aa6ff
Commit
1a2aa6ff
authored
Feb 10, 2022
by
Eric Duminil
Browse files
Some refactor
parent
1575b514
Pipeline
#5779
passed with stage
in 2 minutes and 7 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.h
View file @
1a2aa6ff
...
...
@@ -3,12 +3,10 @@
/*****************************************************************
* Libraries *
*****************************************************************/
#include
"config.h"
#ifndef MEASUREMENT_TIMESTEP
# error Missing config.h file. Please copy config.public.h to config.h.
#endif
//NOTE: Too many headers. Move them to include/ folder?
// Needed for offline config too.
#include
"config.h"
//TODO: Replace with just web_config
#include
"web_config.h"
#include
"csv_writer.h"
...
...
ampel-firmware/ampel-firmware.ino
View file @
1a2aa6ff
...
...
@@ -67,7 +67,7 @@ void setup() {
web_config
::
initialize
();
#ifdef AMPEL_WIFI
#ifdef AMPEL_WIFI
// TODO: What to do with those? Replace with webconf::wifi_active?
web_config
::
setWifiConnectionCallback
([]()
{
//TODO: Move somewhere else
led_effects
::
showKITTWheel
(
color
::
green
);
...
...
@@ -113,7 +113,7 @@ void setup() {
csv_writer
::
initialize
(
ampel
.
sensorId
);
#ifdef AMPEL_WIFI
// Structure doesn't make sense anymore
#ifdef AMPEL_WIFI
wifi
::
defineCommands
();
# ifdef AMPEL_HTTP
web_server
::
definePages
();
...
...
ampel-firmware/lorawan.cpp
View file @
1a2aa6ff
...
...
@@ -2,6 +2,7 @@
#if defined(ESP32)
#include
"config.h"
//TODO: Replace with just web_config
#include
"led_effects.h"
#include
"sensor_console.h"
#include
"util.h"
...
...
ampel-firmware/lorawan.h
View file @
1a2aa6ff
#ifndef AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_
#include
"config.h"
# if defined(ESP32)
#include
<stdint.h>
// For uint32_t & uint16_t
...
...
ampel-firmware/mqtt.cpp
View file @
1a2aa6ff
#include
"mqtt.h"
#include
"web_config.h"
#include
"config.h"
#include
"led_effects.h"
#include
"sensor_console.h"
#include
"wifi_util.h"
...
...
@@ -121,7 +120,7 @@ namespace mqtt {
Serial
.
print
(
F
(
"User:'"
));
Serial
.
print
(
config
::
mqtt_user
);
Serial
.
print
(
F
(
"' Password:'"
));
for
(
in
t
i
=
0
;
i
<
strlen
(
config
::
mqtt_password
);
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
strlen
(
config
::
mqtt_password
);
++
i
)
{
Serial
.
print
(
"*"
);
}
Serial
.
print
(
F
(
"' ..."
));
...
...
@@ -201,7 +200,7 @@ namespace mqtt {
char
payload
[
75
];
// Should be enough for info json...
const
char
*
json_info_format
=
PSTR
(
"{
\"
local_ip
\"
:
\"
%s
\"
,
\"
ssid
\"
:
\"
%s
\"
}"
);
snprintf
(
payload
,
sizeof
(
payload
),
json_info_format
,
wifi
::
local_ip
,
WIFI_SSID
);
snprintf
(
payload
,
sizeof
(
payload
),
json_info_format
,
wifi
::
local_ip
,
config
::
current_ssid
()
);
mqttClient
.
publish
(
info_topic
,
payload
);
}
...
...
ampel-firmware/mqtt.h
View file @
1a2aa6ff
...
...
@@ -3,8 +3,6 @@
#include
<stdint.h>
// For uint32_t & uint16_t
#include
"config.h"
namespace
mqtt
{
extern
char
last_successful_publish
[];
extern
bool
connected
;
...
...
ampel-firmware/util.h
View file @
1a2aa6ff
...
...
@@ -26,7 +26,7 @@ class Ampel {
private:
static
void
showFreeSpace
();
public:
const
char
*
version
=
"
v0.2.3
-DEV"
;
// Update manually after significant changes.
const
char
*
version
=
"
webconf
-DEV"
;
// Update manually after significant changes.
const
char
*
board
;
const
char
*
sensorId
;
const
char
*
macAddress
;
...
...
ampel-firmware/web_config.cpp
View file @
1a2aa6ff
...
...
@@ -7,6 +7,10 @@
#endif
#include
"config.h"
#ifndef MEASUREMENT_TIMESTEP
# error Missing config.h file. Please copy config.public.h to config.h.
#endif
#include
"util.h"
#include
"sensor_console.h"
...
...
@@ -268,6 +272,11 @@ namespace web_config {
* Define all the corresponding config values as reference, so that they can be updated.
*/
namespace
config
{
char
*
current_ssid
()
{
return
web_config
::
iotWebConf
->
getWifiSsidParameter
()
->
valueBuffer
;
}
// Sensor
uint16_t
&
measurement_timestep
=
web_config
::
timestepParam
.
value
();
// [s] Value between 2 and 1800 (range for SCD30 sensor).
uint16_t
&
altitude_above_sea_level
=
web_config
::
altitudeParam
.
value
();
// [m]
...
...
ampel-firmware/web_config.h
View file @
1a2aa6ff
...
...
@@ -10,6 +10,7 @@
#endif
namespace
config
{
char
*
current_ssid
();
// Sensor
extern
uint16_t
&
measurement_timestep
;
// [s] Value between 2 and 1800 (range for SCD30 sensor).
extern
uint16_t
&
altitude_above_sea_level
;
// [m]
...
...
ampel-firmware/web_server.cpp
View file @
1a2aa6ff
#include
"web_server.h"
#include
"web_config.h"
#include
"config.h"
#include
"config.h"
// TODO: Remove once HTTP_USER and HTTP_PASSWORD are in web_config
#include
"util.h"
#include
"ntp.h"
#include
"wifi_util.h"
...
...
@@ -96,16 +96,16 @@ namespace web_server {
"<tr><td>Humidity</td><td>%.1f%%</td></tr>
\n
"
"<tr><td>Last measurement</td><td>%s</td></tr>
\n
"
"<tr><td>Measurement timestep</td><td>%5d s</td></tr>
\n
"
"<tr><th colspan='2'>CSV</th></tr>
\n
"
"<tr><th colspan='2'>CSV</th></tr>
\n
"
//TODO: Gray out if !config::csv_active
"<tr><td>Last write</td><td>%s</td></tr>
\n
"
"<tr><td>Timestep</td><td>%5d s</td></tr>
\n
"
"<tr><td>Available drive space</td><td>%d kB</td></tr>
\n
"
"<tr><th colspan='2'>MQTT</th></tr>
\n
"
"<tr><th colspan='2'>MQTT</th></tr>
\n
"
//TODO: Gray out if !config::mqtt_active
"<tr><td>Connected?</td><td>%s</td></tr>
\n
"
"<tr><td>Last publish</td><td>%s</td></tr>
\n
"
"<tr><td>Timestep</td><td>%5d s</td></tr>
\n
"
#if defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>
\n
"
"<tr><th colspan='2'>LoRaWAN</th></tr>
\n
"
//TODO: Gray out if !config::lora_active
"<tr><td>Connected?</td><td>%s</td></tr>
\n
"
"<tr><td>Frequency</td><td>%s MHz</td></tr>
\n
"
"<tr><td>Last transmission</td><td>%s</td></tr>
\n
"
...
...
ampel-firmware/wifi_util.cpp
View file @
1a2aa6ff
#include
"wifi_util.h"
#include
"config.h"
#include
"
web_
config.h"
#include
"util.h"
#include
"ntp.h"
#include
"led_effects.h"
...
...
@@ -12,18 +12,6 @@
# include <WiFi.h>
#endif
namespace
config
{
// WiFi config. See 'config.h' if you want to modify those values.
const
char
*
wifi_ssid
=
WIFI_SSID
;
const
char
*
wifi_password
=
WIFI_PASSWORD
;
#ifdef WIFI_TIMEOUT
const
uint8_t
wifi_timeout
=
WIFI_TIMEOUT
;
// [s] Will try to connect during wifi_timeout seconds before failing.
#else
const
uint8_t
wifi_timeout
=
60
;
// [s] Will try to connect during wifi_timeout seconds before failing.
#endif
}
namespace
wifi
{
char
local_ip
[
16
];
// "255.255.255.255\0"
...
...
@@ -53,9 +41,9 @@ namespace wifi {
Serial
.
print
(
F
(
"WiFi - Local IP : "
));
Serial
.
println
(
wifi
::
local_ip
);
Serial
.
print
(
F
(
"WiFi - SSID : "
));
Serial
.
println
(
WIFI_SSID
);
Serial
.
println
(
config
::
current_ssid
()
);
}
void
defineCommands
()
{
sensor_console
::
defineCommand
(
"wifi_scan"
,
scanNetworks
,
F
(
"(Scans available WiFi networks)"
));
sensor_console
::
defineCommand
(
"local_ip"
,
showLocalIp
,
F
(
"(Displays local IP and current SSID)"
));
...
...
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