title: flask-mqtt: Mqtt Client disconnects immediately after connect
body: <p>i tried the example project of the Flask-MQTT (<a href="https://github.com/stlehmann/Flask-MQTT" rel="nofollow noreferrer">https://github.com/stlehmann/Flask-MQTT</a>) with my local mosquitto broker. But unfortunatly it is not working.
  Subscription and publish are not forwared correctly. so i've added some logger messages:</p>
  
  <pre><code>def handle_connect(client, userdata, flags, rc):
  print("CLIENT CONNECTED")
  
  @mqtt.on_disconnect()
  def handle_disconnect():
  print("CLIENT DISCONNECTED")
  
  @mqtt.on_log()
  def handle_logging(client, userdata, level, buf):
  print(level, buf)
  </code></pre>
  
  <blockquote>
    <p>16 Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k30) client_id=b'flask_mqtt'<br>
    CLIENT DISCONNECTED<br>
    16 Received CONNACK (0, 0)<br>
    CLIENT CONNECTED<br>
    16 Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k30) client_id=b'flask_mqtt'<br>
    CLIENT DISCONNECTED<br>
    16 Received CONNACK (0, 0)<br></p>
  </blockquote>
  
  <p>The mosquitto Broker shows that it disconnects the flask app because of the client is already connected:</p>
  
  <blockquote>
    <p>1580163250: New connection from 127.0.0.1 on port 1883.<br>
    1580163250: Client flask_mqtt already connected, closing old connection.<br>
    1580163250: New client connected from 127.0.0.1 as flask_mqtt (p2, c1, k30).<br>
    1580163250: No will message specified.<br>
    1580163250: Sending CONNACK to flask_mqtt (0, 0)<br>
    1580163251: New connection from 127.0.0.1 on port 1883.<br>
    1580163251: Client flask_mqtt already connected, closing old connection.<br>
    1580163251: New client connected from 127.0.0.1 as flask_mqtt (p2, c1, k30).<br>
    1580163251: No will message specified.<br>
    1580163251: Sending CONNACK to flask_mqtt (0, 0)<br>
    1580163251: Socket error on client flask_mqtt, disconnecting.<br></p>
  </blockquote>
  
  <p>i also tested a simple python.paho mqtt client example without flask and it works as expected.
  i also changed tried several loop starts inside the flask-mqtt code <code>self.client.loop_start() 
  --&gt; self.client.loop_forever()</code>  ... did not change anything.</p>
  
  <p>so any idea where's the problem? i also debugged the flask-mqtt code and cannot find issues.
  (my python version is Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
  (my host system is elementary Linux) </p>
  
  <p>maybe the FLASK-MQTT lib is deprecated ?
  any hint or idea is appreciated!</p>