-->
Page 3 of 5

Re: WiFi.hostname doesn work

PostPosted: Tue Aug 15, 2017 11:58 am
by rudy
Don't add it if you don't want it.

sprintf(HostName, "MyESPAP");

Re: WiFi.hostname doesn work

PostPosted: Tue Aug 15, 2017 12:48 pm
by KDB
The question is : does it work !!
In my configuration it doesn't !!!

rudy wrote:Don't add it if you don't want it.

sprintf(HostName, "MyESPAP");

Re: WiFi.hostname doesn work

PostPosted: Wed Aug 16, 2017 11:51 am
by martinayotte
Yes, it works ...

Re: WiFi.hostname doesn work

PostPosted: Thu Aug 17, 2017 12:37 pm
by KDB
Hi marinayotte !

Do you see my mistake ?
Never had such problems with a simple program :

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>

const char* ssid = "********";
const char* password = "*********";
char hostString[16] = {0};

// TCP server at port 80 will respond to HTTP requests
WiFiServer server(80);

void setup(void)
{
Serial.begin(115200);
sprintf(hostString, "ESP_%06X", ESP.getChipId());
Serial.print("Hostname: ");
Serial.println(hostString);
WiFi.hostname(hostString);

// Connect to WiFi network
WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());


if (!MDNS.begin(hostString)) {
Serial.println("Error setting up MDNS responder!");
while(1) {
delay(1000);
}
}
Serial.println("mDNS responder started");

// Start TCP (HTTP) server
server.begin();
Serial.println("TCP server started");

// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
}









martinayotte wrote:What do you mean "not working" ?

Does your router shows that ESP3 hostname in the IP leases list ?

Don't expect to be able to do "ping ESP3", it won't work since the DNS doesn't know this hostname.
Use mDNS service on your ESP, install Bonjour on Windows, and then "ESP3.local" will be resolved.