You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing an issue with the mqttClient.connected() command on MKR VIDOR 4000: it seems to freeze when the MQTT connection is broken.
I've been successfully using this command before on MKR1000, MKR GSM 1400, MKR NB 1500.
I've set up the code below so that you can reproduce. I've simulated a broken MQTT connection by turning my Wi-Fi access point off and on again.
#include<ArduinoMqttClient.h>
#include<WiFiNINA.h>
#include"arduino_secrets.h"/////// Enter your sensitive data in arduino_secrets.hconstchar wifi_ssid[] = SECRET_WIFI_SSID;
constchar wifi_pass[] = SECRET_WIFI_PASS;
constchar mqtt_broker[] = "test.mosquitto.org";
constint mqtt_port = 1883;
WiFiClient networkClient;
MqttClient mqttClient(networkClient);
voidsetup() {
Serial.begin(9600);
while (!Serial);
Serial.println();
mqttClient.setId("TestVIDOR");
}
voidloop() {
if (WiFi.status() != WL_CONNECTED) {
connectWiFi();
}
if (!mqttClient.connected()) {
connectMQTT();
}
mqttClient.poll();
}
voidconnectWiFi() {
Serial.print("Attempting to connect to SSID: ");
Serial.print(wifi_ssid);
while (WiFi.begin(wifi_ssid, wifi_pass) != WL_CONNECTED) {
// failed, retry
Serial.print(".");
delay(5000);
}
Serial.println();
Serial.println("You're connected to the network");
}
voidconnectMQTT() {
Serial.print("Attempting to connect to MQTT broker: ");
Serial.print(mqtt_broker);
while (!mqttClient.connected()) {
if (!mqttClient.connect(mqtt_broker, mqtt_port)) {
// failed, retry
Serial.print(".");
delay(5000);
}
}
Serial.println();
Serial.println("You're connected to the MQTT broker");
}
The VIDOR board reconnects to Wi-Fi and then freezes when it comes to MQTT:
22:29:20.066 -> Attempting to connect to SSID: Logan
22:29:25.711 -> You're connected to the network
22:29:25.711 -> Attempting to connect to MQTT broker: test.mosquitto.org
22:29:27.911 -> You're connected to the MQTT broker
// Wi-Fi interruption //
22:29:48.061 -> Attempting to connect to SSID: Logan.
22:29:59.894 -> You're connected to the network
// nothing else after //
On the other boards, the code reconnects instantly to the Wi-Fi and to the broker. This is the output for MKR1000 (just changed the Wi-Fi library to WiFi101.h):
22:35:11.458 -> Attempting to connect to SSID: Logan
22:35:13.013 -> You're connected to the network
22:35:13.013 -> Attempting to connect to MQTT broker: test.mosquitto.org
22:35:17.924 -> You're connected to the MQTT broker
// Wi-Fi interruption //
22:35:29.854 -> Attempting to connect to SSID: Logan..
22:35:42.733 -> You're connected to the network
22:35:42.733 -> Attempting to connect to MQTT broker: test.mosquitto.org
22:35:45.101 -> You're connected to the MQTT broker
The text was updated successfully, but these errors were encountered:
mdelain
changed the title
mqttClient.connected() is freezing on VIDOR when
mqttClient.connected() is freezing on VIDOR when MQTT connection drops
Jul 19, 2020
It seems this issue happens on MKR WIFI 1010 as well, most specifically if the MQTT server restarts.
My arduinos were all frozen for several days and I had no choice but to restart them. What I do notice as well is that the ".connected()" method seems to slow down the arduino in a random interval as well. The loop checks it every ~2 seconds and sometimes it just hangs for 10-20 seconds before resuming.
I don't believe power supply is an issue there as it seems to do it whether they're on a lab supply or on a solar panel's battery output.
I'm noticing the same issue on an Arduino Portenta H7 using GSM. I'm connecting and disconnecting the MQTTClient before/after each transmission, and after ~24 hours it freezes on MQTT.connect().
Hey there,
I'm facing an issue with the
mqttClient.connected()
command on MKR VIDOR 4000: it seems to freeze when the MQTT connection is broken.I've been successfully using this command before on MKR1000, MKR GSM 1400, MKR NB 1500.
I've set up the code below so that you can reproduce. I've simulated a broken MQTT connection by turning my Wi-Fi access point off and on again.
The VIDOR board reconnects to Wi-Fi and then freezes when it comes to MQTT:
On the other boards, the code reconnects instantly to the Wi-Fi and to the broker. This is the output for MKR1000 (just changed the Wi-Fi library to
WiFi101.h
):The text was updated successfully, but these errors were encountered: