更改本地网络上网页的 url
我在 ESP32 芯片上构建了一个网页,负责创建一个接入点,允许我的计算机连接以访问此页面。
目前我只能通过在浏览器中输入 ESP 的 IP 来访问它,但这可能非常麻烦。
我想知道是否可以使用文字而不是 ESP 的 IP 来更改页面的 url。
也许我遗漏了一些技术术语,但我在互联网上没有找到任何解决方案。
PS:我使用 micropython 和套接字来从板上提供 html 文件:
def handleClient(client_socket):
headers, data = loadRequest(client_socket.recv(1024).decode('utf-8'))
# print('[*] Received:\n%s\n%s\n' % (headers, data))
if headers['method'] == 'GET' and '/connect' == headers['route']:#'/connect' in headers['route']:
ssid, password, status, code = connect(headers)
client_socket.sendall(RESPONSE_TEMPLATE % (code, status, {'ssid': ssid, 'password': password}, code))
return ssid, password
elif headers['method'] == 'GET' and headers['route'] == '/':
renderWebPage(client_socket)
client_socket.close()
return None, None
I built a webpage on an ESP32 chip, charged to create an access point allowing my computer to connect in order to access this page.
For the moment I can only access it using the IP of my ESP by typing it in a browser but it can be very bothersome.
I'd like to know if it was possible to change the url of the page using words instead of the ESP's IP.
Maybe I'm missing some technical terms but I didn't find any solution on the internet.
PS: I'm using micropython with sockets to serve html files from the board:
def handleClient(client_socket):
headers, data = loadRequest(client_socket.recv(1024).decode('utf-8'))
# print('[*] Received:\n%s\n%s\n' % (headers, data))
if headers['method'] == 'GET' and '/connect' == headers['route']:#'/connect' in headers['route']:
ssid, password, status, code = connect(headers)
client_socket.sendall(RESPONSE_TEMPLATE % (code, status, {'ssid': ssid, 'password': password}, code))
return ssid, password
elif headers['method'] == 'GET' and headers['route'] == '/':
renderWebPage(client_socket)
client_socket.close()
return None, None
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决您的问题需要两个部分:
MicroPython 自 v1.12 起内置了对
mdns
的支持。基本代码是使用以下代码分配主机名:
请注意,您的客户端还需要有 mdns 支持才能解析该地址。这可能/将取决于您的客户。
完整的示例如下:
来源:MicroPython 论坛
there are two parts needed to solve your Q:
MicroPython has built-in support for
mdns
since v1.12.The essential code is to assign a hostname using the below:
Note that your client also needs to have mdns support in order to be able to resolve that address. That may/will depend on your client.
a complete sample would be:
Source: MicroPython Forum
当然。最简单的选项是启用 mDNS 。这允许同一本地网络中的主机将设备名称(例如
espressif.local
)解析为其IP。仅适用于本地网络,并且需要在计算机上安装 mDNS 客户端(Mac、Linux 和 Windows 现在都倾向于内置它)。但不知道如何在 Micropython 中做到这一点。尝试一下谷歌。
Certainly. The easiest option is enabling mDNS. This allows hosts in the same local network to resolve the device's name (e.g.
espressif.local
) into its IP. Only works in local network and requires an mDNS client on the computer (Mac, Linux and Windows all tend to have it built in these days).No idea how to do it in Micropython, though. Give Google a try.