From 556ccfeecd155f0ec9fb6c6551b1a041954205d3 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 5 May 2024 20:18:36 +0200 Subject: [PATCH] ESP32: include mac in hostname --- ESP32/main.ino | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ESP32/main.ino b/ESP32/main.ino index 99e7c73..375ed13 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -121,7 +121,13 @@ bool save_serial_speed_configuration(const uint32_t bps) #if !defined(BUILD_FOR_RP2040) void set_hostname() { - WiFi.setHostname("PDP-11"); + uint64_t mac = ESP.getEfuseMac(); + uint8_t *chipid = reinterpret_cast(&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) @@ -150,6 +156,8 @@ void configure_network(console *const c) return; } + c->put_string_lf(format("Connecting to SSID \"%s\"", parts.at(0).c_str())); + if (parts.size() == 1) WiFi.begin(parts.at(0).c_str()); else @@ -184,8 +192,6 @@ void check_network(console *const c) void start_network(console *const c) { - set_hostname(); - WiFi.mode(WIFI_STA); WiFi.useStaticBuffers(true); WiFi.begin(); @@ -249,6 +255,9 @@ void setup() { #if defined(ESP32) heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook); #endif +#if defined(ESP32) + set_hostname(); +#endif #if !defined(BUILD_FOR_RP2040) Serial.print(F("CPU clock frequency (MHz): "));