Skip to content

Change hostname with ethernet W5500lwIP library #8143

Closed
@MassiPi

Description

@MassiPi

Hello, turning this into an issue since i could not find a way to get this working (it is, with a wifi connection)

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git). (using later version through platformio)
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it. - No stack dump
  • I have filled out all fields below.

Platform

  • Hardware: Esp8266
  • Core Version: latest core through platformio
  • Development Env: Platformio
  • Operating System: Windows

Settings in IDE

  • Module: Wemos D1 mini
  • Flash Mode: [qio|dio|other]?
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory (platformio default)
  • Reset Method: [ck|nodemcu]?
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL and OTA
  • Upload Speed: 115200

Problem Description

Using a W5500 module with new lwIP library included in core 3.0.0
I can't get a hostname to be assigned to the device.
Not a problem assigning a hostname with a wireless connection, but with a wired one the setHostname is always failing, everywhere i put it in the script, and obviously my router sees the device with just a "-" as hostname.
This is not a mDNS issue, i'm not looking for a name.local, i'm trying to give a name to the device that my router can resolve, like i'm doing with all my other wifi esp8266 devices.
As suggested by @d-a-v , i also tried explicitly enabling the wifi with enableWiFiAtBootTime(), with and without the WiFi.mode(WIFI_OFF)
It keeps failing and i don't know how to debug this further
Thanks

Discussed in #8129

Originally posted by MassiPi June 16, 2021
Hello,
i searched both the open issues and the pull requests for setHostname() and i could not find anything, please excuse me if i lost something :)
i'm trying to change the hostname with a wired ethernet connection using the "new" W5500lwIP library.
I'm trying to use both the eth.setHostname() and the WiFi.setHostname() functions (that should be the very same and both based on the wifi_station_set_hostname())
I tried to change the hostname in various places, getting no result at all.
This is the sample code:

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <W5500lwIP.h>

byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};

const char hostname[] = "NAMETEST";

Wiznet5500lwIP eth(D1);


void setup() {
  WiFi.mode(WIFI_OFF);
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setFrequency(4000000);

  Serial.println("First: before setDefault");
  Serial.println("eth.setHostname()");
  eth.setHostname(hostname);
  Serial.println("WiFi.setHostname()");
  WiFi.setHostname(hostname);

  eth.setDefault(); // use ethernet for default route

  Serial.println("Second: before begin");
  Serial.println("eth.setHostname()");
  eth.setHostname(hostname);
  Serial.println("WiFi.setHostname()");
  WiFi.setHostname(hostname);

  int present = eth.begin(mac);
  if (!present) {
    Serial.println("no ethernet hardware present");
    while(1);
  }

  Serial.println("Third: before connected");
  Serial.println("eth.setHostname()");
  eth.setHostname(hostname);
  Serial.println("WiFi.setHostname()");
  WiFi.setHostname(hostname);

  Serial.print("connecting ethernet");
  while (!eth.connected()) {
    Serial.print(".");
    delay(100);
  }
  Serial.println("Connected");

  Serial.println("Fourth: after connection");
  Serial.println("eth.setHostname()");
  eth.setHostname(hostname);
  Serial.println("WiFi.setHostname()");
  WiFi.setHostname(hostname);

}

void loop() {

  Serial.println("Fifth: in loop");
  Serial.println("eth.setHostname()");
  eth.setHostname(hostname);
  Serial.println("WiFi.setHostname()");
  WiFi.setHostname(hostname);

  delay(5000);
}

This is what i get:

First: before setDefault
eth.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
WiFi.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
Second: before begin
eth.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
WiFi.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
Third: before connected
eth.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
WiFi.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
connecting ethernet.Connected
Fourth: after connection
eth.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
WiFi.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
Fifth: in loop
eth.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed
WiFi.setHostname()
WiFi.hostname(NAMETEST): wifi_station_set_hostname() failed

what am i missing?
is there a way to further debug this?
thanks!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions