Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

MQTT With Local Server
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

MQTT With Local Server

by yyjdennis on Sat Nov 28, 2020 8:17 pm

Does anyone have an example of using the Adafruit MQTT library with a local MQTT server? I think I just have to replace the Adafruit IO url with my server's ip address and port, but I must be messing up the syntax somehow.

yyjdennis
 
Posts: 6
Joined: Sat Jun 27, 2020 5:02 pm

Re: MQTT With Local Server

by brubell on Mon Nov 30, 2020 11:29 am

An example for this doesn't exist - we use the Adafruit IO server because it's a reliable server and people don't have to set it up.

I've used this library with a local mosquitto broker before. I do not know what error you're receiving, could you please post your code incl. the output from the serial monitor?

brubell
 
Posts: 1381
Joined: Fri Jul 17, 2015 10:33 pm

Re: MQTT With Local Server

by matterantimatter on Fri Dec 25, 2020 8:32 am

I'm having a similar problem. I'm trying to connect to a local MQTT server that has no hostname (just port and IP address). When I store the IP address in the secrets.py broker entry, as a string, it appears that the esp32spi's socket module is trying to interpret it as name (it dies on a call to get_host_by_name()).

I've tried placing a tuple of the IP address in the secrets file, and embedding it directly in the code, and that doesn't work either.

I can call the esp.ping() method by IP address, but something in the call stack of the MQTT.connect() method is trying to look up the IP address by name.

matterantimatter
 
Posts: 5
Joined: Sat Nov 29, 2014 12:21 pm

Re: MQTT With Local Server

by matterantimatter on Mon Dec 28, 2020 3:12 pm

I figured out my issue. I had missed the
wifi.connect()
statement. It's the wireless equivalent of "did you check the cables?"

matterantimatter
 
Posts: 5
Joined: Sat Nov 29, 2014 12:21 pm

Please be positive and constructive with your questions and comments.