If the current connection is terminated unexpectedly (e.g. because the
WiFi connection is dropped) the disconnect callback is not called. This
means that reestablishing the existing connection is not possible any
more.
Avoid this issue by forcefully removing the existing connection before
initiating the reconnection. Calling MQTT_Disconnect and waiting for
the disconnection callback should still be performed for intentional
disconnections.
Fixes#96
If a reconnect is triggered on a built-up connection the current
espconn instance is replaced without waiting for the invocation of
its disconnection callback.
As a result the disconnection callback gets invoked when the new
espconn instance has already been set, falsely terminating the newly
created connection.
Fix this by disconnecting the current connection cleanly before trying
to reestablish the connection. This change also prevents reconnections
via MQTT_Connect. Instead users should disconnect the current
connection via MQTT_Disconnect before invoking MQTT_Connect for an
existing client.