mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 10:42:21 +01:00
[wifi] Optimize WiFi MAC formatting to eliminate sprintf dependency (#10715)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -593,7 +593,7 @@ void WiFiComponent::check_scanning_finished() {
|
||||
for (auto &res : this->scan_result_) {
|
||||
char bssid_s[18];
|
||||
auto bssid = res.get_bssid();
|
||||
sprintf(bssid_s, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
|
||||
format_mac_addr_upper(bssid.data(), bssid_s);
|
||||
|
||||
if (res.get_matches()) {
|
||||
ESP_LOGI(TAG, "- '%s' %s" LOG_SECRET("(%s) ") "%s", res.get_ssid().c_str(),
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "esphome/components/wifi/wifi_component.h"
|
||||
#ifdef USE_WIFI
|
||||
@@ -106,8 +107,8 @@ class BSSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor {
|
||||
wifi::bssid_t bssid = wifi::global_wifi_component->wifi_bssid();
|
||||
if (memcmp(bssid.data(), last_bssid_.data(), 6) != 0) {
|
||||
std::copy(bssid.begin(), bssid.end(), last_bssid_.begin());
|
||||
char buf[30];
|
||||
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
|
||||
char buf[18];
|
||||
format_mac_addr_upper(bssid.data(), buf);
|
||||
this->publish_state(buf);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user