From b065b733f7ba55696361d2c977380c069dfbf623 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 29 Mar 2023 22:02:55 +0200 Subject: [PATCH] mqtt: publish messages for recv stats. --- aqhome/mqtt/endpoint_mqttc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/aqhome/mqtt/endpoint_mqttc.c b/aqhome/mqtt/endpoint_mqttc.c index 599c458..72ce605 100644 --- a/aqhome/mqtt/endpoint_mqttc.c +++ b/aqhome/mqtt/endpoint_mqttc.c @@ -19,6 +19,7 @@ #include "aqhome/msg/msg_node.h" #include "aqhome/msg/msg_value2.h" #include "aqhome/msg/msg_sendstats.h" +#include "aqhome/msg/msg_recvstats.h" #include #include @@ -40,6 +41,7 @@ static void _checkForConnAckMsg(GWEN_MSG_ENDPOINT *ep); static void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg); static void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg); static void _processSendStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg); +static void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg); static void _publishDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v); static void _publishInt(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, int v); static void _publishString(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, const char *v); @@ -273,6 +275,9 @@ void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg) case AQH_MSG_TYPE_COMSENDSTATS: _processSendStatsMessage(ep, nodeMsg); break; + case AQH_MSG_TYPE_COMRECVSTATS: + _processRecvStatsMessage(ep, nodeMsg); + break; default: break; } @@ -321,6 +326,34 @@ void _processSendStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg) +void _processRecvStatsMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg) +{ + uint16_t packetsInInt; + + packetsInInt=AQH_RecvStatsMsg_GetPacketsIn(nodeMsg); + if (packetsInInt) { + double packetsIn; + double errors; + double handled; + double errorsPercentage=0.0; + double handledPercentage=0.0; + + packetsIn=(double) packetsInInt; + errors=(double)AQH_RecvStatsMsg_GetErrors(nodeMsg); + handled=(double)AQH_RecvStatsMsg_GetHandled(nodeMsg); + + errorsPercentage=errors*100.0/packetsIn; + handledPercentage=handled*100.0/packetsIn; + + _publishInt(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/packetsIn", packetsInInt); + _publishInt(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/errors", (int) AQH_RecvStatsMsg_GetErrors(nodeMsg)); + _publishDouble(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/errorsPercent", errorsPercentage); + _publishDouble(ep, AQH_RecvStatsMsg_GetUid(nodeMsg), 0, "net/handledPercent", handledPercentage); + } +} + + + void _publishDouble(GWEN_MSG_ENDPOINT *ep, uint32_t uid, int valueId, const char *valuePath, double v) { char numBuf[16];