Mqtt: avoid crash when not configured
This commit is contained in:
parent
beae8b335b
commit
4cb6516b75
@ -76,8 +76,9 @@ Adafruit_MQTT_Publish *MqttCreatePublisher(const char *fmt, ...){
|
|||||||
bool MqttIsConfigured() {
|
bool MqttIsConfigured() {
|
||||||
return isMqttConfigured;
|
return isMqttConfigured;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MqttIsConnected() {
|
int MqttIsConnected() {
|
||||||
return mqtt->connected();
|
return (mqtt != NULL) ? mqtt->connected() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to connect and reconnect as necessary to the MQTT server.
|
// Function to connect and reconnect as necessary to the MQTT server.
|
||||||
@ -85,6 +86,9 @@ int MqttIsConnected() {
|
|||||||
int MqttConnect() {
|
int MqttConnect() {
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
|
|
||||||
|
if(!isMqttConfigured)
|
||||||
|
return -1;
|
||||||
|
|
||||||
// Stop if already connected.
|
// Stop if already connected.
|
||||||
if (mqtt->connected()) {
|
if (mqtt->connected()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user