-
Notifications
You must be signed in to change notification settings - Fork 51
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
adjust fixed_header init; (-) loop_forever() #46
Conversation
pub_hdr_var.append(len(topic) >> 8) # Topic length, MSB | ||
pub_hdr_var.append(len(topic) & 0xFF) # Topic length, LSB | ||
# variable header = 2-byte Topic length (big endian) | ||
pub_hdr_var = struct.pack(">H", len(topic)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the example simpletest
on Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit PyPortal with samd51j20
throws the following error in the REPL:
Subscribed to test/topic with QOS level 0
Publishing to test/topic
Traceback (most recent call last):
File "code.py", line 116, in <module>
File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 468, in publish
AttributeError: 'bytes' object has no attribute 'extend'
Instead of extend
on L468, we may want to append
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a borderline rookie mistake. I tried append()
instead, but I still got the same error AttributeError: 'bytes' object has no attribute 'append'
However pub_hdr_var += topic.encode()
does what we want. The real problem comes from the change to using struct.pack()
which returns an immutable bytes
object, where methods like append()
or extend(bytes([0x00]))
(notice the need for conversion from int
to bytes
when using extend()
) can only apply to a mutable bytearray
object. So, I've wrapped the struct.pack()
into a bytearray(struct.pack())
which allows us to keep using the pub_hdr_var.append()
calls on L474 & L475.
@2bndy5 Do you want to remove the calls to |
I can open the PR for each since you did all the legwork in testing this in the hardware. Literally the least I could do. |
@brentru PR for Adafruit_CircuitPython_GC_IOT_Core & PR for Adafruit_CircuitPython_AdafruitIO are open with all checks passing. |
Thanks for opening the PRs. Looks like examples are working now. Will merge once I test CircuitPython IO. Tested on
|
Updating https://github.com/adafruit/Adafruit_CircuitPython_GC_IOT_Core to 3.0.0 from 2.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_GC_IOT_Core#14 from 2bndy5/master > Merge pull request adafruit/Adafruit_CircuitPython_GC_IOT_Core#16 from brentru/attribute-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 4.0.0 from 3.3.0: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#46 from 2bndy5/remove-loop_forever() Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 1.3.1 from 1.3.0: > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#13 from FoamyGuy/fix_inital_progress
adjust fixed_header init; (-) loop_forever()
@brentru This should now be rebased upon the adafruit master branch.
changes include:
loop_forever()
in preparation for next major release.fixed_header
initialization to 1 line of code.