# Mqtt Client reconnect

**URL:** <https://community.hivemq.com/t/mqtt-client-reconnect/482>\
**Category:** HiveMQ Client Library\
**Created:** [March 22, 2021, 8:23pm UTC](https://community.hivemq.com/t/mqtt-client-reconnect/482 "2021-03-22T20:23:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlessandroCaliaro](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@AlessandroCaliaro](https://community.hivemq.com/u/AlessandroCaliaro)\
**Post date:** [March 22, 2021, 8:23pm UTC](https://community.hivemq.com/t/mqtt-client-reconnect/482/1 "2021-03-22T20:23:22Z")

</div>

Hi.  
I’m testing the mqtt client and in particular the auto reconnection.  
I set automaticReconnectWithDefaultConfig () and when I deactivate the wifi of the android device, an event is generated in the addDisconnectedListener: a  
ddDisconnectedListener java.net.UnknownHostException: Unable to resolve host “testmqtt.xxx.it”: No address associated with hostname  
When I then turn the wifi back on, I would expect the mqtt to reconnect automatically, but I always get this error:

addDisconnectedListener CONNECT failed as CONNACK contained an Error Code: NOT\_AUTHORIZED.

what can be the reason?  
Thank you

---

<div class="post-metadata">

**Author:** ![AlessandroCaliaro](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@AlessandroCaliaro](https://community.hivemq.com/u/AlessandroCaliaro)\
**Post date:** [March 23, 2021, 9:19am UTC](https://community.hivemq.com/t/mqtt-client-reconnect/482/2 "2021-03-23T09:19:15Z")

</div>

I have found the problem. I have moved the  
simpleAuth()  
from  
connectWith()  
to  
MqttClient.builder()
