Go Down

Topic: mDNS, Bonjour, register a hostname (Read 333 times) previous topic - next topic

Murtle

Hello, I've been struggling with this for a while now. If say I plug a network printer onto my network and then search the network for IP address and host names I can see for example HP-Laser-Printer.home This works whether directly connected to my PC or via a router with DHCP.  I would like my Arduino to act in the same way, but for the life of me I am unable to do this. All it does is report the host name as WIZnet and then the last 3 bytes of the mac address. 


Using EthernetBonjour3, and settings such as: #define HOST_NAME "xxxxx"; or EthernetBonjour.begin("xxxxx"); do not work, I still see WIZnet + mac.

Hardware is STM32F103 blue pill and Wiznet w5500 SPI board. I've try'd adjusting settings in the Dhcp.h and Dhcp.cpp files, all to no success. This along with re-setting the router and even deleting the data it has for the mac address.

Is there an mDNS / Bonjour setting or service I'm missing, or more to the point does someone have a code example that actually works?

Cheers

pylon

Quote
Using EthernetBonjour3, and settings such as: #define HOST_NAME "xxxxx"; or EthernetBonjour.begin("xxxxx"); do not work, I still see WIZnet + mac.
The default of EthernetBonjour is the string provided by the begin() method and ".local" added. Where do you see that WizNet-MAC-combo? In the DHCP server logs?

Post the code that leads to the described effect! (don't forget the code tags, that's the </> button in the editor)

Murtle

#2
Mar 26, 2019, 01:58 pm Last Edit: Mar 26, 2019, 02:14 pm by Murtle
Thank you for the comments pylon,

Yes, I see WIZNet-EFFEED in my router DHCP log and if I run a network device search. This does not change regardless of what code I call or example I use.

There is no code leading to the effect, it's more that every code example I've tried does not change the default hostname. it all has no effect. I can see in the Dhcp.h file the cause, but am unable to create a fix.

Dhcp.h
Code: [Select]
#define HOST_NAME "WIZnet"

Dhcp.cpp
Code: [Select]
    // OPT - host name
    buffer[16] = hostName; // was hostName
    buffer[17] = strlen(HOST_NAME) + 6; // WAS + 6 length of hostname + last 3 bytes of mac address
    strcpy((char*)&(buffer[18]), HOST_NAME);

    printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
    printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
    printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);


No amount of fafing around with this achieves anything other than the device either not appearing on the DHCP list, or defaulting to WIZnet + MAC.


If I plug in another network enabled device (Printer, NAS drive, Scanner, LXI test equipment) I see its name displayed, and this is regardless of wether it's Static or DHCP. Why can the W5500 not do this?

Perhpas the hardware is not capable, and if so what should I be using. If I could just find a working example (code and hardware) then that would be a start.

pylon

Quote
Yes, I see WIZNet-EFFEED in my router DHCP log and if I run a network device search. This does not change regardless of what code I call or example I use.
That's completely unrelated to mDNS/Bonjour. The DHCP code is in the Ethernet library and the host identification used there is not available as a parameter. If you think you must change it you have to modify the Ethernet library. The WizNet part is defined in Dhcp.h, the rest is a part of the MAC address.

Quote
Perhpas the hardware is not capable, and if so what should I be using. If I could just find a working example (code and hardware) then that would be a start.
Usually nobody cares about the DHCP identifier as it's not used for anything else than logging. So why do you care about it?

Murtle

As I've said before, when you plug in a network device such as printer, regardless of static or DHCP IP it still shows on the network with a name thats relevant to the make and model. How do I get my project to do this?
   I absolutely do not want it reporting WIZnet-mac. I want it to show my chosen name .local

pylon

Quote
As I've said before, when you plug in a network device such as printer, regardless of static or DHCP IP it still shows on the network with a name thats relevant to the make and model. How do I get my project to do this?
Define "shows on the network"! Is the meaning still "shows with that name in the DHCP log"? By default it shows up on the network only with it's MAC address. Everything else needs some kind of protocol action. But as you've already seen there are many ways to show up on a network with a name and depending on the protocol used the way to get there is different (DHCP-ID, Bonjour/mDNS name, (reverse) DNS name, WINS name, etc.).

Murtle

#6
Mar 29, 2019, 03:00 pm Last Edit: Mar 29, 2019, 03:02 pm by Murtle
Hi Pylon, and thank you so much for taking the time to answer.

You are correct, and I need to revise what I'm saying.  I need mDNS/Bonjour to report a .local network name. I need the device regardless of DHCP or Static to still display this name. I want all trace of WIZNet-mac to be removed from all naming protocols (DHCP-ID, Bonjour/mDNS name, (reverse) DNS name, WINS name, etc).

Hardware is:
STM32F103C8T6 and W5500 connected via SCP.

Open ports for TCP and UDP are:
80, 111, 5025, 5044

Bellow is what I currently see, or the red box is filled with WIZnet-mac.  I want it to report the name of my choice.



pylon

Quote
I want all trace of WIZNet-mac to be removed from all naming protocols (DHCP-ID, Bonjour/mDNS name, (reverse) DNS name, WINS name, etc).
Why? Why is this so important to you?

Quote
I need mDNS/Bonjour to report a .local network name. I need the device regardless of DHCP or Static to still display this name.
The EthernetBonjour.begin() call is supposed to do exactly that. What do you get with a Bonjour/mDNS scanner if you run that sketch on your board?

Quote
Bellow is what I currently see, or the red box is filled with WIZnet-mac.  I want it to report the name of my choice.
Do you need it exactly for that scanner? As far as I found information on the Net about this scanner it uses a proprietary algorithm to get these "Hostname"s, so it might do several things and display any name. Ask the vendor about what exactly the scanner does in what order to be able to provide the correct name for that scanner.

