Browse Source

mqtt: reduce debug log pressure, return result of mqttSend

master
Maxim Prokhorov 5 years ago
parent
commit
5e7f3c29bd
2 changed files with 21 additions and 12 deletions
  1. +2
    -2
      code/espurna/config/prototypes.h
  2. +19
    -10
      code/espurna/mqtt.ino

+ 2
- 2
code/espurna/config/prototypes.h View File

@ -204,8 +204,8 @@ String mqttTopic(const char * magnitude, unsigned int index, bool is_set);
String mqttMagnitude(char * topic); String mqttMagnitude(char * topic);
void mqttSendRaw(const char * topic, const char * message, bool retain);
void mqttSendRaw(const char * topic, const char * message);
bool mqttSendRaw(const char * topic, const char * message, bool retain);
bool mqttSendRaw(const char * topic, const char * message);
void mqttSend(const char * topic, const char * message, bool force, bool retain); void mqttSend(const char * topic, const char * message, bool force, bool retain);
void mqttSend(const char * topic, const char * message, bool force); void mqttSend(const char * topic, const char * message, bool force);


+ 19
- 10
code/espurna/mqtt.ino View File

@ -640,25 +640,34 @@ String mqttTopic(const char * magnitude, unsigned int index, bool is_set) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void mqttSendRaw(const char * topic, const char * message, bool retain) {
bool mqttSendRaw(const char * topic, const char * message, bool retain) {
if (_mqtt.connected()) {
if (!_mqtt.connected()) return false;
const unsigned int packetId(
#if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT #if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT
unsigned int packetId = _mqtt.publish(topic, _mqtt_qos, retain, message);
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s (PID %d)\n"), topic, message, packetId);
_mqtt.publish(topic, _mqtt_qos, retain, message)
#elif MQTT_LIBRARY == MQTT_LIBRARY_ARDUINOMQTT #elif MQTT_LIBRARY == MQTT_LIBRARY_ARDUINOMQTT
_mqtt.publish(topic, message, retain, _mqtt_qos);
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s\n"), topic, message);
_mqtt.publish(topic, message, retain, _mqtt_qos)
#elif MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT #elif MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT
_mqtt.publish(topic, message, retain);
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s\n"), topic, message);
_mqtt.publish(topic, message, retain)
#endif #endif
);
const size_t message_len = strlen(message);
if (message_len > 128) {
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => (%u bytes) (PID %u)\n"), topic, message_len, packetId);
} else {
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s (PID %u)\n"), topic, message, packetId);
} }
return (packetId > 0);
} }
void mqttSendRaw(const char * topic, const char * message) {
mqttSendRaw (topic, message, _mqtt_retain);
bool mqttSendRaw(const char * topic, const char * message) {
return mqttSendRaw (topic, message, _mqtt_retain);
} }
void mqttSend(const char * topic, const char * message, bool force, bool retain) { void mqttSend(const char * topic, const char * message, bool force, bool retain) {


Loading…
Cancel
Save