user80062: Im trying to assign a static IP to my ESP32 and also set the host name.
I am able to get one or the other to work, but not get them to work together.
Tried moving around WiFi.hostname & WiFi.config in the code, tried WiFi.begin and then setting hostname & IP
#include <WiFi.h>
void setup() {

IPAddress local_IP(192, 168, 1, 100);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(208, 67, 222, 222);
IPAddress secondaryDNS(208, 67, 220, 220);

WiFi.mode(WIFI_STA);
WiFi.hostname("ESP");
WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS);
WiFi.begin("xxxx", "yyyy");

while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}

question in a question:
The WiFi.config that that gives me a static IP is in the format local_IP, gateway, subnet, primaryDNS, secondaryDNS but the documentation for WiFi.config 2 (and also looking at the library WiFi.h code) is ip, dns, gateway, subnet.
and according to the documentation this should also work, but doesn't WiFi.config (ip)

user4143: There is no such thing as a hostname associated with a specific device.

When you request an IP from your router using DHCP the ESP32 has the option (which it uses) to tell the router what it'd like to be called. The router may, if it chooses, decide to inject that name into DNS lookups done through the router to resolve that allocated IP address.
You can manually "advertise" a name through the mDNS protocol which requires the inclusion and use of another library and some more configuration in your sketch, along with mDNS support in the devices and applications doing the name lookup (it is getting more universally implemented but is by no means certain to be available).

Since you're not using either DHCP to obtain your IP, nor using mDNS to advertise your name, there is no mechanism that exists to magically make your device have a "name" on your network.
The simplest method to "get around" the issue is to just use DHCP and let your router do all the work. If you really want a static IP address then configure your router to provide a static IP address to your device.

80062: <p>Im trying to assign a static IP to my ESP32 and also set the host name.
I am able to get one or the other to work, but not get them to <strong>work together</strong>.</p>
<p>Tried moving around WiFi.hostname &amp; WiFi.config in the code, tried WiFi.begin and then setting hostname &amp; IP</p>
<pre><code>#include &lt;WiFi.h&gt;
void setup() {

IPAddress local_IP(192, 168, 1, 100);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(208, 67, 222, 222);
IPAddress secondaryDNS(208, 67, 220, 220);

WiFi.mode(WIFI_STA);
WiFi.hostname(&quot;ESP&quot;);
WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS);
WiFi.begin(&quot;xxxx&quot;, &quot;yyyy&quot;);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
</code></pre>
<p><strong>question in a question:</strong>
The WiFi.config that that gives me a static IP is in the format local_IP, gateway, subnet, primaryDNS, secondaryDNS but the documentation for WiFi.config 2 (and also looking at the library WiFi.h code) is ip, dns, gateway, subnet.</p>
<p>and according to the documentation this should also work, but doesn't WiFi.config (ip)</p>
 4143: <p>There is no such thing as a hostname associated with a specific device.</p>
<ul>
<li>When you request an IP from your router using DHCP the ESP32 has the option (which it uses) to tell the router what it'd like to be called. The router may, if it chooses, decide to inject that name into DNS lookups done through the router to resolve that allocated IP address.</li>
<li>You can manually &quot;advertise&quot; a name through the mDNS protocol which requires the inclusion and use of another library and some more configuration in your sketch, along with mDNS support in the devices and applications doing the name lookup (it is getting more universally implemented but is by no means certain to be available).</li>
</ul>
<p>Since you're not using either DHCP to obtain your IP, nor using mDNS to advertise your name, there is no mechanism that exists to magically make your device have a &quot;name&quot; on your network.</p>
<p>The simplest method to &quot;get around&quot; the issue is to just use DHCP and let your router do all the work. If you really want a static IP address then configure your router to provide a static IP address to your device.</p>
