ESP32: include mac in hostname

This commit is contained in:
folkert van heusden 2024-05-05 20:18:36 +02:00
parent 37f320c353
commit 556ccfeecd
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1

View file

@ -121,7 +121,13 @@ bool save_serial_speed_configuration(const uint32_t bps)
#if !defined(BUILD_FOR_RP2040) #if !defined(BUILD_FOR_RP2040)
void set_hostname() void set_hostname()
{ {
WiFi.setHostname("PDP-11"); uint64_t mac = ESP.getEfuseMac();
uint8_t *chipid = reinterpret_cast<uint8_t *>(&mac);
char name[32];
snprintf(name, sizeof name, "PDP11-%02x%02x%02x%02x", chipid[2], chipid[3], chipid[4], chipid[5]);
WiFi.setHostname(name);
} }
void configure_network(console *const c) void configure_network(console *const c)
@ -150,6 +156,8 @@ void configure_network(console *const c)
return; return;
} }
c->put_string_lf(format("Connecting to SSID \"%s\"", parts.at(0).c_str()));
if (parts.size() == 1) if (parts.size() == 1)
WiFi.begin(parts.at(0).c_str()); WiFi.begin(parts.at(0).c_str());
else else
@ -184,8 +192,6 @@ void check_network(console *const c)
void start_network(console *const c) void start_network(console *const c)
{ {
set_hostname();
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.useStaticBuffers(true); WiFi.useStaticBuffers(true);
WiFi.begin(); WiFi.begin();
@ -249,6 +255,9 @@ void setup() {
#if defined(ESP32) #if defined(ESP32)
heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook); heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook);
#endif #endif
#if defined(ESP32)
set_hostname();
#endif
#if !defined(BUILD_FOR_RP2040) #if !defined(BUILD_FOR_RP2040)
Serial.print(F("CPU clock frequency (MHz): ")); Serial.print(F("CPU clock frequency (MHz): "));