publishing results
This commit is contained in:
@ -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");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user