MQTT library and thingsboard
-
- Posts: 81
- Joined: Fri Sep 02, 2016 9:26 am
MQTT library and thingsboard
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.
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MQTT library and thingsboard
It should work if you don't supply a password to the constructor, or pass None. The default is None. This is different to "".
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 81
- Joined: Fri Sep 02, 2016 9:26 am
Re: MQTT library and thingsboard
pythoncoder wrote: ↑Wed Aug 22, 2018 10:52 amIt 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
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: MQTT library and thingsboard
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MQTT library and thingsboard
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)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: MQTT library and thingsboard
The broker may handle an empty password differently than no password being supplied. I think the code should rather be something like:
And below at line 95:
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.
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
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MQTT library and thingsboard
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.
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MQTT library and thingsboard
The official project for micropython-lib by its author is at https://github.com/pfalcon/micropython-lib . Bugreports/pull requests are welcome there.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.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/