Skip to content
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

Merged
merged 5 commits into from
Aug 6, 2020
Merged

adjust fixed_header init; (-) loop_forever() #46

merged 5 commits into from
Aug 6, 2020

Conversation

2bndy5
Copy link
Contributor

@2bndy5 2bndy5 commented Jul 22, 2020

@brentru This should now be rebased upon the adafruit master branch.
changes include:

  • removed deprecated loop_forever() in preparation for next major release.
  • consolidated the fixed_header initialization to 1 line of code.

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))
Copy link
Member

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

Copy link
Contributor Author

@2bndy5 2bndy5 Jul 29, 2020

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.

@brentru
Copy link
Member

brentru commented Aug 5, 2020

@2bndy5 Do you want to remove the calls to loop_forever within those two libs? Do you want me to?

@2bndy5
Copy link
Contributor Author

2bndy5 commented Aug 5, 2020

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.

@2bndy5
Copy link
Contributor Author

2bndy5 commented Aug 6, 2020

@brentru
Copy link
Member

brentru commented Aug 6, 2020

Thanks for opening the PRs. Looks like examples are working now. Will merge once I test CircuitPython IO.

Tested on Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit PyPortal with samd51j20


Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Connecting to WiFi...
Connected!
Connecting to Adafruit IO...
Connected to Adafruit IO! Listening for topic changes on brubell/feeds/onoff
Sending photocell value: 0...
Sent!
Sending photocell value: 1...
Sent!
Sending photocell value: 2...
Sent!
Sending photocell value: 3...
Sent!
Sending photocell value: 4...
Sent!
Sending photocell value: 5...
Sent!
Sending photocell value: 6...
Sent!
Sending photocell value: 7...
Sent!
Sending photocell value: 8...
Sent!
Sending photocell value: 9...
Sent!
Sending photocell value: 10...
Sent!
Sending photocell value: 11...
Sent!
Sending photocell value: 12...
Sent!
Sending photocell value: 13...
Sent!
Sending photocell value: 14...
Sent!
Sending photocell value: 15...
Sent!
Sending photocell value: 16...
Sent!
Sending photocell value: 17...
Sent!
Sending photocell value: 18...
Sent!
Sending photocell value: 19...
Sent!
Sending photocell value: 20...
Sent!
Sending photocell value: 21...
Sent!
Sending photocell value: 22...
Sent!```

@brentru brentru merged commit f4233d0 into adafruit:master Aug 6, 2020
@2bndy5 2bndy5 deleted the remove-loop_forever() branch August 6, 2020 21:00
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 7, 2020
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
rtwfroody pushed a commit to rtwfroody/Adafruit_CircuitPython_MiniMQTT that referenced this pull request Sep 18, 2022
adjust fixed_header init; (-) loop_forever()
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.

2 participants