-->
Page 1 of 1

give a name to your ESP...

PostPosted: Tue Nov 25, 2014 2:47 pm
by kingfisher
if you want to give a name to your device...

in lwip/core/dhcp.c
add this function

Code: Select all#include "user_interface.h"

char* hostname()
{
        //the name is your SSID... eventually here you can return any string
        // return "ESP8266";

   static struct softap_config apConfig;
   wifi_softap_get_config(&apConfig);
   return apConfig.ssid;
}


and in functions dhcp_select modify, dhcp_renew, dhcp_rebind

change this
Code: Select all#if LWIP_NETIF_HOSTNAME
    if (netif->hostname != NULL) {
      const char *p = (const char*)netif->hostname;
      u8_t namelen = (u8_t)strlen(p);
      if (namelen > 0) {
        LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
        dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
        while (*p) {
          dhcp_option_byte(dhcp, *p++);
        }
      }
    }
#endif /* LWIP_NETIF_HOSTNAME */

into this
Code: Select all      const char *name = hostname();
      u8_t namelen = (u8_t)strlen(name);
      if (namelen > 0) {
        LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
        dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
        while (*name) {
          dhcp_option_byte(dhcp, *name++);
        }
      }

Re: give a name to your ESP...

PostPosted: Tue Nov 25, 2014 3:12 pm
by Bananis
This is great!

Thanks!

/Bananis

Re: give a name to your ESP...

PostPosted: Fri Sep 30, 2016 6:20 pm
by mano1979
Will this code also add the ability to connect (through local network) from one esp8266 to other esp8266's with a hostname instead of ip?