Mqtt: avoid crash when not configured

This commit is contained in:
Mathieu Maret 2016-04-10 01:59:37 +02:00
parent beae8b335b
commit 4cb6516b75

View File

@ -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;