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
78d53f38
Commit
78d53f38
authored
Feb 09, 2022
by
Eric Duminil
Browse files
Not sending MQTT if inactive
parent
afa49c20
Pipeline
#5772
passed with stage
in 2 minutes and 8 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.h
View file @
78d53f38
...
...
@@ -11,15 +11,11 @@
// Needed for offline config too.
#include
"web_config.h"
#ifdef AMPEL_CSV
# include "csv_writer.h"
#endif
#include
"csv_writer.h"
#ifdef AMPEL_WIFI
# include "wifi_util.h"
# ifdef AMPEL_MQTT
# include "mqtt.h"
# endif
# include "mqtt.h"
# ifdef AMPEL_HTTP
# include "web_server.h"
# endif
...
...
ampel-firmware/ampel-firmware.ino
View file @
78d53f38
...
...
@@ -79,9 +79,9 @@ void setup() {
ntp
::
initialize
();
#
if
def AMPEL_MQTT
mqtt
::
initialize
(
ampel
.
sensorId
);
# endif
if
(
config
::
mqtt_active
())
{
mqtt
::
initialize
(
ampel
.
sensorId
);
}
Serial
.
print
(
F
(
"You can access this sensor via http://"
));
Serial
.
print
(
ampel
.
sensorId
);
...
...
@@ -166,8 +166,10 @@ void loop() {
csv_writer
::
logIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
#if defined(AMPEL_WIFI) && defined(AMPEL_MQTT)
mqtt
::
publishIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#if defined(AMPEL_WIFI)
if
(
config
::
mqtt_active
())
{
mqtt
::
publishIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
}
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
...
...
@@ -220,9 +222,9 @@ void keepServicesAlive() {
web_config
::
update
();
if
(
wifi
::
connected
())
{
ntp
::
update
();
// NTP client has its own timer. It will connect to NTP server every 60s.
#
if
def AMPEL_MQTT
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
# endif
if
(
config
::
mqtt_active
())
{
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
}
}
#endif
}
ampel-firmware/mqtt.cpp
View file @
78d53f38
...
...
@@ -42,8 +42,6 @@ namespace mqtt {
char
last_successful_publish
[
23
]
=
""
;
void
initialize
(
const
char
*
sensorId
)
{
Serial
.
print
(
"MQTT ? "
);
Serial
.
println
(
config
::
mqtt_active
());
json_sensor_format
=
PSTR
(
"{
\"
time
\"
:
\"
%s
\"
,
\"
co2
\"
:%d,
\"
temp
\"
:%.1f,
\"
rh
\"
:%.1f}"
);
snprintf
(
publish_topic
,
sizeof
(
publish_topic
),
"CO2sensors/%s"
,
sensorId
);
#if MQTT_ENCRYPTED
...
...
ampel-firmware/util.h
View file @
78d53f38
...
...
@@ -8,7 +8,7 @@
# define esp_get_heap_fragmentation() ESP.getHeapFragmentation()
#elif defined(ESP32)
# define esp_get_max_free_block_size() ESP.getMaxAllocHeap() //largest block of heap that can be allocated.
# define esp_get_heap_fragmentation()
"?"
// apparently not available for ESP32
# define esp_get_heap_fragmentation()
-1
// apparently not available for ESP32
#endif
namespace
util
{
...
...
ampel-firmware/web_server.cpp
View file @
78d53f38
...
...
@@ -10,9 +10,7 @@
#ifdef AMPEL_CSV
# include "csv_writer.h"
#endif
#ifdef AMPEL_MQTT
# include "mqtt.h"
#endif
#include
"mqtt.h"
#ifdef AMPEL_LORAWAN
# include "lorawan.h"
#endif
...
...
@@ -112,12 +110,10 @@ namespace web_server {
"<tr><td>Timestep</td><td>%5d s</td></tr>
\n
"
"<tr><td>Available drive space</td><td>%d kB</td></tr>
\n
"
#endif
#ifdef AMPEL_MQTT
"<tr><th colspan='2'>MQTT</th></tr>
\n
"
"<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
"
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>
\n
"
"<tr><td>Connected?</td><td>%s</td></tr>
\n
"
...
...
@@ -249,9 +245,7 @@ namespace web_server {
#ifdef AMPEL_CSV
csv_writer
::
last_successful_write
,
config
::
csv_interval
,
csv_writer
::
getAvailableSpace
()
/
1024
,
#endif
#ifdef AMPEL_MQTT
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
,
config
::
mqtt_sending_interval
,
#endif
#if defined(AMPEL_LORAWAN) && 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