Openwrt mqtt

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
teltonique21
Posts: 11
Joined: Fri Mar 04, 2022 9:47 am

Openwrt mqtt

Post by teltonique21 » Tue Jun 21, 2022 3:43 pm

I tried the official benchmark script which connects to MQTT from the Peter Hinch github:

https://github.com/peterhinch/micropyth ... nchmark.py

however I get:

Code: Select all

micropython benchmark.py 
Connected to mqtt.blabla.net, subscribed to b'test/test' topic
Traceback (most recent call last):
  File "benchmark.py", line 89, in <module>
  File "benchmark.py", line 86, in main
  File "benchmark.py", line 84, in main
  File "/usr/lib/micropython/umqtt/simple.py", line 203, in check_msg
NotImplementedError: 
apparently the method sock.setblocking(False) is not implemented:

Code: Select all

def check_msg(self):  
        self.sock.setblocking(False)
        return self.wait_msg()
what leaves me perplexed is that the method wait_msg which uses self.sock.setblocking(True) works flawlessy.

Code: Select all

def wait_msg(self):            
        res = self.sock.read(1)        
        self.sock.setblocking(True)  
In my case I need to subscribe and publish at the same time so I cannot block on the socket to receive otherwise my script will never send anything.
My version on OpenWrt is the following:

Code: Select all

# micropython -v
MicroPython v1.9.4 on 2022-06-19; linux version
apparently it's the last port supported by OpenWrt.
Can I have a non blocking subscribe on MQTT??

tepalia02
Posts: 65
Joined: Mon Mar 21, 2022 5:13 am

Re: Openwrt mqtt

Post by tepalia02 » Tue Jun 21, 2022 4:02 pm

Since you're facing issues with MQTT, I think you can try this one: https://randomnerdtutorials.com/micropy ... 2-esp8266/

teltonique21
Posts: 11
Joined: Fri Mar 04, 2022 9:47 am

Re: Openwrt mqtt

Post by teltonique21 » Wed Jun 22, 2022 7:26 am

tepalia02 wrote:
Tue Jun 21, 2022 4:02 pm
Since you're facing issues with MQTT, I think you can try this one: https://randomnerdtutorials.com/micropy ... 2-esp8266/
I am using the Linux / OpenWRT port not the ESP32, also the code uses:

Code: Select all

while True:
  try:
    client.check_msg()
which is the same method I am having problems with.
My code uses TLS and correctly publishes, I have a problem only with the non blocking check_msg() which is not correctly implemented in the library and thus I cannot send and receive MQTT asynchronously.

teltonique21
Posts: 11
Joined: Fri Mar 04, 2022 9:47 am

Re: Openwrt mqtt

Post by teltonique21 » Wed Jun 22, 2022 10:22 am

ok tried this library https://github.com/peterhinch/micropyth ... er/mqtt_as
with TLS certificates, it only works if I comment in mqtt_as.py the setblocking(True) and thus make the connection synchronous.

Code: Select all

async def _connect(self, clean):
        self._sock = socket.socket()
        self._sock.setblocking(True)

otherwise I get: ssl_handshake_status: -4
and on the Mosquitto broker:

Code: Select all

1655892946: New connection from 151.28.112.81:57122 on port 8883.
1655892946: OpenSSL Error[0]: error:140373F2:SSL routines:ACCEPT_SR_KEY_EXCH:sslv3 alert unexpected message
1655892946: OpenSSL Error[1]: error:140370E5:SSL routines:ACCEPT_SR_KEY_EXCH:ssl handshake failure
1655892946: Client <unknown> disconnected: Protocol error.

Post Reply