knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.81k stars 1.47k forks source link

Connect failing to cloud services #171

Open markrpw opened 8 years ago

markrpw commented 8 years ago

My name is Mark, and I've been working in the Samsung IoT group with your PubSubClient for many months. Over the last month, it was functioning extremely well with two simutaneous instances, one to a local Mosquitto broker (unsecured) and another to ARTIK Cloud services (SSL/TLS-encrypted to a Moquette broker if I've understood correctly).

Last week it just stopped working to the ARTIK Cloud connection. All instances on all boards that were otherwise unchanged fell victim. Yet all other clients to this cloud broker continue to work fine - MQTTfx, Node-RED - and according to the Arduino folks, they see the same failure to the cloud portal, yet do not see if using the MQTT library (https://github.com/256dpi/arduino-mqtt).

For our tutorials, we've done a lot of testing and documentation using your library (see https://developer.artik.io/documentation/advanced-concepts/mqtt/color-mqtt-arduino.html#mqtt-client-library) and have more in the pipeline, so I'm reluctant to change client programs if it's something straightforward to correct.

The pared-down test code is simple enough. You just need to get a no-cost account at artik.cloud and pick any pre-existing device to get a device ID and device token.

include

include

include

//------------- // ARTIK Cloud MQTT params
char mqttCloudServer[] = "api.artik.cloud"; int mqttCloudPort = 8883; char mqttCloudClientName[] = "ARTIK-Arduino"; char mqttCloudUsername[] = "_deviceID"; // need to sign up at artik.cloud to get device ID char mqttCloudPassword[] = "_devicetoken"; // and device token

WiFiSSLClient ipCloudStack; PubSubClient mqttCloudClient(mqttCloudServer, mqttCloudPort, ipCloudStack);

void setup() { DebugSerial.begin(115200);
DebugSerial.println("start ARTIK Cloud connect"); int rc = mqttCloudClient.connect(mqttCloudClientName, mqttCloudUsername, mqttCloudPassword); DebugSerial.println("went thru connect init"); } void loop() { }

The nature of the failure: in PubSubClient::connect, everything seems to work fine up through the cert check. But we hang when we hit this part: while (!_client->available()) { unsigned long t = millis(); if (t-lastInActivity >= ((int32_t) MQTT_SOCKET_TIMEOUT*1000UL)) { _state = MQTT_CONNECTION_TIMEOUT; _client->stop(); return false; } }

A representative error output is attached. If you can give me any hints about working around the issue, it would really accelerate release of the next MQTT tutorial in the series. I'd really like to continue promoting your well written library!

Thanks in advance! Mark

out.txt

knolleary commented 8 years ago

To be honest, I have no idea. Where is that error output coming from? What's it telling me? Is it an issue establishing the TLS connection? This library hasnt changed in some time... if it has suddenly stopped working for you, there must be some other part of the system that has changed.