Skip to content

Commit

Permalink
ESP32: include mac in hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed May 5, 2024
1 parent 37f320c commit 556ccfe
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ESP32/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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): "));
Expand Down

0 comments on commit 556ccfe

Please sign in to comment.