publishing results
This commit is contained in:
parent
5714d3f6ed
commit
5e4f9063e1
@ -3,6 +3,9 @@
|
||||
|
||||
|
||||
void mqttCommInit();
|
||||
void mqttPublish(char *topic, char *message);
|
||||
void mqttPublishf(char *topic, char *messageFormat, ...);
|
||||
|
||||
|
||||
|
||||
#endif // _MQTTCOMM_H_
|
||||
|
@ -14,11 +14,12 @@
|
||||
#include <frontend.h>
|
||||
#include <wizHelper.h>
|
||||
#include <mbusParserExt.h>
|
||||
|
||||
#include <mqttComm.h>
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
|
||||
|
||||
static const char MBUS_TOPIC[] = "IoT/MBGW3/Measurement";
|
||||
|
||||
static const uint8_t MBUS_QUERY_CMD = 0x5b;
|
||||
|
||||
@ -201,6 +202,8 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
|
||||
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] Error ratio is %.2f",
|
||||
localMbusCommHandle->requestId,
|
||||
errorRatio);
|
||||
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"ErrorRatio\":\"%.2f\"}",
|
||||
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName, errorRatio);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", localMbusCommHandle->requestId);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
extern const uint8_t MQTT_SOCK;
|
||||
|
||||
@ -133,10 +133,26 @@ void mqttCommInit() {
|
||||
}
|
||||
|
||||
void mqttPublish(char *topic, char *message) {
|
||||
bool res = publish(&mqttClient, topic, message, strlen(message), false);
|
||||
bool res = false;
|
||||
if (isNetworkAvailable()) {
|
||||
res = publish(&mqttClient, topic, message, strlen(message), false);
|
||||
}
|
||||
if (res) {
|
||||
coloredMsg(LOG_GREEN, false, "mqp: %s -> %s successfully published", message, topic);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mqp: %s -> %s failed to publish", message, topic);
|
||||
}
|
||||
}
|
||||
|
||||
void mqttPublishf(char *topic, char *messageFormat, ...) {
|
||||
va_list vl;
|
||||
va_start(vl, messageFormat);
|
||||
char buf[2048];
|
||||
int res = vsnprintf(buf, sizeof(buf), messageFormat, vl);
|
||||
va_end(vl);
|
||||
if (res < sizeof(buf)) {
|
||||
mqttPublish(topic, buf);
|
||||
} else {
|
||||
coloredMsg(LOG_RED, true, "mqc mpf buffer overflow, truncated message not published");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user