Page 1 of 1
MQTT library and thingsboard
Posted: Wed Aug 22, 2018 7:20 am
by ajie_dirgantara
Hi,
I am using mqtt library for micropython, and when connecting to thingsboard via mqtt, it required to supply username with authentication token and password set to "" (no password). Using no password, mqtt libray is failed to connect, while if I connect to another mqtt broker with password, it work just okay. I think it has something to do with the library. It doesn't support "" (empty) password.
Re: MQTT library and thingsboard
Posted: Wed Aug 22, 2018 10:52 am
by pythoncoder
It should work if you don't supply a password to the constructor, or pass None. The default is None. This is different to "".
Re: MQTT library and thingsboard
Posted: Fri Aug 24, 2018 6:51 pm
by ajie_dirgantara
pythoncoder wrote: ↑Wed Aug 22, 2018 10:52 am
It should work if you don't supply a password to the constructor, or pass
None. The default is
None. This is different to "".
if I don't supply any password, it will raise exception TypeError 'NoneType' has no length at simple.py line 60
Re: MQTT library and thingsboard
Posted: Fri Aug 24, 2018 10:26 pm
by SpotlightKid
Yep, looks like a bug to me(it's actually line 68, AFAICS). Code doesn't check whether self.pswd is None or an empty string and sets the password flag in the
connect flags regardless. It inccorrectly assumes that if the user is set, the password is not none.
Re: MQTT library and thingsboard
Posted: Sat Aug 25, 2018 4:31 am
by pythoncoder
Well spotted: in my testing neither was supplied. I suggest you raise an issue or PR. I guess you need something like:
Code: Select all
sz += 2 + len(self.user) + 2 + (len(self.pswd) if self.pswd is not None else 0)
Re: MQTT library and thingsboard
Posted: Sat Aug 25, 2018 8:20 am
by SpotlightKid
The broker may handle an empty password differently than no password being supplied. I think the code should rather be something like:
Code: Select all
if self.user is not None:
sz += 2 + len(self.user)
msg[6] |= 1 << 7
if self.pswd is not None:
sz += 2 + len(self.pswd)
msg[6] |= 1 << 6
And below at line 95:
Code: Select all
if self.user is not None:
self._send_str(self.user)
if self.pswd is not None:
self._send_str(self.pswd)
BTW, where does one submit PRs to micropython-lib these days? At
https://github.com/micropython/micropython-lib/ or
https://github.com/pfalcon/micropython-lib ? The former hasn't seen a commit since february.
Re: MQTT library and thingsboard
Posted: Sun Aug 26, 2018 6:13 am
by pythoncoder
My understanding is that the official library is
https://github.com/micropython/micropython-lib.git - ref
this post from Damien.
Since the unfortunate loss of @pfalcon as a maintainer, library PR's are not always handled in a timely fashion. This is why I (reluctantly) maintain a fork of uasyncio. I'd hope that a bugfix PR will achieve a higher priority response than my efforts at enhancements.
Re: MQTT library and thingsboard
Posted: Sun Aug 26, 2018 6:45 pm
by SpotlightKid
Re: MQTT library and thingsboard
Posted: Mon Aug 27, 2018 6:40 am
by pythoncoder
Looks good to me.
Re: MQTT library and thingsboard
Posted: Sun Sep 23, 2018 7:28 pm
by pfalcon
The official project for micropython-lib by its author is at
https://github.com/pfalcon/micropython-lib . Bugreports/pull requests are welcome there.