Comments (6)
Thank you this helped a lot.
from gmqtt.
As I can see, you subscribed to the "test/#" wildcard topic.
Then you send a message from this client and receive it from the broker by this client. After that, you send another message from another mqtt client, and also receive a message using this client. It works correctly.
If you do not want to receive messages sent by this client, you can use the βno_local = trueβ flag when subscribing to a topic. After that, you will begin to receive only those messages that are sent only by other clients. But it works only with mqtt5 also it depends on broker.
from gmqtt.
import ssl
import asyncio
from gmqtt import Client as MQTTClient
from gmqtt import Subscription
STOP = asyncio.Event()
def on_connect(client, flags, rc, properties):
print('Connected')
# This is OK
client.subscribe('test/a', qos=0, no_local=True)
# This is also OK
b=[Subscription("test/b",qos=0, no_local=True)]
client.subscribe(b)
#This will not disable local messages
c=[Subscription("test/c",qos=0)]
client.subscribe(c, no_local=True)
def on_message(client, topic, payload, qos, properties):
print('[RECV MSG {}] TOPIC: {} PAYLOAD: {} QOS: {} PROPERTIES: {}'.format(client._client_id, topic, payload, qos, properties))
def on_disconnect(client, packet, exc=None):
print('Disconnected')
def on_subscribe(client, mid, qos, properties):
print('SUBSCRIBED')
async def main(broker_host):
client = MQTTClient("code_client-id")
client.on_connect = on_connect
client.on_message = on_message
client.on_disconnect = on_disconnect
client.on_subscribe = on_subscribe
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ssl_context.verify_mode = ssl.CERT_NONE
client.set_auth_credentials("username", "password")
await client.connect(broker_host,8883,ssl_context)
client.publish('test/a', "testA", qos=0)
client.publish('test/b', "testB", qos=0)
client.publish('test/c', "testC", qos=0)
await STOP.wait()
await client.disconnect()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
host = 'mqtt.myhost.com'
loop.run_until_complete(main(host))
There you go.
from gmqtt.
One note on this matter.
I noticed that if I create subscriptions with the subscription class, if I don't set the no_local = true at the time of creation and set it when I actually subscribe, the no_local = true is ignored.
from gmqtt.
@teucrus could you please provide example of code, how are you doing the subscription?
from gmqtt.
@teucrus yeeah, my idea was if you use Subscription
object, you should pass all the arguments into this object, and all the arguments from subscribe
method is ignored. I guess I should do this 'ignoring' more explicit, or update subscriptions with this arguments, I'll think about it, thanks for noticing
from gmqtt.
Related Issues (20)
- server keep live bug HOT 2
- Malformed packet when subscribe non-ASCII topic like 'testtopic/ζΆι΄' HOT 3
- Same message received multiple times. HOT 3
- Develop my own fault recovery logic using gmqtt client
- GMQTT with TLS: Not able to connect to broker #122 HOT 15
- How to increase the max in IdGenerator from client? HOT 1
- Resubscribe after autoreconnect HOT 1
- [PROPERTIES] received invalid property id 105, disconnecting HOT 2
- Handler does not work for null body retained messages published before the handler created HOT 6
- Client still running after disconnect() in 0.6.9 HOT 1
- Exceeded reconnect_retries seems seems not to be working HOT 1
- Unsubscribe doesn't remove the topic from the internal list
- I can't to use ca.crt, client.crt, client.key (X509 certificate) to connect mqtt broker. HOT 2
- Read message from mqtt and post Data to wialon HOT 1
- request and response mechanism
- won't remove resend messages if PUBREC is faster than message pushed HOT 1
- publish() and then disconnect() may result in messages not received by a broker
- is there a handler like python.paho.mqtt message_callback_add? HOT 2
- No PubBack Message HOT 1
- Connection error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmqtt.