MQTT Client Retain Feature (#793)
Optionally allow MQTT client to publish specific messages with the retain flag set. default/current behavior should not be impacted.
This commit is contained in:
@@ -805,6 +805,12 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def MY_MQTT_CLIENT_PUBLISH_RETAIN
|
||||
* @brief Enables MQTT client to set the retain flag when publishing specific messages.
|
||||
*/
|
||||
//#define MY_MQTT_CLIENT_PUBLISH_RETAIN
|
||||
|
||||
// Static ip address of gateway (if this is disabled, DHCP will be used)
|
||||
//#define MY_IP_ADDRESS 192,168,178,66
|
||||
|
||||
@@ -982,4 +988,5 @@
|
||||
#define MY_RFM95_ATC_MODE_DISABLED
|
||||
#define MY_RFM95_RST_PIN
|
||||
#define MY_INDICATION_HANDLER
|
||||
#define MY_MQTT_CLIENT_PUBLISH_RETAIN
|
||||
#endif
|
||||
|
||||
@@ -56,7 +56,13 @@ bool gatewayTransportSend(MyMessage &message)
|
||||
setIndication(INDICATION_GW_TX);
|
||||
char *topic = protocolFormatMQTTTopic(MY_MQTT_PUBLISH_TOPIC_PREFIX, message);
|
||||
debug(PSTR("Sending message on topic: %s\n"), topic);
|
||||
return _MQTT_client.publish(topic, message.getString(_convBuffer));
|
||||
#ifdef MY_MQTT_CLIENT_PUBLISH_RETAIN
|
||||
bool retain = mGetCommand(message) == C_SET ||
|
||||
(mGetCommand(message) == C_INTERNAL && message.type == I_BATTERY_LEVEL);
|
||||
#else
|
||||
bool retain = false;
|
||||
#endif
|
||||
return _MQTT_client.publish(topic, message.getString(_convBuffer), retain);
|
||||
}
|
||||
|
||||
void incomingMQTT(char* topic, uint8_t* payload, unsigned int length)
|
||||
|
||||
@@ -130,6 +130,7 @@ MY_W5100_SPI_EN LITERAL1
|
||||
MY_MQTT_SUBSCRIBE_TOPIC_PREFIX LITERAL1
|
||||
MY_MQTT_PUBLISH_TOPIC_PREFIX LITERAL1
|
||||
MY_MQTT_CLIENT_ID LITERAL1
|
||||
MY_MQTT_CLIENT_PUBLISH_RETAIN LITERAL1
|
||||
MY_GATEWAY_MQTT_CLIENT LITERAL1
|
||||
MY_DISABLE_REMOTE_RESET LITERAL1
|
||||
MY_RS485_DE_PIN LITERAL1
|
||||
|
||||
Reference in New Issue
Block a user