To change the DHCP identifier, change the Ethernet library (Dhcp.cpp) as follows:

Code: [Select]

#define MY_CUSTOM_DHCP_ID "Arduino"
// OPT - host name
buffer[16] = hostName;
buffer[17] = strlen(MY_CUSTOM_DHCP_ID);
strcpy((char*)&(buffer[18]), MY_CUSTOM_DHCP_ID);

//printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
//printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
//printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);

Murtle

#8
Apr 01, 2019, 11:23 am Last Edit: Apr 01, 2019, 11:29 am by Murtle
Thank you for getting back to me again Pylon.

Renaming is important as I have many projects all on the one network, I do not want to see a list of WIZnet-mac host names then have to decipher which was which, I want to see my project name in what ever way I choose to search. If it were a commercial product it most defiantly would have the manufactures name for every type of search and not display the Ethernet interface manufacturer.

If I call EthernetBonjour.begin() I still get WIZnet-mac.local

A cut down version of the code:
Code: [Select]
/*
 =========================================================
 <---- Pinout ---->
 W5500 <--> STM32F103
 SS    <-->  PA4 <-->  BOARD_SPI1_NSS_PIN   (declared below)
 SCK   <-->  PA5 <-->  BOARD_SPI1_SCK_PIN
 MISO  <-->  PA6 <-->  BOARD_SPI1_MISO_PIN
 MOSI  <-->  PA7 <-->  BOARD_SPI1_MOSI_PIN
 =========================================================
 */

#include <SPI.h>
#include <Ethernet_STM.h>
#include <EthernetUdp.h>
#include <EthernetBonjour3.h>


byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};            // Enter a MAC address
IPAddress ip(192,168,0,177);                                  // The IP address will be dependent on the local network
#define SPI1_NSS_PIN PA4                                      // SPI_1 Chip Select pin is PA4. You can change it to the STM32 pin you want.char
SetHostName[] = "My-Project";                                    // Set hostname
#define HOST_NAME "My-Project";                                   // Set hostname

SPIClass SPI_1(1);                                            // Create an instance of the SPI Class called SPI_1 that uses the 1st SPI Port

EthernetUDP Udp;                                              // Rename the UDP server
                                                             
EthernetServer server1(80);                                   // HTTP          Initialize the Ethernet server librarys
EthernetServer server2(111);                                  // VXI-11        Initialize the Ethernet server librarys

void setup() {
  Serial.begin(9600);                                         // Open serial communications and wait for port to open:
   while (!Serial) {
    ;                                                         // Wait for serial port to connect
  }

  Serial.println("Trying to get an IP address using DHCP");
  if (Ethernet.begin(mac) == 0) {                             // start the Ethernet connection:
    Serial.println("Failed to configure Ethernet using DHCP");
     Ethernet.begin(mac, ip);                                 // initialize the Ethernet device not using DHCP:
         for (;;)
      ;
  }

  server1.begin();                                            // Start Server1 for HTTP           port 80
  server2.begin();                                            // Start Server2 for VXI-11         port 111
  EthernetBonjour.begin("My-Project");                        // Initialize the Bonjour/MDNS library, always call this before any other method!
  int length = 10;
  if (!EthernetBonjour.isResolvingName()) {
    if (length > 0) {   
      byte ipAddr[4];
      Serial.print("Resolving '");
      Serial.print(SetHostName);
      Serial.println("' via Multicast DNS (Bonjour)...");
      EthernetBonjour.resolveName(SetHostName, 5000);
    } 
  }
  Serial.println("Ready");

 }

  void loop() {
  EthernetBonjour.run();
  EthernetClient client1 = server1.available();               // Listen for incoming client on port 80
  EthernetClient client2 = server2.available();               // listen for incoming client on port 111

pylon

In my tries with an adapted version of your code (I used EthernetBonjour instead of EthernetBonjour3 because the latter uses the Ethernet3 library which doesn't work on my system) I had no problems, setting a correct mDNS name (I used "arduino" and the Arduino was accessible by the name "arduino.local") as well as changing the DHCP-ID in the Dhcp.h file. Keep in mind that you have to reboot your PC/router after every change you made to the values as the mDNS stuff is kept for a longer time period, otherwise you might be presented older values.
.
I don't know what you have to change to make this work on the STM platform as this platform seems not to use the standard Ethernet library but it's own variant Ethernet_STM.

Murtle

Well with your help Pylon, I have resolved the issue, I modified the Dhcp.cpp and Dhcp.h files in the Ethernet_STM as follows:

.cpp file
Code: [Select]

 // OPT - host name
    buffer[16] = hostName;
    buffer[17] = strlen(HOST_NAME); //was buffer[17] = strlen(HOST_NAME) + 6;
    strcpy((char*)&(buffer[18]), HOST_NAME);

    //printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
    //printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
    //printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);



.h file
Code: [Select]

#define HOST_NAME "My-Required-Name" //ORIGINALLY #define HOST_NAME "WIZnet"


And also using within my arduino app for mDNS:
Code: [Select]

EthernetBonjour.begin("My-Required-Name");                        // Initialize the Bonjour/MDNS library, always call this before any other method!
EthernetBonjour.addServiceRecord("My-Required-Name._http", 80, MDNSServiceTCP);
EthernetBonjour.addServiceRecord("My-Required-Name._vxi-11", 111, MDNSServiceTCP);


All is working perfectly, and with every search app the correct data is displayed.

Go Up