1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-19 00:05:43 +00:00

Compare commits

..

1 Commits

9 changed files with 40 additions and 16 deletions

View File

@@ -13,14 +13,16 @@ static const char *const TAG = "captive_portal";
void CaptivePortal::handle_config(AsyncWebServerRequest *request) {
AsyncResponseStream *stream = request->beginResponseStream(ESPHOME_F("application/json"));
stream->addHeader(ESPHOME_F("cache-control"), ESPHOME_F("public, max-age=0, must-revalidate"));
char mac_s[18];
const char *mac_str = get_mac_address_pretty_into_buffer(mac_s);
#ifdef USE_ESP8266
stream->print(ESPHOME_F("{\"mac\":\""));
stream->print(get_mac_address_pretty().c_str());
stream->print(mac_str);
stream->print(ESPHOME_F("\",\"name\":\""));
stream->print(App.get_name().c_str());
stream->print(ESPHOME_F("\",\"aps\":[{}"));
#else
stream->printf(R"({"mac":"%s","name":"%s","aps":[{})", get_mac_address_pretty().c_str(), App.get_name().c_str());
stream->printf(R"({"mac":"%s","name":"%s","aps":[{})", mac_str, App.get_name().c_str());
#endif
for (auto &scan : wifi::global_wifi_component->get_scan_result()) {

View File

@@ -4,7 +4,8 @@
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
namespace esphome::lock {
namespace esphome {
namespace lock {
template<typename... Ts> class LockAction : public Action<Ts...> {
public:
@@ -71,4 +72,5 @@ class LockUnlockTrigger : public Trigger<> {
}
};
} // namespace esphome::lock
} // namespace lock
} // namespace esphome

View File

@@ -3,7 +3,8 @@
#include "esphome/core/controller_registry.h"
#include "esphome/core/log.h"
namespace esphome::lock {
namespace esphome {
namespace lock {
static const char *const TAG = "lock";
@@ -107,4 +108,5 @@ LockCall &LockCall::set_state(const std::string &state) {
}
const optional<LockState> &LockCall::get_state() const { return this->state_; }
} // namespace esphome::lock
} // namespace lock
} // namespace esphome

View File

@@ -7,7 +7,8 @@
#include "esphome/core/preferences.h"
#include <initializer_list>
namespace esphome::lock {
namespace esphome {
namespace lock {
class Lock;
@@ -176,4 +177,5 @@ class Lock : public EntityBase {
ESPPreferenceObject rtc_;
};
} // namespace esphome::lock
} // namespace lock
} // namespace esphome

View File

@@ -359,8 +359,8 @@ void WebServer::handle_pna_cors_request(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "");
response->addHeader(HEADER_CORS_ALLOW_PNA, "true");
response->addHeader(HEADER_PNA_NAME, App.get_name().c_str());
std::string mac = get_mac_address_pretty();
response->addHeader(HEADER_PNA_ID, mac.c_str());
char mac_s[18];
response->addHeader(HEADER_PNA_ID, get_mac_address_pretty_into_buffer(mac_s));
request->send(response);
}
#endif

View File

@@ -341,10 +341,11 @@ void WiFiComponent::setup() {
}
void WiFiComponent::start() {
char mac_s[18];
ESP_LOGCONFIG(TAG,
"Starting\n"
" Local MAC: %s",
get_mac_address_pretty().c_str());
get_mac_address_pretty_into_buffer(mac_s));
this->last_connected_ = millis();
uint32_t hash = this->has_sta() ? fnv1_hash(App.get_compilation_time()) : 88491487UL;
@@ -826,7 +827,8 @@ void WiFiComponent::print_connect_params_() {
char bssid_s[18];
format_mac_addr_upper(bssid.data(), bssid_s);
ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str());
char mac_s[18];
ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty_into_buffer(mac_s));
if (this->is_disabled()) {
ESP_LOGCONFIG(TAG, " Disabled");
return;

View File

@@ -126,7 +126,10 @@ class BSSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor {
class MacAddressWifiInfo : public Component, public text_sensor::TextSensor {
public:
void setup() override { this->publish_state(get_mac_address_pretty()); }
void setup() override {
char mac_s[18];
this->publish_state(get_mac_address_pretty_into_buffer(mac_s));
}
void dump_config() override;
};

View File

@@ -638,9 +638,8 @@ std::string get_mac_address() {
}
std::string get_mac_address_pretty() {
uint8_t mac[6];
get_mac_address_raw(mac);
return format_mac_address_pretty(mac);
char buf[18];
return std::string(get_mac_address_pretty_into_buffer(buf));
}
void get_mac_address_into_buffer(std::span<char, 13> buf) {
@@ -649,6 +648,13 @@ void get_mac_address_into_buffer(std::span<char, 13> buf) {
format_mac_addr_lower_no_sep(mac, buf.data());
}
const char *get_mac_address_pretty_into_buffer(std::span<char, 18> buf) {
uint8_t mac[6];
get_mac_address_raw(mac);
format_mac_addr_upper(mac, buf.data());
return buf.data();
}
#ifndef USE_ESP32
bool has_custom_mac_address() { return false; }
#endif

View File

@@ -1052,6 +1052,11 @@ std::string get_mac_address_pretty();
/// Assumes buffer length is 13 (12 digits for hexadecimal representation followed by null terminator).
void get_mac_address_into_buffer(std::span<char, 13> buf);
/// Get the device MAC address into the given buffer, in colon-separated uppercase hex notation.
/// Buffer must be exactly 18 bytes (17 for "XX:XX:XX:XX:XX:XX" + null terminator).
/// Returns pointer to the buffer for convenience.
const char *get_mac_address_pretty_into_buffer(std::span<char, 18> buf);
#ifdef USE_ESP32
/// Set the MAC address to use from the provided byte array (6 bytes).
void set_mac_address(uint8_t *mac);