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() {
|
||||
return isMqttConfigured;
|
||||
}
|
||||
|
||||
int MqttIsConnected() {
|
||||
return mqtt->connected();
|
||||
return (mqtt != NULL) ? mqtt->connected() : 0;
|
||||
}
|
||||
|
||||
// Function to connect and reconnect as necessary to the MQTT server.
|
||||
@ -85,6 +86,9 @@ int MqttIsConnected() {
|
||||
int MqttConnect() {
|
||||
int8_t ret;
|
||||
|
||||
if(!isMqttConfigured)
|
||||
return -1;
|
||||
|
||||
// Stop if already connected.
|
||||
if (mqtt->connected()) {
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user