aqhome-nodes: send heartbeat message to interface every 2mins.

e02 now expects this message. If for at least 10mins no such msg is
received the USB interface is reset.
This commit is contained in:
Martin Preuss
2026-04-27 16:01:12 +02:00
parent a0360d5373
commit 0ac20ba82c
12 changed files with 217 additions and 26 deletions

View File

@@ -36,6 +36,7 @@
#define CONNCLEAN_INTERVAL_IN_SECS 2
#define CONNCHECK_INTERVAL_IN_SECS 10
#define HEARTBEAT_INTERVAL_IN_SECS 120 /* every 2mins */
@@ -133,11 +134,13 @@ void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop)
int timeout;
time_t timeLastConnectionCleanup;
time_t timeLastConnCheck;
time_t timeLastHeartbeat;
timeout=AQH_NodeServer_GetTimeout(aqh);
timeStart=time(NULL);
timeLastConnectionCleanup=time(NULL);
timeLastConnCheck=time(NULL);
timeLastConnectionCleanup=timeStart;
timeLastConnCheck=timeStart;
timeLastHeartbeat=timeStart;
while(!stopService) {
time_t now;
@@ -162,6 +165,13 @@ void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop)
timeLastConnCheck=now;
}
if (_diffInSeconds(now, timeLastHeartbeat)>HEARTBEAT_INTERVAL_IN_SECS) {
DBG_INFO(NULL, "Sending heartbeat message");
AQH_NodeServer_SendHeartbeat(aqh);
timeLastHeartbeat=now;
}
if (timeout && (_diffInSeconds(now, timeStart)>timeout)) {
DBG_INFO(NULL, "Timeout");
break;

View File

@@ -42,6 +42,7 @@
#include <aqhome/msg/node/m_recvstats.h>
#include <aqhome/msg/node/m_sendstats.h>
#include <aqhome/msg/node/m_memstats.h>
#include <aqhome/msg/node/m_heartbeat.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/args.h>
@@ -811,6 +812,25 @@ void AQH_NodeServer_HandleTtyMsgs(AQH_OBJECT *o)
void AQH_NodeServer_SendHeartbeat(AQH_OBJECT *o)
{
AQH_NODE_SERVER *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_NODE_SERVER, o);
if (xo && xo->ttyEndpoint) {
AQH_MESSAGE *nodeMsg;
time_t t;
t=time(0);
nodeMsg=AQH_HeartbeatMessage_new(0xf0, 0x00, AQH_MSG_TYPE_HEARTBEAT, (uint32_t) t);
AQH_Endpoint_AddMsgOut(xo->ttyEndpoint, nodeMsg);
AQH_NodeServer_WriteTtyMsgToLogFile(o, nodeMsg, "sending");
DBG_ERROR(NULL, "Forwarding node message %d to node", AQH_NodeMessage_GetMsgType(nodeMsg));
}
}
void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
{
uint8_t code;

View File

@@ -57,6 +57,7 @@ void AQH_NodeServer_HandleClientMsgs(AQH_OBJECT *o);
void AQH_NodeServer_HandleBrokerMsgs(AQH_OBJECT *o);
void AQH_NodeServer_CheckBrokerConnection(AQH_OBJECT *o);
void AQH_NodeServer_CheckTtyConnection(AQH_OBJECT *o);
void AQH_NodeServer_SendHeartbeat(AQH_OBJECT *o);
/* getters and setters */

View File

@@ -23,6 +23,7 @@
#include "aqhome/msg/msg_sysstats.h"
#include "aqhome/msg/msg_ping.h"
#include "aqhome/msg/msg_pong.h"
#include "aqhome/msg/m_heartbeat.h"
#include "aqhome/msg/msg_needaddr.h"
#include "aqhome/msg/msg_claimaddr.h"
#include "aqhome/msg/msg_haveaddr.h"
@@ -80,6 +81,7 @@ void AqHomed_LogTtyMsg(AQHOMED *aqh, const GWEN_MSG *msg)
switch(msgType) {
case AQH_MSG_TYPE_PING: AQH_PingMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_PONG: AQH_PongMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_HEARTBEAT: AQH_HeartbeatMessage_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_COMSENDSTATS: AQH_SendStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_COMRECVSTATS: AQH_RecvStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
case AQH_MSG_TYPE_TWIBUSMEMBER: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;