Skip to content

Commit

Permalink
Fix MAC address initialization order
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSchinazi committed Dec 23, 2024
1 parent 2435c94 commit 984582b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/jazzlights/networks/arduino_esp_wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ std::string WiFiReasonToString(uint8_t reason) {
}
} // namespace

ArduinoEspWiFiNetwork::ArduinoEspWiFiNetwork(const char* ssid, const char* pass) : creds_{ssid, pass} {}
ArduinoEspWiFiNetwork::ArduinoEspWiFiNetwork(const char* ssid, const char* pass) : creds_{ssid, pass} {
uint8_t macAddress[6] = {};
if (WiFi.macAddress(&macAddress[0]) == nullptr) {
uint64_t efuseMac64 = ESP.getEfuseMac();
if (efuseMac64 == 0) { jll_fatal("%u Wi-Fi failed to read MAC address from both Wi-Fi and EFUSE", timeMillis()); }
memcpy(macAddress, &efuseMac64, sizeof(macAddress));
}
localDeviceId_ = NetworkDeviceId(macAddress);
}

void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch (event) {
Expand Down Expand Up @@ -163,11 +171,6 @@ NetworkStatus ArduinoEspWiFiNetwork::update(NetworkStatus status, Milliseconds c
WiFi.onEvent(WiFiEvent, ARDUINO_EVENT_WIFI_STA_LOST_IP);
WiFi.onEvent(WiFiEvent, ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
wl_status_t beginWiFiStatus = WiFi.begin(creds_.ssid, creds_.pass);
uint8_t macAddress[6] = {};
if (WiFi.macAddress(&macAddress[0]) == nullptr) {
jll_fatal("%u Wi-Fi failed to read MAC address", timeMillis());
}
localDeviceId_ = NetworkDeviceId(macAddress);
jll_info("%u %s Wi-Fi " DEVICE_ID_FMT " begin to %s returned %s", currentTime, networkName(),
DEVICE_ID_HEX(localDeviceId_), creds_.ssid, WiFiStatusToString(beginWiFiStatus).c_str());
return CONNECTING;
Expand Down
2 changes: 2 additions & 0 deletions src/jazzlights/networks/arduino_ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ std::string EthernetHardwareStatusToString(EthernetHardwareStatus hwStatus) {
} // namespace

ArduinoEthernetNetwork::ArduinoEthernetNetwork(NetworkDeviceId localDeviceId) : localDeviceId_(localDeviceId) {
jll_info("%u %s Starting Ethernet with MAC address " DEVICE_ID_FMT, timeMillis(), networkName(),
DEVICE_ID_HEX(localDeviceId_));
#if JL_CORE2AWS_ETHERNET
// These pins work with the M5Stack Core2AWS connected to the Ethernet W5500 module.
// https://docs.m5stack.com/en/core/core2_for_aws
Expand Down

0 comments on commit 984582b

Please sign in to comment.