mirror of
https://github.com/esphome/esphome.git
synced 2025-09-12 00:02:21 +01:00
ESP-IDF support and generic target platforms (#2303)
* Socket refactor and SSL * esp-idf temp * Fixes * Echo component and noise * Add noise API transport support * Updates * ESP-IDF * Complete * Fixes * Fixes * Versions update * New i2c APIs * Complete i2c refactor * SPI migration * Revert ESP Preferences migration, too complex for now * OTA support * Remove echo again * Remove ssl again * GPIOFlags updates * Rename esphal and ICACHE_RAM_ATTR * Make ESP32 arduino compilable again * Fix GPIO flags * Complete pin registry refactor and fixes * Fixes to make test1 compile * Remove sdkconfig file * Ignore sdkconfig file * Fixes in reviewing * Make test2 compile * Make test4 compile * Make test5 compile * Run clang-format * Fix lint errors * Use esp-idf APIs instead of btStart * Another round of fixes * Start implementing ESP8266 * Make test3 compile * Guard esp8266 code * Lint * Reformat * Fixes * Fixes v2 * more fixes * ESP-IDF tidy target * Convert ARDUINO_ARCH_ESPxx * Update WiFiSignalSensor * Update time ifdefs * OTA needs millis from hal * RestartSwitch needs delay from hal * ESP-IDF Uart * Fix OTA blank password * Allow setting sdkconfig * Fix idf partitions and allow setting sdkconfig from yaml * Re-add read/write compat APIs and fix esp8266 uart * Fix esp8266 store log strings in flash * Fix ESP32 arduino preferences not initialized * Update ifdefs * Change how sdkconfig change is detected * Add checks to ci-custom and fix them * Run clang-format * Add esp-idf clang-tidy target and fix errors * Fixes from clang-tidy idf round 2 * Fixes from compiling tests with esp-idf * Run clang-format * Switch test5.yaml to esp-idf * Implement ESP8266 Preferences * Lint * Re-do PIO package version selection a bit * Fix arduinoespressif32 package version * Fix unit tests * Lint * Lint fixes * Fix readv/writev not defined * Fix graphing component * Re-add all old options from core/config.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "wifi_component.h"
|
||||
#include "esphome/core/macros.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#ifdef USE_ESP8266
|
||||
|
||||
#include <user_interface.h>
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/esphal.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/util.h"
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
@@ -39,6 +39,12 @@ namespace wifi {
|
||||
|
||||
static const char *const TAG = "wifi_esp8266";
|
||||
|
||||
static bool s_sta_connected = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
static bool s_sta_got_ip = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
static bool s_sta_connect_not_found = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
static bool s_sta_connect_error = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
static bool s_sta_connecting = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
|
||||
uint8_t current_mode = wifi_get_opmode();
|
||||
bool current_sta = current_mode & 0b01;
|
||||
@@ -177,7 +183,7 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
IPAddress WiFiComponent::wifi_sta_ip_() {
|
||||
network::IPAddress WiFiComponent::wifi_sta_ip() {
|
||||
if (!this->has_sta())
|
||||
return {};
|
||||
struct ip_info ip {};
|
||||
@@ -319,6 +325,12 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
|
||||
}
|
||||
}
|
||||
|
||||
s_sta_connecting = true;
|
||||
s_sta_connected = false;
|
||||
s_sta_got_ip = false;
|
||||
s_sta_connect_error = false;
|
||||
s_sta_connect_not_found = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -453,6 +465,7 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
|
||||
buf[it.ssid_len] = '\0';
|
||||
ESP_LOGV(TAG, "Event: Connected ssid='%s' bssid=%s channel=%u", buf, format_mac_addr(it.bssid).c_str(),
|
||||
it.channel);
|
||||
s_sta_connected = true;
|
||||
break;
|
||||
}
|
||||
case EVENT_STAMODE_DISCONNECTED: {
|
||||
@@ -462,10 +475,14 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
|
||||
buf[it.ssid_len] = '\0';
|
||||
if (it.reason == REASON_NO_AP_FOUND) {
|
||||
ESP_LOGW(TAG, "Event: Disconnected ssid='%s' reason='Probe Request Unsuccessful'", buf);
|
||||
s_sta_connect_not_found = true;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Event: Disconnected ssid='%s' bssid=" LOG_SECRET("%s") " reason='%s'", buf,
|
||||
format_mac_addr(it.bssid).c_str(), LOG_STR_ARG(get_disconnect_reason_str(it.reason)));
|
||||
s_sta_connect_error = true;
|
||||
}
|
||||
s_sta_connected = false;
|
||||
s_sta_connecting = false;
|
||||
break;
|
||||
}
|
||||
case EVENT_STAMODE_AUTHMODE_CHANGE: {
|
||||
@@ -487,6 +504,7 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
|
||||
auto it = event->event_info.got_ip;
|
||||
ESP_LOGV(TAG, "Event: Got IP static_ip=%s gateway=%s netmask=%s", format_ip_addr(it.ip).c_str(),
|
||||
format_ip_addr(it.gw).c_str(), format_ip_addr(it.mask).c_str());
|
||||
s_sta_got_ip = true;
|
||||
break;
|
||||
}
|
||||
case EVENT_STAMODE_DHCP_TIMEOUT: {
|
||||
@@ -563,21 +581,22 @@ void WiFiComponent::wifi_pre_setup_() {
|
||||
this->wifi_mode_(false, false);
|
||||
}
|
||||
|
||||
wl_status_t WiFiComponent::wifi_sta_status_() {
|
||||
WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() {
|
||||
station_status_t status = wifi_station_get_connect_status();
|
||||
switch (status) {
|
||||
case STATION_GOT_IP:
|
||||
return WL_CONNECTED;
|
||||
return WiFiSTAConnectStatus::CONNECTED;
|
||||
case STATION_NO_AP_FOUND:
|
||||
return WL_NO_SSID_AVAIL;
|
||||
return WiFiSTAConnectStatus::ERROR_NETWORK_NOT_FOUND;
|
||||
;
|
||||
case STATION_CONNECT_FAIL:
|
||||
case STATION_WRONG_PASSWORD:
|
||||
return WL_CONNECT_FAILED;
|
||||
case STATION_IDLE:
|
||||
return WL_IDLE_STATUS;
|
||||
return WiFiSTAConnectStatus::ERROR_CONNECT_FAILED;
|
||||
case STATION_CONNECTING:
|
||||
return WiFiSTAConnectStatus::CONNECTING;
|
||||
case STATION_IDLE:
|
||||
default:
|
||||
return WL_DISCONNECTED;
|
||||
return WiFiSTAConnectStatus::IDLE;
|
||||
}
|
||||
}
|
||||
bool WiFiComponent::wifi_scan_start_() {
|
||||
@@ -656,9 +675,9 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
||||
info.gw.addr = static_cast<uint32_t>(manual_ip->gateway);
|
||||
info.netmask.addr = static_cast<uint32_t>(manual_ip->subnet);
|
||||
} else {
|
||||
info.ip.addr = static_cast<uint32_t>(IPAddress(192, 168, 4, 1));
|
||||
info.gw.addr = static_cast<uint32_t>(IPAddress(192, 168, 4, 1));
|
||||
info.netmask.addr = static_cast<uint32_t>(IPAddress(255, 255, 255, 0));
|
||||
info.ip.addr = static_cast<uint32_t>(network::IPAddress(192, 168, 4, 1));
|
||||
info.gw.addr = static_cast<uint32_t>(network::IPAddress(192, 168, 4, 1));
|
||||
info.netmask.addr = static_cast<uint32_t>(network::IPAddress(255, 255, 255, 0));
|
||||
}
|
||||
|
||||
if (wifi_softap_dhcps_status() == DHCP_STARTED) {
|
||||
@@ -677,13 +696,13 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) {
|
||||
#endif
|
||||
|
||||
struct dhcps_lease lease {};
|
||||
IPAddress start_address = info.ip.addr;
|
||||
network::IPAddress start_address = info.ip.addr;
|
||||
start_address[3] += 99;
|
||||
lease.start_ip.addr = static_cast<uint32_t>(start_address);
|
||||
ESP_LOGV(TAG, "DHCP server IP lease start: %s", start_address.toString().c_str());
|
||||
ESP_LOGV(TAG, "DHCP server IP lease start: %s", start_address.str().c_str());
|
||||
start_address[3] += 100;
|
||||
lease.end_ip.addr = static_cast<uint32_t>(start_address);
|
||||
ESP_LOGV(TAG, "DHCP server IP lease end: %s", start_address.toString().c_str());
|
||||
ESP_LOGV(TAG, "DHCP server IP lease end: %s", start_address.str().c_str());
|
||||
if (!wifi_softap_set_dhcps_lease(&lease)) {
|
||||
ESP_LOGV(TAG, "Setting SoftAP DHCP lease failed!");
|
||||
return false;
|
||||
@@ -746,11 +765,27 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
|
||||
|
||||
return true;
|
||||
}
|
||||
IPAddress WiFiComponent::wifi_soft_ap_ip() {
|
||||
network::IPAddress WiFiComponent::wifi_soft_ap_ip() {
|
||||
struct ip_info ip {};
|
||||
wifi_get_ip_info(SOFTAP_IF, &ip);
|
||||
return {ip.ip.addr};
|
||||
}
|
||||
bssid_t WiFiComponent::wifi_bssid() {
|
||||
bssid_t bssid{};
|
||||
uint8_t *raw_bssid = WiFi.BSSID();
|
||||
if (raw_bssid != nullptr) {
|
||||
for (size_t i = 0; i < bssid.size(); i++)
|
||||
bssid[i] = raw_bssid[i];
|
||||
}
|
||||
return bssid;
|
||||
}
|
||||
std::string WiFiComponent::wifi_ssid() { return WiFi.SSID().c_str(); }
|
||||
int8_t WiFiComponent::wifi_rssi() { return WiFi.RSSI(); }
|
||||
int32_t WiFiComponent::wifi_channel_() { return WiFi.channel(); }
|
||||
network::IPAddress WiFiComponent::wifi_subnet_mask_() { return {WiFi.subnetMask()}; }
|
||||
network::IPAddress WiFiComponent::wifi_gateway_ip_() { return {WiFi.gatewayIP()}; }
|
||||
network::IPAddress WiFiComponent::wifi_dns_ip_(int num) { return {WiFi.dnsIP(num)}; }
|
||||
void WiFiComponent::wifi_loop_() {}
|
||||
|
||||
} // namespace wifi
|
||||
} // namespace esphome
|
||||
|
Reference in New Issue
Block a user