Skip to content
Snippets Groups Projects
Commit b4081328 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix non-mosquitto build

By moving mosquitto_will_set() call into mqtt_connect().

I'm still having the issue that the LWT is being published after mosquitto_disconnect(), even though I set the "force" parameter to false in the call to mqtt_loop_stop()
parent 731da454
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3479 passed
......@@ -295,6 +295,7 @@ int mqtt_connect(struct mqtt* mqtt, const char* bind_address)
return MQTT_FAILURE;
#ifdef USE_MOSQUITTO
char topic[128];
char* username = mqtt->cfg->mqtt.username;
char* password = mqtt->cfg->mqtt.password;
if(*username == '\0')
......@@ -303,6 +304,10 @@ int mqtt_connect(struct mqtt* mqtt, const char* bind_address)
password = NULL;
mosquitto_int_option(mqtt->handle, MOSQ_OPT_PROTOCOL_VERSION, mqtt->cfg->mqtt.protocol_version);
mosquitto_username_pw_set(mqtt->handle, username, password);
const char* value = "disconnected";
mosquitto_will_set(mqtt->handle
,mqtt_topic(mqtt, TOPIC_HOST, topic, sizeof(topic), "status")
,strlen(value), value, /* QOS: */2, /* retain: */true);
if(mqtt->cfg->mqtt.tls.mode == MQTT_TLS_CERT) {
char* certfile = NULL;
char* keyfile = NULL;
......@@ -368,7 +373,7 @@ int mqtt_thread_stop(struct mqtt* mqtt)
return MQTT_FAILURE;
#ifdef USE_MOSQUITTO
return mosquitto_loop_stop(mqtt->handle, /* force: */true);
return mosquitto_loop_stop(mqtt->handle, /* force: */false);
#else
return MQTT_FAILURE;
#endif
......
......@@ -1812,11 +1812,6 @@ int main(int argc, char** argv)
if(result != MQTT_SUCCESS) {
lprintf(LOG_ERR, "MQTT open failure: %d", result);
} else {
char topic[128];
p = "disconnected";
mosquitto_will_set(bbs_startup.mqtt.handle
,mqtt_topic(&bbs_startup.mqtt, TOPIC_HOST, topic, sizeof(topic), "status")
,strlen(p), p, /* QOS: */2, /* retain: */true);
lprintf(LOG_INFO, "MQTT connecting to broker %s:%u", scfg.mqtt.broker_addr, scfg.mqtt.broker_port);
result = mqtt_connect(&bbs_startup.mqtt, /* bind_address: */NULL);
if(result == MQTT_SUCCESS) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment