After a MQTT socket is de-initialized, the mqtt thread still can attempt to send out TCP packets. My goal has been to create a loop that attempts to maintain a MQTT connection - tolerating network loss and reconnect.
wiced_tls_encrypt_packet() is called. Something beneath has already been deinitialized, so this call causes some ARM exceptions (null pointer??)
I haven't done too much analysis underneath this, but my initial suggestion is that the thread should not be processing further requests from user space to send messages. So, my suggested fix (below) uses member "net_init_ok" to decide this. I also noticed setting this was omitted in the situation of attempting to disconnect from user space (versus a TCP callback).
This MQTT library seems quite rough still. I highly suggest addition of a more robust connection loop in the MQTT sample code.