-
Notifications
You must be signed in to change notification settings - Fork 51
Fix publishing large payloads (>127 bytes) #42
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
Merged
brentru
merged 16 commits into
adafruit:master
from
brentru:variable-headers-large-payload
Jul 3, 2020
Merged
Fix publishing large payloads (>127 bytes) #42
brentru
merged 16 commits into
adafruit:master
from
brentru:variable-headers-large-payload
Jul 3, 2020
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@caternuson @seantibor this is ready for review (or testing if you are set up to test) |
I'm not familiar enough with the code level details to do a code review. But ran a simple test, which seems to work. Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit PyPortal with samd51j20
>>> import pp_mqtt_send
ESP firmware: bytearray(b'1.2.2\x00')
Set background to 0
No SD card found: no SD card
Connecting to WiFi...
Connected!
Connecting to Adafruit IO...
Subscribing to feed.
Connected.
Sending image...
Published
>>> Here's the code: from adafruit_binascii import b2a_base64
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
#https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT
import adafruit_minimqtt.adafruit_minimqtt as MQTT
import adafruit_pyportal
FILENAME = 'squares.jpg'
FEED = 'image_test'
from secrets import secrets
pyportal = adafruit_pyportal.PyPortal()
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(pyportal._esp, secrets, None)
# Connect to WiFi
print("Connecting to WiFi...")
wifi.connect()
print("Connected!")
# Callbacks
def connected(client, userdata, flags, rc):
print("Subscribing to feed.")
client.subscribe(mqtt_topic)
def disconnected(client, userdata, rc):
print("Disconnected from MQTT Broker!")
def message(client, topic, message):
print("New message on topic {0}: {1}".format(topic, message))
mqtt_topic = "{}/feeds/{}".format(secrets['aio_username'], FEED)
MQTT.set_socket(socket, pyportal._esp)
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
username=secrets["aio_username"],
password=secrets["aio_key"],
)
# Setup the callback methods above
mqtt_client.on_connect = connected
mqtt_client.on_disconnect = disconnected
mqtt_client.on_message = message
# Connect the client to the MQTT broker.
print("Connecting to Adafruit IO...")
mqtt_client.connect()
print("Connected.")
print("Sending image...")
# pre-send loop pump
mqtt_client.loop()
with open(FILENAME, "rb") as imgfile:
img64 = b2a_base64(imgfile.read())
mqtt_client.publish(mqtt_topic, img64.decode("utf-8"), retain=False, qos=0)
#post-send loop pump
mqtt_client.loop()
print("Published") |
@caternuson Thanks for testing. |
adafruit-adabot
added a commit
to adafruit/Adafruit_CircuitPython_Bundle
that referenced
this pull request
Jul 4, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 3.2.0 from 3.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#42 from brentru/variable-headers-large-payload
rtwfroody
pushed a commit
to rtwfroody/Adafruit_CircuitPython_MiniMQTT
that referenced
this pull request
Sep 18, 2022
…yload Fix publishing large payloads (>127 bytes)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: #31
Previously, the library would throw an
IndexError
if the combined length of a topic and payload was > 127 bytes.This pull request:
Tests
Note: tests performed on
Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit Feather M4 Express with samd51j19
with an Ethernet FeatherWing.PUBLISH'ing a larger payload (image, 557 bytes) to Adafruit IO
Publishing a small packet with a QoS of 0 and

retain
flag un-set.mqtt_client.publish(test_feed, "adafruit")
Publishing with a QoS of 0 and
retain
flag set.mqtt_client.publish(test_feed, img64.decode("utf-8"), retain=True, qos=0)
Repeated Publishing with a QoS of 1 and a large payload