ESP8266 nodemcu解析树莓派的本地dns [英] ESP8266 nodemcu resolving raspberry's local dns

查看:254
本文介绍了ESP8266 nodemcu解析树莓派的本地dns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过mqtt连接树莓派上的esp模块时遇到问题.经过大量搜索,我想我现在有点迷茫.

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.

这就是问题

我已将树莓派的本地dns设置为cubex.local,我按照此处的说明进行操作:

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

一切似乎都可以正常工作...
我可以在本地网络上使用cubex.local来通过ssh和ftp访问树莓派,但是当涉及到esp并试图解析该地址时,它会一直失败.

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.

这是在esp上运行的代码:

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)

和输出:

通过cubex.local连接到MQTT代理.请稍候...
DNS重试1!
DNS重试2!
DNS重试3!
DNS重试4!
DNS失败!
通过cubex.local连接到MQTT代理.请稍候...
DNS重试1!
DNS重试2!
DNS重试3!
DNS重试4!
DNS失败!
通过cubex.local连接到MQTT代理.请稍候...
DNS重试1!
DNS重试2!
DNS重试3!
DNS重试4!
DNS失败!

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!

主机变量保存cubex.local,端口为1883.
当我使用树莓派的IP(192.168.0.3)时,一切正常.
仍然我不明白为什么它总是无法解析地址.

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.

推荐答案

您的主机名cubex.local通过mDNS注册,但是mqtt查询DNS来解析该主机名.

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

一种选择是使用DNS代理来替代mDNS,例如 mdns-proxy ,一种是修改nodemcu以直接查询mDNS.

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.

这篇关于ESP8266 nodemcu解析树莓派的本地dns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