Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5196

MicroPython • Re: MQTT on Pico W with broker on Pi - How to connect to broker ?

$
0
0
(But since the OP is normally insightful and resilient I may be missing some deeper significance to the question... )
Possibly that I am running on a Pico W, and using MicroPython, so the usual tools one might use from the command line on a host aren't available.

It seems the 'socket.getaddrinfo(self.server, self.port)' under the hood, a prerequiste to establishing a connnection, can handle named IP Addresses, can lookup internet URL, but doesn't handle an 'mDNS' lookup to find the "Pi3B.local" in my case.

I could write my own code to issue an 'mDNS' lookup packet, handle the reply, but was thinking there must be some other easier way I don't know about, haven't seen. I was sure others must have needed similar, but perhaps not, have usually used Fixed IP as I have.

This is what I would normally use -

Code:

import socketaddr = socket.getaddrinfo("Pi3B.local", 1884)for n in range(0, 5):  print("[{}] =".format(n), addr[0][n])
And that works fine on the Pi ...

Code:

[0] = AddressFamily.AF_INET[1] = SocketKind.SOCK_STREAM[2] = 6[3] =[4] = ('192.168.0.130', 1884)
For the PIco W, where line 40 is my 'socket.getaddrinfo()' ...

Code:

Traceback (most recent call last):   File "<stdin>", line 40, in <module>OSError: -2

Statistics: Posted by hippy — Tue Jul 23, 2024 1:22 pm



Viewing all articles
Browse latest Browse all 5196

Trending Articles