adafruit / Adafruit_WICED_Arduino

Adafruit WICED Feather Arduino BSP
https://www.adafruit.com/products/3056
27 stars 19 forks source link

Feather WICED & AWS disconnects #59

Closed hathach closed 7 years ago

hathach commented 7 years ago

https://forums.adafruit.com/viewtopic.php?f=57&t=102931&p=517129#p517129

I'm using AWS, so I have based my code on what's in that example. I'll do a rewrite later, but this is sufficient for now. I'm using the connectAp() method to hook it to the web before initiating AWS. This is using Feather.connect().

When my board disconnects, it is always able to reconnect to the Access Point (AP), but right after doing that it freezes up. This makes me suspect that there's something that isn't being released when a MQTT connection drops? Here's some debugging I've done.

In the connect() method there's two calls that set up the MQTT connection to AWS:

Code: Select all | TOGGLE FULL SIZE
    mqtt.connectSSL(AWS_IOT_MQTT_HOST, AWS_IOT_MQTT_PORT);
       mqtt.subscribe(AWS_IOT_MQTT_TOPIC, MQTT_QOS_AT_MOST_ONCE, subscribed_callback);

The first of these are using an instance of the tcp class to set up the connection

I used my phone as an AP so I can easily test different scenarios.

If the AP is down, I'll get one of these:

Code: Select all | TOGGLE FULL SIZE
    SDEP_CMD_MQTTPUBLISH failed, Error: MQTT_FAILED (31000)
       --- FEATHER HALTED ---

No cleanup is done, it's just crashing and stopping.
If my AP looses it's internet connection, but stays connected to the WICED I get this:

Code: Select all | TOGGLE FULL SIZE
    SDEP_CMD_MQTTPUBLISH failed, Error: MQTT_FAILED (31000)

       --- FEATHER HALTED ---

       *** disconnect_cleanup
       [Heap free] stop 483: Arudino = 10792, featherlib = 22644
       [free] TCP Client
       [free] TCP TLS Context
       [free] TCP TLS Identity

       [Heap free] stop 496: Arudino = 14016, featherlib = 23924

       -----------------------------
       DISCONNECTED FROM MQTT BROKER
       -----------------------------

Now this looks quite good? It does halt, but also does a cleanup (I placed a Serial.println with the three stars *** in that routine to see that it's called) and calls the MQTT disconnect routine. That's good!

I've set my code up to keep running in the case of errors using mqtt.err_actions(true, false), but I have a suspicion that something isn't properly reset so that my second call to mqtt.connectSSL just crashes.