Skip to content

Commit

Permalink
Little code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Nov 10, 2024
1 parent fcc3794 commit 32cae35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/MycilaESPConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Mycila::ESPConnect::Mode Mycila::ESPConnect::getMode() const {
}

const String Mycila::ESPConnect::getMACAddress(Mycila::ESPConnect::Mode mode) const {
String mac = emptyString;
String mac;

switch (mode) {
case Mycila::ESPConnect::Mode::AP:
Expand Down Expand Up @@ -197,7 +197,7 @@ const String Mycila::ESPConnect::getMACAddress(Mycila::ESPConnect::Mode mode) co

char buffer[18] = {0};
snprintf(buffer, sizeof(buffer), "%02X:%02X:%02X:%02X:%02X:%02X", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
return String(buffer);
return buffer;
#endif
}

Expand All @@ -217,7 +217,7 @@ const IPAddress Mycila::ESPConnect::getIPAddress(Mycila::ESPConnect::Mode mode)
}
}

const String Mycila::ESPConnect::getWiFiSSID() const {
const String& Mycila::ESPConnect::getWiFiSSID() const {
switch (WiFi.getMode()) {
case WIFI_MODE_AP:
case WIFI_MODE_APSTA:
Expand Down Expand Up @@ -432,8 +432,8 @@ void Mycila::ESPConnect::_setState(Mycila::ESPConnect::State state) {
preferences.begin("espconnect", false);
preferences.putBool("ap", _config.apMode);
if (!_config.apMode) {
preferences.putString("ssid", _config.wifiSSID);
preferences.putString("password", _config.wifiPassword);
preferences.putString("ssid", _config.wifiSSID.c_str());
preferences.putString("password", _config.wifiPassword.c_str());
}
preferences.end();
}
Expand Down
8 changes: 4 additions & 4 deletions src/MycilaESPConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ namespace Mycila {
// returns the current default mode of the ESP (STA, AP, ETH). ETH has priority over STA if both are connected
Mode getMode() const;

inline bool isConnected() const { return getIPAddress()[0] != 0; }
bool isConnected() const { return getIPAddress()[0] != 0; }

inline const String getMACAddress() const { return getMACAddress(getMode()); }
const String getMACAddress() const { return getMACAddress(getMode()); }
const String getMACAddress(Mode mode) const;

// Returns the IP address of the current Ethernet, WiFi, or IP address of the AP or captive portal, or empty if not available
inline const IPAddress getIPAddress() const { return getIPAddress(getMode()); }
const IPAddress getIPAddress() const { return getIPAddress(getMode()); }
const IPAddress getIPAddress(Mode mode) const;

// Returns the SSID of the current WiFi, or SSID of the AP or captive portal, or empty if not available
const String getWiFiSSID() const;
const String& getWiFiSSID() const;
// Returns the BSSID of the current WiFi, or BSSID of the AP or captive portal, or empty if not available
const String getWiFiBSSID() const;
// Returns the RSSI of the current WiFi, or -1 if not available
Expand Down

0 comments on commit 32cae35

Please sign in to comment.