MQTT Esp security credentials


#1
I Zerynth team,
I've a nodemcu v2 board, and I would like create a MQTT connection with a broker. The Broker credentials are clientid, username and password.
I've read mqtt library doc, and there is no methods that allow me to set password and username for connection. Isn't it true?How can i do?
Thanks

#2

Hello Cosimo,
unfortunately I forgot to document the

my_client.set_username_pw(username, password)
```

method  :o
We will fix as soon as possible,
anyway you can call this method before
my_client.connect(...)
```
 Let me know if everything works :smile:

#3

Trying to connect mqtt but facing this issue
[exception from mqtt: IOError @[0036:0012:009F:01CC:009E:0025:00F7:0033]]

I have written this code
try:
print(“testing”)
mqtt_c = mqtt.Client(“zerynth-mqtt”,True)
mqtt_c.set_username_pw(“username”,“Password”)
for retry in range(2):
try:
mqtt_c.connect(“host”,port,60)
break
except Exception as e:
print(“connecting…”)
print(“connected.”)

        if not mqtt_c:
            print ('mqtt not connected')
        else:
            print ('mqtt connected')
            return
    except Exception as e:
        print ('exception from mqtt: ', e)
        sleep(30)