Skip to content

Commit

Permalink
Use MQTT publish rather than enqueue to avoid missing messages on lar…
Browse files Browse the repository at this point in the history
…ge battery installs
  • Loading branch information
stuartpittaway committed Nov 28, 2023
1 parent c0c0d39 commit a3570a9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ESPController/src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ bool checkMQTTReady()
static inline void publish_message(std::string const &topic, std::string &payload, bool clear_payload = true)
{
static constexpr int MQTT_QUALITY_OF_SERVICE = 0;
static constexpr int MQTT_RETAIN_MESSAGE = 0;
static constexpr int MQTT_RETAIN_MESSAGE = 1;

if (mqtt_client != nullptr && mqttClient_connected)
{
int id = esp_mqtt_client_enqueue(mqtt_client, topic.c_str(),
int id=esp_mqtt_client_publish(mqtt_client, topic.c_str(),
payload.c_str(), payload.length(),MQTT_QUALITY_OF_SERVICE, MQTT_RETAIN_MESSAGE);

/*int id = esp_mqtt_client_enqueue(mqtt_client, topic.c_str(),
payload.c_str(), payload.length(),
MQTT_QUALITY_OF_SERVICE, MQTT_RETAIN_MESSAGE, true);

*/
if (id < 0)
{
ESP_LOGE(TAG, "Topic:%s, failed publish", topic.c_str());
Expand Down

0 comments on commit a3570a9

Please sign in to comment.