485 views|0 replies

251

Posts

4

Resources
The OP
 

[Digi-Key Follow me Issue 4] Basic Task 1 Bonus: Use mDNS service to publish your own IP address to the LAN [Copy link]

 

In [Digi-Key Follow me Issue 4] Basic Task 1: Static IP Configuration, Ping, and Packet Capture Analysis, we shared the steps of basic network configuration, domain name resolution, Ping, and packet analysis on W5500_Evb_Pico.

In network applications, IP address is a very important information.

On the Internet, we can use domain names to access websites instead of remembering the corresponding IP addresses. You should know that in the early days of the Internet, many services required remembering IP addresses.

In the local area network, you can use the mDNS service to allow computers, devices or development boards to publish their own IP addresses to the local area network through the local area network name. In this way, no matter how the IP changes, you can access the network service of the development board through this specific name.

Below, I will share the specific usage steps.

1. Introduction to MDNS protocol

[Network Introduction] mDNS is multicast DNS, using port 5353 and multicast address 224.0.0.251. In a small network without a conventional DNS server, mDNS can be used to implement a programming interface, packet format, and operational semantics similar to DNS. The message structure of the MDNS protocol is the same as that of DNS, but some fields have new meanings for MDNS.

Each host that enters the LAN, if the mDNS service is turned on, will multicast a message to all hosts in the LAN, who I am and what my IP address is. Then other hosts that also have the service will respond and tell you who it is and what its IP address is. The domain name of mDNS is distinguished from the domain name of ordinary DNS by the suffix .local. If a terminal needs to access an mDNS domain name, it will send a multicast to the LAN to ask what the IP address of the domain name is.

2. Install mDNS support library

In the Arduino IDE, just install the ArduinoMDNS extension library:

3. Enable mDNS service

To enable the mDNS service, add the following code based on the previously completed network configuration:

// mDNS
#include <EthernetUdp.h>
#include <ArduinoMDNS.h>

// mDNS
EthernetUDP udp;
MDNS mdns(udp);


void setup() {
  // 修改原有的网卡初始化
  Ethernet.begin(mac);

  // 在联网成功以后,添加如下的代码
  // 开启mDNS服务
  Serial.println("mdns Begin");
  mdns.begin(Ethernet.localIP(), "arduino_pico");
  Serial.println("addServiceRecord");
}

void loop() {
  // mDNS运行检查
  mdns.run();
}

In the above code, the mDNS name arduino_pico is used to publish its own IP to the LAN.

After compiling and downloading, the running results are as follows:

4. LAN access

On other computers in the LAN, you can now use the mDNS name to access it.

In the code, use the mDNS name arduino_pico to publish its own IP to the local area network, then use arduino_pico.local to access it.

Now to ping the development board, you can use the following command:

ping arduino_pico.local

V. Conclusion

mDNS is a very useful service in a LAN environment.

This service is available on all Apple devices (Mac, MacBook, iPhone, iPad, etc.).

Many Linux boxes also provide this service.

Windows devices may not provide this by default, but if software such as iTunes is installed, this service is also provided.

Through the mDNS service, you can use this service to interact within the local area network, which will be much more convenient.

In subsequent sharing, we will also share how to use mDNS to publish WWW services.

This post is from DigiKey Technology Zone
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list