Skip to content

Add Topic-specific message callbacks #38

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
merged 7 commits into from
Jun 8, 2020
Merged

Add Topic-specific message callbacks #38

merged 7 commits into from
Jun 8, 2020

Conversation

brentru
Copy link
Member

@brentru brentru commented Jun 5, 2020

Addresses issue: #37


Tested using: examples/minimqtt_pub_sub_blocking_topic_callbacks.py
Tested on: Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit Feather Bluefruit Sense with nRF52840 with AirLift FeatherWing

REPL output

code.py output:
Connecting to WiFi...
Connected!
Connecting to MQTT broker...
Connected to MQTT Broker!
Subscribed to device/# with QOS level 1
Battery level: 3.5v
New message on topic device/sensor1: 3.5
New message on topic device/sensor1: 500

Mosquitto Publisher Client

mosquitto_pub -h IP -p PORT -m 3.5  -t device/batteryLevel
mosquitto_pub -h IP -p PORT -m 500  -t device/sensor1

Test for remove_topic_callback, modified minimqtt_pub_sub_blocking_topic_callbacks.py

def on_battery_msg(client, topic, message):
    # Method called when device/batteryLife has a new value
    print("Battery level: {}v".format(message))

    # Remove this topic callback
    client.remove_topic_callback("device/batteryLevel")

Mosquitto Publisher Client

mosquitto_pub -h IP -p PORT -m 3.5  -t device/batteryLevel
mosquitto_pub -h IP -p PORT -m 3.5  -t device/batteryLevel

REPL output

code.py output:
Connecting to WiFi...
Failed to connect, retrying
 ('Failed to connect to ssid', b'TP-Link_519E')
Connected!
Connecting to MQTT broker...
Connected to MQTT Broker!
Subscribed to device/# with QOS level 1
New message on topic device/sensor1: 500
Battery level: 3.5v
< remove_topic_callback executed here >
New message on topic device/batteryLevel: 3.5 <<< topic filters to on_message instead 

@ladyada
Copy link
Member

ladyada commented Jun 6, 2020

@jimbobbennett hi do ya wanna review this one?

@jimbobbennett
Copy link

@jimbobbennett hi do ya wanna review this one?

Yup - I'll take a look next week and test it out by upgrading the Azure IoT library to make use of it.

@jimbobbennett
Copy link

Looks good now. Tested with the Azure IoT library.

PR raised for the Azure library to update to use these changes once merged.

@brentru
Copy link
Member Author

brentru commented Jun 8, 2020

Perfect - thank you for testing it against that library.

@brentru brentru merged commit 4f01403 into adafruit:master Jun 8, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 9, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_AHTx0 to 1.0.1 from 1.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_AHTx0#1 from kattni/example-i2c-update

Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 3.4.1 from 3.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#99 from Flameeyes/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_ILI9341 to 1.2.1 from 1.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ILI9341#22 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_ILI9341#21 from adafruit/setup-py-disabled
  > build.yml: add black formatting check

Updating https://github.com/adafruit/Adafruit_CircuitPython_LPS2X to 2.0.0 from 1.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_LPS2X#4 from adafruit/lps22
  > build.yml: add black formatting check

Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.4.0 from 1.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#20 from xorbit/master
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#14 from adafruit/pylint-update

Updating https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT to 2.2.1 from 2.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_AzureIoT#16 from jimbobbennett/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.7.0 from 2.6.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#49 from kmatch98/background
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#48 from FoamyGuy/better_group_full_error

Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.3.0 from 2.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#39 from rhooper/bugfixes
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#38 from rhooper/sequence-one-shot
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#40 from rhooper/pixelgrid

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 3.1.0 from 3.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#38 from brentru/on-message-enhancements

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_ILI9341
rtwfroody pushed a commit to rtwfroody/Adafruit_CircuitPython_MiniMQTT that referenced this pull request Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants