Skip to content

umqtt.simple: refactor packet de/encoding and fix remaining length encoding (fixes #284) #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

SpotlightKid
Copy link
Contributor

@SpotlightKid SpotlightKid commented Aug 27, 2018

As stated in #284, the MQTTClient.subscribe method doesn't handle topic lengths >= 122 correctly, since it only allocates one byte for the remaining length portion of the SUBSCRIPTION packet. I've refactored the variable length encoding of the remaining length bytes to use the new _varlen_encode method consistently and also got rid of the usage of the ustruct module.

  • Add _varlen_encode method to write variable length encoded remaining length bytes to packet buffer and use it consistently.
  • Use int.from_bytes/to_bytes to de/encode short integers and replace ustruct usage with it.
  • Correctly separate bytes of fixed and variable header in connect method.

In a separate commit I've also removed all (commented ou) debug printing calls in simple.py and added a debug wrapper for MQTTClient (umqtt_debug.py) to the examples, which can optionally be used with examples, and I've also expanded example_pub.py and example_sub.py so that they can be parametrized form the command line. If desired, I can separate this commit into an extra PR.

This PR is based on the branch for PR #302. If the latter is merged, I will rebase this on master.

@SpotlightKid SpotlightKid force-pushed the bugfix/umqtt-fix-varlen branch from 4365d12 to 367bb92 Compare August 27, 2018 17:28
…coding (fixes micropython#284)

* Add `_varlen_encode` method to write variable length encoded
  remaining length bytes to packet buffer and use it consistently.
* Use `int.from_bytes/to_bytes` to de/encode short integers
  and replace `ustruct` usage with it.
* Correctly separate bytes of fixed and variable header in `connect` method.
* Comment out unused import of `ubinascii.hexlify`.
…ent which can optionally be used with examples
@SpotlightKid SpotlightKid force-pushed the bugfix/umqtt-fix-varlen branch from 367bb92 to 65a29fe Compare August 27, 2018 17:29
@Kriechi
Copy link

Kriechi commented Dec 29, 2018

@pfalcon this looks like an important bugfix - any chance you could review this?

@SpotlightKid
Copy link
Contributor Author

SpotlightKid commented Dec 29, 2018

@Kriechi It seems that only the fork (or original, depending on how you look at it) of micropython-libat https://github.com/pfalcon/micropython-lib is maintained and developed any further, ATM.

I could re-submit my PR there, but I have basically given up on MicroPython, and I probably won't put any more effort into it. Feel free to take this PR (and any others I have made in this repo) and re-submit it (them) to pfalcon's repo.

@dl2080
Copy link

dl2080 commented Feb 9, 2021

Thank you @SpotlightKid! Without your refactor bug fix I wasn't able to subscribe to my AWS topic, although it was only 63 bytes in length. Now it is working!

@SpotlightKid
Copy link
Contributor Author

Closing this since I'm cleaning my unmerged PRs and this hasn't been acted upon in years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants