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
36230378
Commit
36230378
authored
Apr 18, 2021
by
Eric Duminil
Browse files
MQTT sending interval, for consistency
parent
0c4e9f87
Pipeline
#2829
passed with stage
in 1 minute and 40 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/mqtt.cpp
View file @
36230378
...
...
@@ -2,7 +2,7 @@
namespace
config
{
// Values should be defined in config.h
uint16_t
sending_interval
=
MQTT_SENDING_INTERVAL
;
// [s]
uint16_t
mqtt_
sending_interval
=
MQTT_SENDING_INTERVAL
;
// [s]
//INFO: Listen to every CO2 sensor which is connected to the server:
// mosquitto_sub -h MQTT_SERVER -t 'CO2sensors/#' -p 443 --capath /etc/ssl/certs/ -u "MQTT_USER" -P "MQTT_PASSWORD" -v
const
char
*
mqtt_server
=
MQTT_SERVER
;
...
...
@@ -123,7 +123,7 @@ namespace mqtt {
void
publishIfTimeHasCome
(
const
String
&
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
::
sending_interval
)
{
if
(
now
-
last_sent_at
>
config
::
mqtt_
sending_interval
)
{
last_sent_at
=
now
;
publish
(
timeStamp
,
co2
,
temp
,
hum
);
}
...
...
@@ -141,9 +141,9 @@ namespace mqtt {
* Callbacks for sensor commands *
*****************************************************************/
void
setMQTTinterval
(
int32_t
sending_interval
)
{
config
::
sending_interval
=
sending_interval
;
config
::
mqtt_
sending_interval
=
sending_interval
;
Serial
.
print
(
F
(
"Setting MQTT sending interval to : "
));
Serial
.
print
(
config
::
sending_interval
);
Serial
.
print
(
config
::
mqtt_
sending_interval
);
Serial
.
println
(
"s."
);
led_effects
::
showKITTWheel
(
color
::
green
,
1
);
}
...
...
ampel-firmware/mqtt.h
View file @
36230378
...
...
@@ -8,7 +8,7 @@
#include
"src/lib/PubSubClient/src/PubSubClient.h"
#include
"wifi_util.h"
namespace
config
{
extern
uint16_t
sending_interval
;
// [s]
extern
uint16_t
mqtt_
sending_interval
;
// [s]
}
namespace
mqtt
{
extern
String
last_successful_publish
;
...
...
ampel-firmware/web_server.cpp
View file @
36230378
...
...
@@ -230,7 +230,7 @@ namespace web_server {
csv_writer
::
last_successful_write
.
c_str
(),
config
::
csv_interval
,
csv_writer
::
getAvailableSpace
()
/
1024
,
#endif
#ifdef AMPEL_MQTT
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
.
c_str
(),
config
::
sending_interval
,
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
.
c_str
(),
config
::
mqtt_
sending_interval
,
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan
::
connected
?
"Yes"
:
"No"
,
LMIC_FREQUENCY_PLAN
,
lorawan
::
last_transmission
.
c_str
(),
...
...
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