Skip to content

Commit 9e8d0cf

Browse files
committed
Merge pull request arduino#300 from tekka007/heartbeatfix
Heartbeat enhancement
2 parents aea6e74 + 56c9311 commit 9e8d0cf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

libraries/MySensors/core/MySensorCore.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces among other
2828
char _convBuf[MAX_PAYLOAD*2+1];
2929
#endif
3030

31-
uint16_t _heartbeat;
31+
uint32_t _heartbeat = 0;
3232
void (*_timeCallback)(unsigned long); // Callback for requested time messages
3333

3434

@@ -188,6 +188,8 @@ ControllerConfig getConfig() {
188188

189189

190190
boolean _sendRoute(MyMessage &message) {
191+
// increment heartbeat counter
192+
_heartbeat++;
191193
#if defined(MY_GATEWAY_FEATURE)
192194
if (message.destination == _nc.nodeId) {
193195
// This is a message sent from a sensor attached on the gateway node.
@@ -215,7 +217,7 @@ void sendBatteryLevel(uint8_t value, bool enableAck) {
215217
}
216218

217219
void sendHeartbeat(void) {
218-
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_HEARTBEAT_RESPONSE, false).set(_heartbeat++));
220+
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_HEARTBEAT_RESPONSE, false).set(_heartbeat));
219221

220222
}
221223

@@ -271,8 +273,7 @@ void _processInternalMessages() {
271273
presentation();
272274
}
273275
} else if (type == I_HEARTBEAT) {
274-
// Send heartbeat ack message back to sender (with the same payload)
275-
_sendRoute(build(_msg, _nc.nodeId, _msg.sender, _msg.sensor, C_INTERNAL, I_HEARTBEAT_RESPONSE, false).set(_heartbeat++));
276+
sendHeartbeat();
276277
} else if (type == I_TIME && receiveTime) {
277278
// Deliver time to callback
278279
if (receiveTime)

0 commit comments

Comments
 (0)