From a662083abd53d069dce155da711dfd307c01ae49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 21 Jan 2018 09:30:13 +0100 Subject: [PATCH] Fixed crash when calling idbSend from an MQTT callback (#410) --- code/espurna/mqtt.ino | 6 ++---- code/espurna/system.ino | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 2f3b402d..51b15ae8 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -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(); } diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 8f21c75e..5002c26d 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -11,6 +11,7 @@ Copyright (C) 2018 by Xose PĂ©rez // ----------------------------------------------------------------------------- unsigned long _loopDelay = 0; +bool _system_send_heartbeat = false; // ----------------------------------------------------------------------------- @@ -58,6 +59,10 @@ void systemCheckLoop() { // ----------------------------------------------------------------------------- +void systemSendHeartbeat() { + _system_send_heartbeat = true; +} + void systemLoop() { // Check system stability @@ -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(); }