mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 10:14:13 +01:00
Fix build issues for idf 4.2 (Support ESP32-S2) (#1433)
Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
parent
5c3af1d3f6
commit
a546677b08
3 changed files with 63 additions and 3 deletions
|
@ -136,7 +136,11 @@ void Logger::pre_setup() {
|
||||||
break;
|
break;
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case UART_SELECTION_UART2:
|
case UART_SELECTION_UART2:
|
||||||
|
#if !CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
// FIXME: Validate in config that UART2 can't be set for ESP32-S2 (only has
|
||||||
|
// UART0-UART1)
|
||||||
this->hw_serial_ = &Serial2;
|
this->hw_serial_ = &Serial2;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,11 @@ class WiFiComponent : public Component {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
void wifi_event_callback_(arduino_event_id_t event, arduino_event_info_t info);
|
||||||
|
#else
|
||||||
void wifi_event_callback_(system_event_id_t event, system_event_info_t info);
|
void wifi_event_callback_(system_event_id_t event, system_event_info_t info);
|
||||||
|
#endif
|
||||||
void wifi_scan_done_callback_();
|
void wifi_scan_done_callback_();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,14 @@ const char *get_auth_mode_str(uint8_t mode) {
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string format_ip4_addr(const ip4_addr_t &ip) {
|
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
using esphome_ip4_addr_t = esp_ip4_addr_t;
|
||||||
|
#else
|
||||||
|
using esphome_ip4_addr_t = ip4_addr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string format_ip4_addr(const esphome_ip4_addr_t &ip) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
sprintf(buf, "%u.%u.%u.%u", uint8_t(ip.addr >> 0), uint8_t(ip.addr >> 8), uint8_t(ip.addr >> 16),
|
sprintf(buf, "%u.%u.%u.%u", uint8_t(ip.addr >> 0), uint8_t(ip.addr >> 8), uint8_t(ip.addr >> 16),
|
||||||
uint8_t(ip.addr >> 24));
|
uint8_t(ip.addr >> 24));
|
||||||
|
@ -346,14 +353,22 @@ const char *get_disconnect_reason_str(uint8_t reason) {
|
||||||
return "Unspecified";
|
return "Unspecified";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
void WiFiComponent::wifi_event_callback_(arduino_event_id_t event, arduino_event_info_t info) {
|
||||||
|
#else
|
||||||
void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_info_t info) {
|
void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_info_t info) {
|
||||||
|
#endif
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case SYSTEM_EVENT_WIFI_READY: {
|
case SYSTEM_EVENT_WIFI_READY: {
|
||||||
ESP_LOGV(TAG, "Event: WiFi ready");
|
ESP_LOGV(TAG, "Event: WiFi ready");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_SCAN_DONE: {
|
case SYSTEM_EVENT_SCAN_DONE: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_scan_done;
|
||||||
|
#else
|
||||||
auto it = info.scan_done;
|
auto it = info.scan_done;
|
||||||
|
#endif
|
||||||
ESP_LOGV(TAG, "Event: WiFi Scan Done status=%u number=%u scan_id=%u", it.status, it.number, it.scan_id);
|
ESP_LOGV(TAG, "Event: WiFi Scan Done status=%u number=%u scan_id=%u", it.status, it.number, it.scan_id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -366,7 +381,11 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_STA_CONNECTED: {
|
case SYSTEM_EVENT_STA_CONNECTED: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_sta_connected;
|
||||||
|
#else
|
||||||
auto it = info.connected;
|
auto it = info.connected;
|
||||||
|
#endif
|
||||||
char buf[33];
|
char buf[33];
|
||||||
memcpy(buf, it.ssid, it.ssid_len);
|
memcpy(buf, it.ssid, it.ssid_len);
|
||||||
buf[it.ssid_len] = '\0';
|
buf[it.ssid_len] = '\0';
|
||||||
|
@ -375,7 +394,11 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_sta_disconnected;
|
||||||
|
#else
|
||||||
auto it = info.disconnected;
|
auto it = info.disconnected;
|
||||||
|
#endif
|
||||||
char buf[33];
|
char buf[33];
|
||||||
memcpy(buf, it.ssid, it.ssid_len);
|
memcpy(buf, it.ssid, it.ssid_len);
|
||||||
buf[it.ssid_len] = '\0';
|
buf[it.ssid_len] = '\0';
|
||||||
|
@ -388,7 +411,11 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_sta_authmode_change;
|
||||||
|
#else
|
||||||
auto it = info.auth_change;
|
auto it = info.auth_change;
|
||||||
|
#endif
|
||||||
ESP_LOGV(TAG, "Event: Authmode Change old=%s new=%s", get_auth_mode_str(it.old_mode),
|
ESP_LOGV(TAG, "Event: Authmode Change old=%s new=%s", get_auth_mode_str(it.old_mode),
|
||||||
get_auth_mode_str(it.new_mode));
|
get_auth_mode_str(it.new_mode));
|
||||||
// Mitigate CVE-2020-12638
|
// Mitigate CVE-2020-12638
|
||||||
|
@ -424,13 +451,25 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_AP_STACONNECTED: {
|
case SYSTEM_EVENT_AP_STACONNECTED: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_sta_connected;
|
||||||
|
auto &mac = it.bssid;
|
||||||
|
#else
|
||||||
auto it = info.sta_connected;
|
auto it = info.sta_connected;
|
||||||
ESP_LOGV(TAG, "Event: AP client connected MAC=%s aid=%u", format_mac_addr(it.mac).c_str(), it.aid);
|
auto &mac = it.mac;
|
||||||
|
#endif
|
||||||
|
ESP_LOGV(TAG, "Event: AP client connected MAC=%s", format_mac_addr(mac).c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_AP_STADISCONNECTED: {
|
case SYSTEM_EVENT_AP_STADISCONNECTED: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_sta_disconnected;
|
||||||
|
auto &mac = it.bssid;
|
||||||
|
#else
|
||||||
auto it = info.sta_disconnected;
|
auto it = info.sta_disconnected;
|
||||||
ESP_LOGV(TAG, "Event: AP client disconnected MAC=%s aid=%u", format_mac_addr(it.mac).c_str(), it.aid);
|
auto &mac = it.mac;
|
||||||
|
#endif
|
||||||
|
ESP_LOGV(TAG, "Event: AP client disconnected MAC=%s", format_mac_addr(mac).c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_AP_STAIPASSIGNED: {
|
case SYSTEM_EVENT_AP_STAIPASSIGNED: {
|
||||||
|
@ -438,7 +477,11 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_AP_PROBEREQRECVED: {
|
case SYSTEM_EVENT_AP_PROBEREQRECVED: {
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
auto it = info.wifi_ap_probereqrecved;
|
||||||
|
#else
|
||||||
auto it = info.ap_probereqrecved;
|
auto it = info.ap_probereqrecved;
|
||||||
|
#endif
|
||||||
ESP_LOGVV(TAG, "Event: AP receive Probe Request MAC=%s RSSI=%d", format_mac_addr(it.mac).c_str(), it.rssi);
|
ESP_LOGVV(TAG, "Event: AP receive Probe Request MAC=%s RSSI=%d", format_mac_addr(it.mac).c_str(), it.rssi);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -446,8 +489,13 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
if (event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
|
||||||
|
uint8_t reason = info.wifi_sta_disconnected.reason;
|
||||||
|
#else
|
||||||
if (event == SYSTEM_EVENT_STA_DISCONNECTED) {
|
if (event == SYSTEM_EVENT_STA_DISCONNECTED) {
|
||||||
uint8_t reason = info.disconnected.reason;
|
uint8_t reason = info.disconnected.reason;
|
||||||
|
#endif
|
||||||
if (reason == WIFI_REASON_AUTH_EXPIRE || reason == WIFI_REASON_BEACON_TIMEOUT ||
|
if (reason == WIFI_REASON_AUTH_EXPIRE || reason == WIFI_REASON_BEACON_TIMEOUT ||
|
||||||
reason == WIFI_REASON_NO_AP_FOUND || reason == WIFI_REASON_ASSOC_FAIL ||
|
reason == WIFI_REASON_NO_AP_FOUND || reason == WIFI_REASON_ASSOC_FAIL ||
|
||||||
reason == WIFI_REASON_HANDSHAKE_TIMEOUT) {
|
reason == WIFI_REASON_HANDSHAKE_TIMEOUT) {
|
||||||
|
@ -458,7 +506,11 @@ void WiFiComponent::wifi_event_callback_(system_event_id_t event, system_event_i
|
||||||
this->error_from_callback_ = true;
|
this->error_from_callback_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
if (event == ARDUINO_EVENT_WIFI_SCAN_DONE) {
|
||||||
|
#else
|
||||||
if (event == SYSTEM_EVENT_SCAN_DONE) {
|
if (event == SYSTEM_EVENT_SCAN_DONE) {
|
||||||
|
#endif
|
||||||
this->wifi_scan_done_callback_();
|
this->wifi_scan_done_callback_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue