← index #948Issue #792
Related · high · value 1.733
QUERY · ISSUE

umqtt.simple using websockets

openby Anonymouse83opened 2024-12-12updated 2024-12-16

I have an existing - working - MQTT application using Paho-MQTT and Websockets.
I am working on a new device, which lacks the memory to use Paho-MQTT, but I cannot get umqtt.simple to work with Websockets.
The only example I could find showed setting up the websocket, then setting e.g. cleitn=MQTTClient(<clientid>, <server>, sock=websocket, port=<port>), which fails irrespective of how "sock" is set.
Is there a way to use the websocket protocol with umqtt.simple?
Many thanks,

1 comment
jomasnash · 2024-12-16

The official umqtt.simple from micropython-lib does not support setting the 'sock'.
Only client_id,server, port, user, password, keepalive, ssl is possible.

Also umqtt.simple uses a normal socket. When using Websockets, all MQTT packets are wrapped in a Websocket packet so it is not possible, without significant modifications, to use it in umqtt.simple.

I have made a async MQTT-client using Websockets. I use a patched version of aiohttp. The modifications to aiohttp were necessary because aiohttp does not accept headers (which are needed for almost every broker). Even then, aiohttp can still be blocking because the used getaddrinfo is still a blocking function, therefore I use my own developed, fully async, version of getaddrinfo.

CANDIDATE · ISSUE

How to use the umqtt.simple in other socket

openby ZuWardopened 2024-01-28updated 2024-01-29

I am use the esp32 and w5500 eth module. But I am using a third-party driver().
The socket of third-party drivers does not include the read and write method
How can I make umqtt.simple support this socket

3 comments
beyonlo · 2024-01-28

Have you checked this discussion https://github.com/orgs/micropython/discussions/11474? Since MicroPython version 1.20.0 the W5500 is supported by MicroPython (from Espressif ESP-IDF implementation). So I think that if you use that, everything else (like as mqtt client and any other protocol, including ssl) will be transparent because that espressif W5500 implementation (and micropython support) is using a raw ethernet implementation.

Can anyone confirm if what I did write is correct?

ZuWard · 2024-01-29

I have reviewed the discussion, but I have only succeeded with the code in the discussion once. Even if the same code is used after the second attempt, it cannot connect to the network and can cause SPI blocking. I do not understand why this is the case. Even if SPI is available after a power outage and restart, ETH still cannot obtain the IP, so I can only try using a third-party driver

ZuWard · 2024-01-29

Under the same code, there will always be an OSError prompt: Ethernet enable failed. I guess it's a problem with SPI blocking. How can I avoid this problem.
When I am in the shell, I can obtain the IP address, but when I use thorny to actually execute it, it cannot work

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied