Once i have to update Mosquito my MQTT broker. And then suddenly all of my esp. connected devices stopped working.
So first thing to do is to debug. I was using umqtt Simple for my ESPe8266 Node Mcu v3.
The error shows something like -1.

Then i found one nice solution.

The first hint how to fix it i found in this thread.
https://github.com/micropython/micropython-lib/issues/210

I had same problem with continue disconnecting from the mqtt server with keepalive > 0.

This gives me a bit to think cause i do not have keepalive value. 
On this website i found more about keepalive:
https://www.donskytech.com/common-micropython-problems/

So the natural way was to set keep alive to 60 or something and problem solved right ? 

 

Not quite. True it works but only for the amount of time keep alive was issued. 
So there is an fix. If you send message before keepalive expire. Like in my case:
My keepalive value was set to 31. And the message is published at 30.

This ensures the connection and everything working right now. 
The tutorial on mqtt might be released soon. 

Fixing umqtt keepalive feauture

c = MQTTClient(env.ID, env.SERVER, env.PORT, env.USER, env.MQTT_PASS, keepalive=30)
c.set_callback(sub_cb)
c.connect()
c.subscribe(topic1)

counter = 0
while True:
    try:
        if(counter < 30):
            counter += 1
            print(counter)
        else:
            c.publish("notice/alive", str(counter))
            counter = 0
            
        c.check_msg()
#         display.send(str(gc.mem_alloc()) + " " + str(gc.mem_free()))
        sleep(1)
        gc.collect()
    except Exception as e:
        print(type(e))    # the exception instance
        print(e.args)     # arguments stored in .args
        print(e)          # __str__ allows args to be printed directly,
        sleep(1)