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)