Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

MQTT API - how to change 'qos'
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

MQTT API - how to change 'qos'

by readylan on Mon Dec 16, 2019 2:04 pm

Hello,
I'm exploring how to set the parameter 'qos' (for quality of service) in my mqtt client connection with python.

In online documentation you can read Adafruit IO can deal with values 0 & 1 for that. How can I set qos=1 in code?
This is the signature of publish with Adafruit IO Client Library (mqtt)

Code: Select all | TOGGLE FULL SIZE
mqttc.publish(feed_id, value, group_id, feed_user)


Thanks in advance,

Eduardo

readylan
 
Posts: 3
Joined: Mon Dec 09, 2019 10:44 am

Re: MQTT API - how to change 'qos'

by brubell on Wed Dec 18, 2019 4:52 pm

Hi readylan,

Yes, MQTT QoS 0 and QoS 1 are supported by Adafruit IO. QoS 2 is not.

To help me debug the signature you provided better, I need to know which library are you using to publish data (URL link or a name please)

- brent r.

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: MQTT API - how to change 'qos'

by readylan on Thu Dec 19, 2019 6:32 am

Hello brubell, thanks for your reply,

I'm using recent Adafruit libraries, this is my virtualenv (python 3.6.9):
Code: Select all | TOGGLE FULL SIZE
$ pip freeze
adafruit-io==2.3.2
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
cryptography==2.8
future==0.18.2
idna==2.8
paho-mqtt==1.5.0
pkg-resources==0.0.0
pycparser==2.19
python-telegram-bot==12.2.0
requests==2.22.0
six==1.13.0
tornado==6.0.3
urllib3==1.25.7


Now, in code, I have instantiated mqtt client object this way:

Code: Select all | TOGGLE FULL SIZE
from Adafruit_IO import MQTTClient
mqttc = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)


After that, how can I set QoS for publish / subscribe actions ?

Eduardo

readylan
 
Posts: 3
Joined: Mon Dec 09, 2019 10:44 am

Re: MQTT API - how to change 'qos'

by brubell on Thu Dec 19, 2019 11:29 am

Ok, I am mistaken. You are not able to set this in Adafruit IO Python...yet. I added an issue to the GitHub repository (https://github.com/adafruit/Adafruit_IO ... issues/106) for this library and will patch it. Thanks for bringing this up.

- brent r.

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: MQTT API - how to change 'qos'

by brubell on Mon Dec 23, 2019 2:48 pm

Updating this thread with good news

Adafruit IO Python v2.4.0 adds QoS Levels to subscribe calls!
https://github.com/adafruit/Adafruit_IO ... /tag/2.4.0

To subscribe to an Adafruit Feed with a provided QoS Level (1, in this example) with Adafruit IO Python v2.4.0 or above, use the following method call:
Code: Select all | TOGGLE FULL SIZE
    client.subscribe(feed_identifier, qos=1)

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: MQTT API - how to change 'qos'

by readylan on Sat Dec 28, 2019 8:48 am

Hello!
I wonder how to try this improvement since I don't know how to set qos 1 for a PUBLISH command. I suppose the addition of the qos parameter in the client's publish method is work in progress ;)

In fact, I see that the messages sent with qos 1 are returned by the broker with qos 0:
(In this log I used the mosquitto client of my machine with Linux ubuntu)
This code is showing the publish action with QoS 1 ( -q 1):

Code: Select all | TOGGLE FULL SIZE
mosquitto_pub -h io.adafruit.com -u readylan -P *** -q 1 -t readylan/feeds/kk -m 2 -d
Client mosq-TDrBZShLUysQaoaKma sending CONNECT
Client mosq-TDrBZShLUysQaoaKma received CONNACK (0)
Client mosq-TDrBZShLUysQaoaKma sending PUBLISH (d0, q1, r0, m1, 'readylan/feeds/kk', ... (1 bytes))
Client mosq-TDrBZShLUysQaoaKma received PUBACK (Mid: 1, RC:0)
Client mosq-TDrBZShLUysQaoaKma sending DISCONNECT


Here, the subscribe action with QoS 1 ( -q 1):
Code: Select all | TOGGLE FULL SIZE
mosquitto_sub -h io.adafruit.com -u readylan -P *** -q 1 -t readylan/feeds/kk -d
Client mosq-Yy35PAZhNezDlK4cVw sending CONNECT
Client mosq-Yy35PAZhNezDlK4cVw received CONNACK (0)
Client mosq-Yy35PAZhNezDlK4cVw sending SUBSCRIBE (Mid: 1, Topic: readylan/feeds/kk, QoS: 1, Options: 0x00)
Client mosq-Yy35PAZhNezDlK4cVw received SUBACK
Subscribed (mid: 1): 1
Client mosq-Yy35PAZhNezDlK4cVw received PUBLISH (d0, q0, r0, m0, 'readylan/feeds/kk', ... (1 bytes))
2

Note that the response received does not maintain the initial Quality of Service.

Best regards,

Eduardo

readylan
 
Posts: 3
Joined: Mon Dec 09, 2019 10:44 am

Re: MQTT API - how to change 'qos'

by brubell on Thu Jan 02, 2020 3:49 pm

Hi readylan,

We do not support publishing with a QoS level, only subscribing.

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.