Skip to content

WiFi Hostname is only set when changing mode to WIFI_MODE_STA #7227

Closed
@tbnobody

Description

@tbnobody

Board

generic

Device Description

Hardware Configuration

No

Version

v2.0.4

IDE Name

VSCode with PlatformIO

Operating System

Windows 11

Flash frequency

PSRAM enabled

no

Upload speed

115200

Description

There are several issues in issue trackers out there in the internet which are stating that the hostname is not set correctly. When diving deeper into the library, it seems that the hostname is only set on one location:

err = set_esp_interface_hostname(ESP_IF_WIFI_STA, get_esp_netif_hostname());

That means set a call of WiFi.setHostname() does nothing in the first step. It's not even enough to call WiFi.mode(WIFI_MODE_STA); if the mode was already WIFI_MODE_STA. Because if current mode equals new mode:


no changes are applied.

To set the hostname correctly the following snippet has to be used:

WiFi.mode(WIFI_MODE_APSTA); // or any other mode
WiFi.setHostname("asdf");
WiFi.mode(WIFI_MODE_STA);

If the behavior is known to the user of the class it's simple to use but it's a little bit unintuitive. Does it make sense to at least document this behavior?

Sketch

-

Debug Message

-

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Area: BT&WifiBT & Wifi related issuesType: DocumentationIssue pertains to Documentation of Arduino ESP32

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions