Skip to content

Commit

Permalink
Fixed crash when calling idbSend from an MQTT callback (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Jan 21, 2018
1 parent b1542f1 commit a662083
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 2 additions & 4 deletions code/espurna/mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,8 @@ void _mqttCallback(unsigned int type, const char * topic, const char * payload)
// Subscribe to internal action topics
mqttSubscribe(MQTT_TOPIC_ACTION);

// Send heartbeat messages
#if HEARTBEAT_ENABLED
heartbeat();
#endif
// Flag system to send heartbeat
systemSendHeartbeat();

}

Expand Down
8 changes: 7 additions & 1 deletion code/espurna/system.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------

unsigned long _loopDelay = 0;
bool _system_send_heartbeat = false;

// -----------------------------------------------------------------------------

Expand Down Expand Up @@ -58,6 +59,10 @@ void systemCheckLoop() {

// -----------------------------------------------------------------------------

void systemSendHeartbeat() {
_system_send_heartbeat = true;
}

void systemLoop() {

// Check system stability
Expand All @@ -68,7 +73,8 @@ void systemLoop() {
#if HEARTBEAT_ENABLED
// Heartbeat
static unsigned long last = 0;
if ((last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) {
if (_system_send_heartbeat || (last == 0) || (millis() - last > HEARTBEAT_INTERVAL)) {
_system_send_heartbeat = false;
last = millis();
heartbeat();
}
Expand Down

0 comments on commit a662083

Please sign in to comment.