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

subscribe qos not apply #19

Closed
AhnSeongHyun opened this Issue Jan 24, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@AhnSeongHyun
Copy link
Contributor

AhnSeongHyun commented Jan 24, 2018

import json
from flask import Flask
from flask_mqtt import Mqtt

app = Flask(__name__)
app.config['MQTT_BROKER_URL'] = 'localhost'
app.config['MQTT_BROKER_PORT'] = 1993
app.config['MQTT_KEEPALIVE'] = 30

mqtt = Mqtt(app)
mqtt.subscribe(topic="TEST", qos=2)

app.run()

subscribe qos set 2 but only 0.

I use emqttd

test

Topic TEST is paho mqtt and Topic TEST_FLAK_MQTT is flask-mqtt.

Do not set subscribe qos:2

@stlehmann

This comment has been minimized.

Copy link
Owner

stlehmann commented Jan 24, 2018

That is strange. The subscribe function passes the parameters directly to paho. In your snippet I don't see the topic TEST_FLASK_MQTT. For TEST it seems to work.

@AhnSeongHyun

This comment has been minimized.

Copy link
Contributor

AhnSeongHyun commented Jan 25, 2018

my codes are blow:

import json
from flask import Flask
from flask_mqtt import Mqtt
app = Flask(__name__)
app.config['MQTT_BROKER_URL'] = 'localhost'
app.config['MQTT_BROKER_PORT'] = 1993
app.config['MQTT_KEEPALIVE'] = 30
app.config['MQTT_LAST_WILL_QOS'] = 2
mqtt = Mqtt(app)
mqtt.subscribe(topic="TEST_FLAK_MQTT", qos=2)
app.run()
import paho.mqtt.client as mqtt
mqttc = mqtt.Client()
mqttc.connect("localhost", port=1993, keepalive=60)  
mqttc.subscribe("TEST", 2)
mqttc.loop_forever()
@AhnSeongHyun

This comment has been minimized.

Copy link
Contributor

AhnSeongHyun commented Jan 25, 2018

mqtt.subscribe(("TEST_FLAK_MQTT",2)) # tuple 

set QOS : 2

mqtt.subscribe(topic="TEST_FLAK_MQTTT", qos=2)

Not set QOS : 2

@stlehmann

This comment has been minimized.

Copy link
Owner

stlehmann commented Jan 25, 2018

That is strange. I will give it a close look asap.

@stlehmann stlehmann added the bug label Jan 25, 2018

@stlehmann

This comment has been minimized.

Copy link
Owner

stlehmann commented Jan 26, 2018

You have to wait with the subscription until the connection has been established. Use the on_connect decorator for this. In your example this would look like this:

import json
from flask import Flask
from flask_mqtt import Mqtt

app = Flask(__name__)
app.config['MQTT_BROKER_URL'] = 'localhost'
app.config['MQTT_KEEPALIVE'] = 30
app.config['MQTT_LAST_WILL_QOS'] = 2

mqtt = Mqtt(app)

@mqtt.on_connect()
def connected(*args, **kwargs):
    mqtt.subscribe("TEST_FLASK_MQTT", 2)

app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment