mirror of
https://github.com/esphome/esphome.git
synced 2025-11-16 06:45:48 +00: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:
@@ -5,20 +5,20 @@
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/network/ip_address.h"
|
||||
#include <string>
|
||||
#include <IPAddress.h>
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||
#include <esp_wifi.h>
|
||||
#include <WiFiType.h>
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266WiFiType.h>
|
||||
#ifdef USE_ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WiFiType.h>
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && ARDUINO_VERSION_CODE < VERSION_CODE(2, 4, 0)
|
||||
#if defined(USE_ESP8266) && ARDUINO_VERSION_CODE < VERSION_CODE(2, 4, 0)
|
||||
extern "C" {
|
||||
#include <user_interface.h>
|
||||
};
|
||||
@@ -54,13 +54,21 @@ enum WiFiComponentState {
|
||||
WIFI_COMPONENT_STATE_AP,
|
||||
};
|
||||
|
||||
enum class WiFiSTAConnectStatus : int {
|
||||
IDLE,
|
||||
CONNECTING,
|
||||
CONNECTED,
|
||||
ERROR_NETWORK_NOT_FOUND,
|
||||
ERROR_CONNECT_FAILED,
|
||||
};
|
||||
|
||||
/// Struct for setting static IPs in WiFiComponent.
|
||||
struct ManualIP {
|
||||
IPAddress static_ip;
|
||||
IPAddress gateway;
|
||||
IPAddress subnet;
|
||||
IPAddress dns1; ///< The first DNS server. 0.0.0.0 for default.
|
||||
IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
|
||||
network::IPAddress static_ip;
|
||||
network::IPAddress gateway;
|
||||
network::IPAddress subnet;
|
||||
network::IPAddress dns1; ///< The first DNS server. 0.0.0.0 for default.
|
||||
network::IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
|
||||
};
|
||||
|
||||
#ifdef USE_WIFI_WPA2_EAP
|
||||
@@ -153,6 +161,10 @@ enum WiFiPowerSaveMode {
|
||||
WIFI_POWER_SAVE_HIGH,
|
||||
};
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
struct IDFWiFiEvent;
|
||||
#endif
|
||||
|
||||
/// This component is responsible for managing the ESP WiFi interface.
|
||||
class WiFiComponent : public Component {
|
||||
public:
|
||||
@@ -207,13 +219,13 @@ class WiFiComponent : public Component {
|
||||
bool has_sta() const;
|
||||
bool has_ap() const;
|
||||
|
||||
IPAddress get_ip_address();
|
||||
network::IPAddress get_ip_address();
|
||||
std::string get_use_address() const;
|
||||
void set_use_address(const std::string &use_address);
|
||||
|
||||
const std::vector<WiFiScanResult> &get_scan_result() const { return scan_result_; }
|
||||
|
||||
IPAddress wifi_soft_ap_ip();
|
||||
network::IPAddress wifi_soft_ap_ip();
|
||||
|
||||
bool has_sta_priority(const bssid_t &bssid) {
|
||||
for (auto &it : this->sta_priorities_)
|
||||
@@ -239,36 +251,46 @@ class WiFiComponent : public Component {
|
||||
});
|
||||
}
|
||||
|
||||
network::IPAddress wifi_sta_ip();
|
||||
std::string wifi_ssid();
|
||||
bssid_t wifi_bssid();
|
||||
|
||||
int8_t wifi_rssi();
|
||||
|
||||
protected:
|
||||
static std::string format_mac_addr(const uint8_t mac[6]);
|
||||
void setup_ap_config_();
|
||||
void print_connect_params_();
|
||||
|
||||
void wifi_loop_();
|
||||
bool wifi_mode_(optional<bool> sta, optional<bool> ap);
|
||||
bool wifi_sta_pre_setup_();
|
||||
bool wifi_apply_output_power_(float output_power);
|
||||
bool wifi_apply_power_save_();
|
||||
bool wifi_sta_ip_config_(optional<ManualIP> manual_ip);
|
||||
IPAddress wifi_sta_ip_();
|
||||
bool wifi_apply_hostname_();
|
||||
bool wifi_sta_connect_(const WiFiAP &ap);
|
||||
void wifi_pre_setup_();
|
||||
wl_status_t wifi_sta_status_();
|
||||
WiFiSTAConnectStatus wifi_sta_connect_status_();
|
||||
bool wifi_scan_start_();
|
||||
bool wifi_ap_ip_config_(optional<ManualIP> manual_ip);
|
||||
bool wifi_start_ap_(const WiFiAP &ap);
|
||||
bool wifi_disconnect_();
|
||||
int32_t wifi_channel_();
|
||||
network::IPAddress wifi_subnet_mask_();
|
||||
network::IPAddress wifi_gateway_ip_();
|
||||
network::IPAddress wifi_dns_ip_(int num);
|
||||
|
||||
bool is_captive_portal_active_();
|
||||
bool is_esp32_improv_active_();
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#ifdef USE_ESP8266
|
||||
static void wifi_event_callback(System_Event_t *event);
|
||||
void wifi_scan_done_callback_(void *arg, STATUS status);
|
||||
static void s_wifi_scan_done_callback(void *arg, STATUS status);
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
void wifi_event_callback_(arduino_event_id_t event, arduino_event_info_t info);
|
||||
#else
|
||||
@@ -276,6 +298,9 @@ class WiFiComponent : public Component {
|
||||
#endif
|
||||
void wifi_scan_done_callback_();
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
void wifi_process_event_(IDFWiFiEvent *);
|
||||
#endif
|
||||
|
||||
std::string use_address_;
|
||||
std::vector<WiFiAP> sta_;
|
||||
|
||||
Reference in New Issue
Block a user