Raspberry Pico W MQTT client -- Local Mosquitto Broker Connection problem #10306
Replies: 3 comments
-
I don't know the answer but this module has been tested with the Pico W. Alternatively you could raise an issue against the library you are using. |
Beta Was this translation helpful? Give feedback.
-
I did a complete "makeover" and replaced the mqtt-module with your mqtt_as.py module & now everything works just fine (both for ESP32 & RPi PICO W), so THANK YOU !!!! Regarding the mqtt_as.py routine : Question #1 : Now as the WiFi part is "built-in" into your module, how can I access this info (IP/mask/GW/DNS & MAC) ?? Question #2 : I have my PUB & SUB topics specified as strings like : As the mqtt_as-module expects them as byte strings i am converting them using : This works fine for publish, but for subscribe I have to use the string name : Is there a difference (or just me having more bad luck :-) .... |
Beta Was this translation helpful? Give feedback.
-
You don't need these details to run Re strings/bytes see the docs and the test scripts. If you do need to convert between strings and bytes use |
Beta Was this translation helpful? Give feedback.
-
For quite some time I have used ESP32 boards running MicroPython and the MQTT client from :
https://github.com/leiyong711/micropython-mqtt-1/blob/master/src/mqtt.py
connecting to a local Mosquitto MQTT broker (running on a Raspberry Pi 4).
This has been working perfectly for the ESP32, but when trying the same (simple) program on a Raspberry Pico W it won't connect/stay connected to the local Mosquitto broker.
.
The client message i get is :
Connecting to MQTT broker....
Exception caught opening MQTT socket: OSError(113,)
Connecting to MQTT broker....
Exception caught opening MQTT socket: OSError(113,)
etc.
The Client software code is simply a copy of the github/leiyong711/... mqtt example code...
_import micropython
from libs.mqtt import MQTTClient
def puback_cb(msg_id):
print('PUBACK ID = %r' % msg_id)
def suback_cb(msg_id, qos):
print('SUBACK ID = %r, Accepted QOS = %r' % (msg_id, qos))
def con_cb(connected):
if connected:
client.subscribe('subscribe/topic')
def msg_cb(topic, pay):
print('Received %s: %s' % (topic.decode("utf-8"), pay.decode("utf-8")))
client = MQTTClient('192.168.1.1', port=1883)
client.set_connected_callback(con_cb)
client.set_puback_callback(puback_cb)
client.set_suback_callback(suback_cb)
client.set_message_callback(msg_cb)
client.connect('my_client_id')
while True:
if client.isconnected():
try:
pub_id = client.publish('publish/topic', 'payload', False)
except Exception as e:
print(e)
utime.sleep_ms(1000)_
---------------------------------------
I am using the same settings on the Pico W as on the ESP32, I am on the same subnet, I have tried with/without anonymous logins, checked qos, timeout etc. etc. but the Pico W just won't connect/stay connected.
I have updated the Pico W with the latest firmware (20221220), and the Mosquitto Broker version is 2.0.11
The output from the mosquitto log file is :
671721470: New client connected from 192.168.0.128:56930 as 29 (p2, c1, k60, u'gurra').
immediately followed by :
1671721470: Client 29 closed its connection.
I have also tried connecting the Pico W to my local Home Assistant MQTT Broker with the same result (the ESP32 logs in just fine, but not the Pico W)...
How do I get on here ???
Beta Was this translation helpful? Give feedback.
All reactions