From 076c1f1b4d2d56e42afeb2e6710b078824606d0a Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 2 May 2021 04:31:53 +0200 Subject: [PATCH] Implement mqttEnabled --- src/mqtt/hasp_mqtt_paho_single.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index 5a40f762..816b4035 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -203,6 +203,8 @@ void mqtt_subscribe(void* context, const char* topic) int mqttPublish(const char* topic, const char* payload, size_t len, bool retain) { + if(!mqttEnabled) return MQTT_ERR_DISABLED; + if(!mqttIsConnected()) { mqttFailedCount++; return MQTT_ERR_NO_CONN; @@ -311,7 +313,9 @@ void mqttStart() // } printf("%s %d\n", __FILE__, __LINE__); - if(mqttServer.length() > 0) { + mqttEnabled = strlen(mqttServer) > 0 && mqttPort > 0; + + if(mqttEnabled) { conn_opts.will = &will_opts; conn_opts.will->message = "offline"; conn_opts.will->qos = 1;