Go Down

Topic: Arduino Cloud mqtt stuck ? (Read 2907 times) previous topic - next topic

benjenq

Mar 09, 2017, 08:56 am Last Edit: Mar 10, 2017, 10:49 am by benjenq Reason: issue fixed.
I try to use Esp8266 to connect to Arduino Cloud.
Everything work yesterday, but it stuck today.

Please reference my code, it stuck at "Connecting to mqtt broker..." and doesn't finish poll() action.

Any idea?


Here is my code (has remove DHT11 library):

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoCloud.h>

char ssid[] = "...";
char pass[] = "...";
WiFiClientSecure  clientSSL;

unsigned long theTime;

//(A)rduino (C)loud (T)hing
const char acUserName[]   = "benjenq";
const char acthingName[]  = "myArduinoThing1";
const char acthingId[]    = "xxxx";
const char acthingPsw[]   = "xxxx";

// build a new object "Arduino cloud Thing Object"
ArduinoCloudThing acObject;

void setup() {
 // put your setup code here, to run once:

 Serial.begin(115200);
 theTime = millis();
 startWifi();


 Serial.println("Start Arduino Cloud thing property...");
 //Arduino Cloud
 acObject.enableDebug(); // eneble the serial debug output
 acObject.begin(acthingName, acUserName, acthingId, acthingPsw, clientSSL);
 // define the properties
 acObject.addProperty("temperatureCelsius", INT , R);
 acObject.addProperty("humidity", INT , R);
 acObject.addProperty("rssi", INT , R);
 Serial.println("Finish Arduino Cloud thing property...");

}

void loop() {
 // put your main code here, to run repeatedly:
 startWifi();

 if (millis() - theTime > 5000) {
   theTime = millis();
   Serial.println("Test Arduino Cloud Thing before poll()...");
   acObject.poll();
   Serial.println("Test Arduino Cloud Thing after poll()...");
 }

}

void startWifi() {
 if (WiFi.status() != WL_CONNECTED) {
   WiFi.begin(ssid, pass);
 }
 else {
   return;
 }

 int i = 0;
 while (WiFi.status() != WL_CONNECTED && i < 20) {
   Serial.print(".");
   i++;
   delay(500);
 }

 if (WiFi.status() != WL_CONNECTED) {
   Serial.println("");
   Serial.print("Can NOT connect to ssid: [");
    Serial.print(ssid);
    Serial.println("], ESP8266 will try again...");
   delay(500);
   startWifi();
 }

}

Terminal output:

.........Start Arduino Cloud thing property...
Finish Arduino Cloud thing property...
Test Arduino Cloud Thing before poll()...
Connecting to mqtt broker...



sandeepmistry

Hi @benjenq,

There was an issue with the MQTT broker, could you please try again?

benjenq

Hi @sandeepmistry,

Today it turn back to work again! Thank you!

Danish_Mahmood

I have been successful at connecting my arduino mkr1000 to the Arduino Cloud but today i got an issue. In the serial monitor it says "MQTT Stuck".


I realize this problem has happened before...How can it be fixed or do i just have to wait.

sandeepmistry

I've re-resolved the issue with the broker again.

Go Up