set hostname using static IP



  • Hi,
    I'm new here, and I did not find any search feature, and I could no find anything with google in this topic.

    Hi, I have a lot of ESP32 devices with static IP. Is it possible to set hostname for them?
    I have a TP-Link DECO system, I see the devices but the hostname like this: "Device_29D0", and the MAC does not match to the give one (in MY_MAC_ADDRESS).

    I found this, but as I see it is only for DHCP.
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_HOSTNAME "my_custom_hostname"

    What did I wrong? πŸ™‚
    Is this any possibility?

    Thanks,
    SH



  • @sandorhoffmann I hope there is someone that can answer your question.

    But, I really recommend using DHCP. In that way, you can control all of your IPaddresses in one place, your DHCP server (almost always, your router)

    The huge advantage of ESP devices over Arduino is the WiFi. You don't need a big library. The MAC address is hard coded at the factory. I'm not sure that you can change it, which you would want to do if a device failed and you need an EXACT replacement.

    The downside of ESP is also the WiFi. Most home routers can only handle 20-30 WiFi devices My Asus routers start dropping WiFi devices resulting in difficult reconnects. The network becomes unusable. Because I have many ESP devices, I employed a Ubiquity access point that can handle 300 WiFi devices. The routers can handle 254 (253?) IP assignments, though some only allow 64 DHCP assignments.

    There is a discussion on this forum someplace on the number of clients there can be in a MySensors network. In theory 254 (253?) is the max, though I am unaware if anyone has tested it. I use an RPi as my gateway and haven't had problems with too many devices. If one is considering a very large number I would recommend starting each sensors one at a time because the gateway way will assign the NodeID which gets written into location 0 of the EEPROM. Or burn a NodeID into the Arduino EEPROM before running the actual code.

    bottom line, you didn't do anything wrong, its the nature of the beast.


  • Contest Winner

    I did a grep on the source code and found this snipper

    #if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
    	// Turn off access point
    	WiFi.mode(WIFI_STA);
    #if defined(MY_GATEWAY_ESP8266)
    	WiFi.hostname(MY_HOSTNAME);
    #elif defined(MY_GATEWAY_ESP32)
    	WiFi.setHostname(MY_HOSTNAME);
    #endif
    #if defined(MY_IP_ADDRESS)
    	WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
    #endif /* End of MY_IP_ADDRESS */
    	(void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
    #endif
    

    MySensors uses the standard ESP libraries for this. So I expect it to work. But you need to provide at least a bit of source code. Right now it's hard to answer your question. Regarding to MySensors:

    • A HTTP hostname can only be set for Gateways that either use Wifi or Ethernet
    • For nodes you can provide a sketchname and that will be seen in your controller.

    Regarding to static non static IP addresses. I prefer to use DHCP and set that device in my router as a static IP. There I also give it another hostname. So that in case I have to replace my Gateway I can do it all in the router.

    Hope this helps. But please provide more info on what you're trying to achieve



Suggested Topics

  • 1
  • 2
  • 1
  • 210
  • 13
  • 92
  • 1
  • 116

31
Online

11.7k
Users

11.2k
Topics

113.0k
Posts