ESP8266 nodemcu resolving raspberry's local dns

别等时光非礼了梦想. 提交于 2019-12-12 06:36:55

问题


I'm having an issue with connecting the esp module on the raspberry via mqtt. After a lot of search I think I am kinda lost now.

So here's the problem

I have setup my raspberry's local dns to work as cubex.local, I followed the instructions here:

http://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/

Everything seems to be working fine on this end...
I can use the cubex.local on the local network to have ssh and ftp access to the raspberry but when it comes to the esp trying to resolve that address it keeps failing.

this is the code running on the esp:

function broker_connect()
 m = mqtt.Client(ID, 120, BRUSER, BRPWD)
 m:on("message", on_message_received)
 m:on("connect", on_connect)
 m:on("offline", on_mqqt_offline)

 tmr.alarm(0, 1000, 1,function() 
 print("Connecting to MQTT broker at "..HOST..". Please wait...")
 m:connect( HOST , PORT, 0)
end)

and the output:

Connecting to MQTT broker at cubex.local. Please wait...
DNS retry 1!
DNS retry 2!
DNS retry 3!
DNS retry 4!
DNS Fail!
Connecting to MQTT broker at cubex.local. Please wait...
DNS retry 1!
DNS retry 2!
DNS retry 3!
DNS retry 4!
DNS Fail!
Connecting to MQTT broker at cubex.local. Please wait...
DNS retry 1!
DNS retry 2!
DNS retry 3!
DNS retry 4!
DNS Fail!

The host variable holds the cubex.local and the port is 1883.
When I use the raspberry's IP which is 192.168.0.3 everything works fine.
Still I fail to understand why it keeps failing to resolve the address.


回答1:


Your hostname cubex.local is registered through mDNS, but mqtt query a DNS to resolve the hostname.

One option could be to use a DNS proxy to mDNS like mdns-proxy, an other one is to modify nodemcu to query the mDNS directly.



来源:https://stackoverflow.com/questions/37938454/esp8266-nodemcu-resolving-raspberrys-local-dns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!