How to resolve ESP32 AP to a name?

uTasker
Posts: 19
Joined: Mon Mar 15, 2021 10:15 pm

How to resolve ESP32 AP to a name?

Postby uTasker » Fri May 12, 2023 3:37 pm

Hi All

I have an ESP32-S2-MINI and have a web server on port 80.
To connect to it I use (from a browser)
http://192.168.4.1

It is possible to use some technique to be able to browse to it by name instead of its IP address?

Eg.

http://MyESP32

(I have used NetBios to do something similar in the past on Ethernet)

Thanks in advance.

Regards

Mark

username
Posts: 536
Joined: Thu May 03, 2018 1:18 pm

Re: How to resolve ESP32 AP to a name?

Postby username » Sat May 13, 2023 3:36 am


uTasker
Posts: 19
Joined: Mon Mar 15, 2021 10:15 pm

Re: How to resolve ESP32 AP to a name?

Postby uTasker » Sun May 14, 2023 3:42 pm

Hi

If I use the standard ESP32-AT is this possible?

Regards

Mark

esp-at
Posts: 200
Joined: Mon May 09, 2022 3:00 am

Re: How to resolve ESP32 AP to a name?

Postby esp-at » Mon May 22, 2023 3:58 am

Yes, standard ESP32-AT firmware has already include mDNS command.
For example, if you set the mDNS service by command: AT+MDNS=1,"espressif","_iot",80
and start a web server on port 80.
then after your mobile phone connected to ESP32's AP, open the browser and visit http://espressif.local, it's same to visit the http://192.168.4.1

uTasker
Posts: 19
Joined: Mon Mar 15, 2021 10:15 pm

Re: How to resolve ESP32 AP to a name?

Postby uTasker » Fri May 26, 2023 10:26 pm

Hi

Many thanks!!!

I tried
AT+MDNS=1,"espressif","_iot",80
and that did allow connecting on the ULR espressif.local

I haven't yet understood what the "_iot" means but this is a good start since it is much better than needing to know the IP address!

Regards

Mark

esp-at
Posts: 200
Joined: Mon May 09, 2022 3:00 am

Re: How to resolve ESP32 AP to a name?

Postby esp-at » Mon May 29, 2023 3:35 am

"_iot" is just a demo, it indicates the service type that the host can serves. The real service type, you can refer to http://www.dns-sd.org/serviceTypes.html for more details.
once you set it, this service type should be in mDNS query and mDNS query response packets.

Read the mDNS services doc: https://docs.espressif.com/projects/esp ... index.html for more details.

~

uTasker
Posts: 19
Joined: Mon Mar 15, 2021 10:15 pm

Re: How to resolve ESP32 AP to a name?

Postby uTasker » Tue May 30, 2023 10:15 am

Hi

Thank you.
It sounds that when using port 80 "http" would be the better service type entry to use.

Presently, although the resolution is working, it is taking about 15s before it operates. I retested with "http" set but it didn't seem to make any difference and it still takes a long time before it connection. In addition it often also stops responding (and takes again 15s before it continues) - but works normally if I use the IP address.

Although it works from my PC it doesn't work from my Android phone.

I'll keep investigating but presently the operation is not adequate for real use based on experiences to date.

Regards

Mark

uTasker
Posts: 19
Joined: Mon Mar 15, 2021 10:15 pm

Re: How to resolve ESP32 AP to a name?

Postby uTasker » Tue May 30, 2023 10:48 am

Hi

After experimenting with different service types I find no change in behavior.

Also I have monitored the mDNS process and don't see that it is used in any of the queries or replies.

The problem at the moment is the time it takes to resolve - the browser spins for about 15s before it connects.
Then, after a short time of non-use it has to resolve again and the browser again spins for about 15s until it resolves again.

However i don't think it is a problem with the mDNS operation in the ESP since it does immediately respond with a "cache flush 192.168.4.1" but the PC only actually uses it after a number or repetitions.
I also see that the ESP32 gives the address only 2 minutes to live and this is probably why it keeps having to re-resolve, causing the subsequent slowness.

Regards

Mark

uTasker
Posts: 19
Joined: Mon Mar 15, 2021 10:15 pm

Re: How to resolve ESP32 AP to a name?

Postby uTasker » Tue May 30, 2023 10:52 am

Hi

Another point.

I don't see why the TCP port is required as a parameter since I also see no reference to the TCP port during the mDNS resolution.

Regards

Mark

esp-at
Posts: 200
Joined: Mon May 09, 2022 3:00 am

Re: How to resolve ESP32 AP to a name?

Postby esp-at » Mon Jun 05, 2023 1:03 pm

i tried the mdns, and it seems work well on my side.


1. About the "TCP port is required as a parameter"
For a well-designed application protocol, the SRV record has a name of the form "<Instance>.<Service>.<Domain>"
and gives the target host and port where the service instance can be reached. you can refer to RFC6763 for more details.
About the port resolution, you can refer to RFC6763 section 5.

2. About the "ESP32 gives the address only 2 minutes to live".
IMHO, i don't think this is a place that affects latency or functionality. in RFC6762, section 10. it said:
"As a general rule, the recommended TTL value for Multicast DNS resource records with a host name as the resource record’s name
(e.g., A, AAAA, HINFO) or a host name contained within the resource record’s rdata (e.g., SRV, reverse mapping PTR record) SHOULD
be 120 seconds." so, it's reasonable for mdns. of course, you can change this TTL value at file:

Code: Select all

esp-at/managed_components/espressif__mdns/private_include/mdns_private.h (L70 to L72)
In addition, capturing packets through wireshark, reading mDNS related protocols, and debugging mDNS (esp-at/managed_components/espressif__mdns) code may help quickly analyze mDNS issues.

Who is online

Users browsing this forum: No registered users and 22 guests