aqhomed, aqhome: added MQTT endpoint, publish value changes via MQTT.

This commit is contained in:
Martin Preuss
2023-03-29 16:46:32 +02:00
parent bf4451f3f4
commit 5d5446ad90
8 changed files with 538 additions and 24 deletions

View File

@@ -21,7 +21,9 @@
#include "aqhome/msg/msg_claimaddr.h"
#include "aqhome/msg/msg_haveaddr.h"
#include "aqhome/msg/msg_device.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include <gwenhywfar/endpoint_tcpc.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
@@ -35,6 +37,7 @@ static void _loopOnceOverEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr);
static void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep);
static void _handleNodeMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _handleIpcMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _handleMqttMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _handleMsgValue2(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _handleMsgNeedAddress(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
static void _handleMsgClaimAddress(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg);
@@ -99,7 +102,15 @@ void _loopOnceOverEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr)
ep=GWEN_MsgEndpoint_List_First(endpointList);
while(ep) {
_handleEndpoint(emgr, ep);
if (GWEN_MsgEndpoint_GetGroupId(ep) & AQH_MSGMGR_ENDPOINTGROUP_MQTT) {
if (GWEN_TcpcEndpoint_GetState(ep)>=GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED)
_handleEndpoint(emgr, ep);
else {
DBG_INFO(AQH_LOGDOMAIN, "Not handling MQTT endpoint right now (not fully connected)");
}
}
else
_handleEndpoint(emgr, ep);
ep=GWEN_MsgEndpoint_List_Next(ep);
} /* while */
}
@@ -127,6 +138,7 @@ void _handleEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep)
switch(groupId) {
case AQH_MSGMGR_ENDPOINTGROUP_NODE: _handleNodeMsg(emgr, ep, msg); break;
case AQH_MSGMGR_ENDPOINTGROUP_IPC: _handleIpcMsg(emgr, ep, msg); break;
case AQH_MSGMGR_ENDPOINTGROUP_MQTT: _handleMqttMsg(emgr, ep, msg); break;
default:
DBG_ERROR(AQH_LOGDOMAIN, "unhandled groupId %d (%02x), ignoring message", groupId, groupId);
break;
@@ -176,6 +188,13 @@ void _handleIpcMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWE
void _handleMqttMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
/* exec MQTT message */
}
void _handleMsgValue2(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
{
AQH_MSG_MANAGER *xmgr;