Comments (7)
Hi, @fangchih. At this moment ws transport is experimital feature in gmqtt. You may help us to debug and test it by using gmqtt from support-ws-transport branch.
As I say, this is experimital feature and in future we can to change methods and ways to use it;
Here is a small exmaple how to init client with ws as transport:
mqtt = Client("test")
mqtt.set_auth_credentials('TOKEN')
# init your handlers on_connect, on_message and etc
await mqtt.connect('ws://mqtt.flespi.io', keepalive=60)
mqtt.subscribe('#')
data_to_send = '0xDEADBEAF' * (512 * 102)
mqtt.publish('topic/test', data_to_send)
from gmqtt.
Any news about this branch? When will it been merged to master?
from gmqtt.
@jeffreykira This happens because you didn't set valid credentials for the client, uncomment this line:
# mqtt.set_auth_credentials(token, None)
from gmqtt.
@Lenka42 Thanks for your replay. It works for me.
from gmqtt.
Hi, @Mixser. I get the wrong result using the above example.
Traceback (most recent call last):
File "gmqtt_websocket.py", line 60, in <module>
loop.run_until_complete(main(host, token))
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "gmqtt_websocket.py", line 43, in main
await mqtt.connect(broker_host, keepalive=60)
File "/Users/jing/virtualenv/mqtt_test/lib/python3.8/site-packages/gmqtt/client.py", line 143, in connect
self._connection = await self._create_connection(
File "/Users/jing/virtualenv/mqtt_test/lib/python3.8/site-packages/gmqtt/client.py", line 160, in _create_connection
connection = await MQTTConnection.create_connection(host, port, ssl, clean_session, keepalive)
File "/Users/jing/virtualenv/mqtt_test/lib/python3.8/site-packages/gmqtt/mqtt/connection.py", line 26, in create_connection
transport, protocol = await loop.create_connection(MQTTProtocol, host, port, ssl=ssl)
File "uvloop/loop.pyx", line 1914, in create_connection
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<Client._resend_qos_messages() running at /Users/jing/virtualenv/mqtt_test/lib/python3.8/site-packages/gmqtt/client.py:96> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x10d5c2070>()]>>
Below is my code. How can I solve this problem? Thank you.
import asyncio
import os
import signal
import time
from gmqtt import Client
# gmqtt also compatibility with uvloop
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
STOP = asyncio.Event()
def on_connect(client, flags, rc, properties):
print('Connected')
def on_message(client, topic, payload, qos, properties):
print('RECV TOPIC: ', topic)
def on_disconnect(client, packet, exc=None):
print('Disconnected')
def on_subscribe(client, mid, qos):
print('SUBSCRIBED, mid: {}'.format(mid))
def ask_exit(*args):
STOP.set()
async def main(broker_host, token):
mqtt = Client("test")
mqtt.on_connect = on_connect
mqtt.on_message = on_message
mqtt.on_disconnect = on_disconnect
mqtt.on_subscribe = on_subscribe
# mqtt.set_auth_credentials(token, None)
await mqtt.connect(broker_host, keepalive=60)
mqtt.subscribe('#')
data_to_send = '0xDEADBEAF' * (512 * 102)
mqtt.publish('topic/test', data_to_send)
await STOP.wait()
await mqtt.disconnect()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGINT, ask_exit)
loop.add_signal_handler(signal.SIGTERM, ask_exit)
host = 'ws://mqtt.flespi.io'
token = os.environ.get('FLESPI_TOKEN')
loop.run_until_complete(main(host, token))
from gmqtt.
@jeffreykira WS support feature is not master
yet, so in order to test it you should clone the repo and setup gmqtt from support-ws-transport
branch
from gmqtt.
@Lenka42 Thank you for your reminder. After adjustment I got the following error.
Traceback (most recent call last):
File "gmqtt_websocket.py", line 56, in <module>
loop.run_until_complete(main(host, token))
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "gmqtt_websocket.py", line 39, in main
await mqtt.connect(broker_host, keepalive=60)
File "/Users/jing/workspace/mqtt/gmqtt/gmqtt/client.py", line 152, in connect
raise self._error
gmqtt.gmqtt.mqtt.handler.MQTTConnectError: code 134 (Connection Refused: Bad User Name or Password)
from gmqtt.
Related Issues (20)
- 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
- [RECV EMPTY] Connection will be reset automatically. HOT 1
- blocking the loop when processing messages for a long time HOT 1
- Formal documentation for API HOT 1
- The subscribe non blocking method
- The QoS 2 Message Receive Queue is not being cleared HOT 1
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.