peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

Unable to subscribe (Solved) #137

Closed ebolisa closed 3 months ago

ebolisa commented 3 months ago

Hello Peter, I was wondering if can get some help on this issue since I cannot understand what I'm doing wrong.

I'm connecting to an AWS server with no error and I can publish also. However, I cannot subscribe for some reason.

These are my settings:

config['port'] = 8883
config['ssl_params'] ={'key':user_key,
                       'cert':user_cert,
                       'cadata':ca_data,
                       'server_hostname':server,
                       'server_side':False,
                       'cert_reqs':ssl.CERT_REQUIRED,
                       'do_handshake':True
                       }
config['ssid'] = readConfig('ssid')
config['wifi_pw'] = readConfig('password')
config['server'] = server  # Change to suit e.g. 'iot.eclipse.org'
config['ssl'] = True
config['subs_cb'] = sub_cb
config['wifi_coro'] = wifi_han
config['will'] = (pub_topic, 'Goodbye!', False, 0)
config['connect_coro'] = conn_han
config['keepalive'] = 120
config["queue_len"] = 1  # Use event interface with default queue size

This' the log I see:

MPY: soft reboot
3.4.0; MicroPython v1.22.2 on 2024-02-22
(name='micropython', version=(1, 22, 2, ''), _machine='Raspberry Pi Pico W with RP2040', _mpy=4614)
rp2

Connecting to: mywify
waiting for connection... trying: 9
waiting for connection... trying: 8
waiting for connection... trying: 7
Wifi connected
ip = 192.168.1.225
Time updated! <---- ntptime.timeset()
Booted!  <-- end of boot.py

Read CA Certificate... OK
Read User Certificate... OK
Read User Key... OK

Checking WiFi integrity.
Got reliable connection
Connecting to broker.
Connected to broker.
RAM free 127952 alloc 63920
RAM free 127952 alloc 63920
RAM free 127952 alloc 63920
...

At this point, I get on the server side the info I'm publishing. However, the routine below is never called therefore, the text "Subscribed" isn't shown.

async def conn_han(client):
    dprint('Subscribed')
    await client.subscribe(sub_topic,1)

Where should I start looking at? I'm using the latest mqtt_as lib. TIA

myoung34 commented 2 months ago

What was the fix? Im also not seeing any callbacks on my end for subscribe

ebolisa commented 2 months ago

What was the fix? Im also not seeing any callbacks on my end for subscribe

Sorry but I don't recall. Surely was some stupid on my side.