mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[wifi] Reduce memory usage (#9232)
This commit is contained in:
		| @@ -62,7 +62,7 @@ struct SavedWifiFastConnectSettings { | |||||||
|   uint8_t channel; |   uint8_t channel; | ||||||
| } PACKED;  // NOLINT | } PACKED;  // NOLINT | ||||||
|  |  | ||||||
| enum WiFiComponentState { | enum WiFiComponentState : uint8_t { | ||||||
|   /** Nothing has been initialized yet. Internal AP, if configured, is disabled at this point. */ |   /** Nothing has been initialized yet. Internal AP, if configured, is disabled at this point. */ | ||||||
|   WIFI_COMPONENT_STATE_OFF = 0, |   WIFI_COMPONENT_STATE_OFF = 0, | ||||||
|   /** WiFi is disabled. */ |   /** WiFi is disabled. */ | ||||||
| @@ -146,14 +146,14 @@ class WiFiAP { | |||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   std::string ssid_; |   std::string ssid_; | ||||||
|   optional<bssid_t> bssid_; |  | ||||||
|   std::string password_; |   std::string password_; | ||||||
|  |   optional<bssid_t> bssid_; | ||||||
| #ifdef USE_WIFI_WPA2_EAP | #ifdef USE_WIFI_WPA2_EAP | ||||||
|   optional<EAPAuth> eap_; |   optional<EAPAuth> eap_; | ||||||
| #endif  // USE_WIFI_WPA2_EAP | #endif  // USE_WIFI_WPA2_EAP | ||||||
|   optional<uint8_t> channel_; |  | ||||||
|   float priority_{0}; |  | ||||||
|   optional<ManualIP> manual_ip_; |   optional<ManualIP> manual_ip_; | ||||||
|  |   float priority_{0}; | ||||||
|  |   optional<uint8_t> channel_; | ||||||
|   bool hidden_{false}; |   bool hidden_{false}; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -177,14 +177,14 @@ class WiFiScanResult { | |||||||
|   bool operator==(const WiFiScanResult &rhs) const; |   bool operator==(const WiFiScanResult &rhs) const; | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   bool matches_{false}; |  | ||||||
|   bssid_t bssid_; |   bssid_t bssid_; | ||||||
|   std::string ssid_; |   std::string ssid_; | ||||||
|  |   float priority_{0.0f}; | ||||||
|   uint8_t channel_; |   uint8_t channel_; | ||||||
|   int8_t rssi_; |   int8_t rssi_; | ||||||
|  |   bool matches_{false}; | ||||||
|   bool with_auth_; |   bool with_auth_; | ||||||
|   bool is_hidden_; |   bool is_hidden_; | ||||||
|   float priority_{0.0f}; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| struct WiFiSTAPriority { | struct WiFiSTAPriority { | ||||||
| @@ -192,7 +192,7 @@ struct WiFiSTAPriority { | |||||||
|   float priority; |   float priority; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| enum WiFiPowerSaveMode { | enum WiFiPowerSaveMode : uint8_t { | ||||||
|   WIFI_POWER_SAVE_NONE = 0, |   WIFI_POWER_SAVE_NONE = 0, | ||||||
|   WIFI_POWER_SAVE_LIGHT, |   WIFI_POWER_SAVE_LIGHT, | ||||||
|   WIFI_POWER_SAVE_HIGH, |   WIFI_POWER_SAVE_HIGH, | ||||||
| @@ -383,28 +383,36 @@ class WiFiComponent : public Component { | |||||||
|   std::string use_address_; |   std::string use_address_; | ||||||
|   std::vector<WiFiAP> sta_; |   std::vector<WiFiAP> sta_; | ||||||
|   std::vector<WiFiSTAPriority> sta_priorities_; |   std::vector<WiFiSTAPriority> sta_priorities_; | ||||||
|  |   std::vector<WiFiScanResult> scan_result_; | ||||||
|   WiFiAP selected_ap_; |   WiFiAP selected_ap_; | ||||||
|   bool fast_connect_{false}; |  | ||||||
|   bool retry_hidden_{false}; |  | ||||||
|  |  | ||||||
|   bool has_ap_{false}; |  | ||||||
|   WiFiAP ap_; |   WiFiAP ap_; | ||||||
|   WiFiComponentState state_{WIFI_COMPONENT_STATE_OFF}; |   optional<float> output_power_; | ||||||
|   bool handled_connected_state_{false}; |   ESPPreferenceObject pref_; | ||||||
|  |   ESPPreferenceObject fast_connect_pref_; | ||||||
|  |  | ||||||
|  |   // Group all 32-bit integers together | ||||||
|   uint32_t action_started_; |   uint32_t action_started_; | ||||||
|   uint8_t num_retried_{0}; |  | ||||||
|   uint32_t last_connected_{0}; |   uint32_t last_connected_{0}; | ||||||
|   uint32_t reboot_timeout_{}; |   uint32_t reboot_timeout_{}; | ||||||
|   uint32_t ap_timeout_{}; |   uint32_t ap_timeout_{}; | ||||||
|  |  | ||||||
|  |   // Group all 8-bit values together | ||||||
|  |   WiFiComponentState state_{WIFI_COMPONENT_STATE_OFF}; | ||||||
|   WiFiPowerSaveMode power_save_{WIFI_POWER_SAVE_NONE}; |   WiFiPowerSaveMode power_save_{WIFI_POWER_SAVE_NONE}; | ||||||
|  |   uint8_t num_retried_{0}; | ||||||
|  | #if USE_NETWORK_IPV6 | ||||||
|  |   uint8_t num_ipv6_addresses_{0}; | ||||||
|  | #endif /* USE_NETWORK_IPV6 */ | ||||||
|  |  | ||||||
|  |   // Group all boolean values together | ||||||
|  |   bool fast_connect_{false}; | ||||||
|  |   bool retry_hidden_{false}; | ||||||
|  |   bool has_ap_{false}; | ||||||
|  |   bool handled_connected_state_{false}; | ||||||
|   bool error_from_callback_{false}; |   bool error_from_callback_{false}; | ||||||
|   std::vector<WiFiScanResult> scan_result_; |  | ||||||
|   bool scan_done_{false}; |   bool scan_done_{false}; | ||||||
|   bool ap_setup_{false}; |   bool ap_setup_{false}; | ||||||
|   optional<float> output_power_; |  | ||||||
|   bool passive_scan_{false}; |   bool passive_scan_{false}; | ||||||
|   ESPPreferenceObject pref_; |  | ||||||
|   ESPPreferenceObject fast_connect_pref_; |  | ||||||
|   bool has_saved_wifi_settings_{false}; |   bool has_saved_wifi_settings_{false}; | ||||||
| #ifdef USE_WIFI_11KV_SUPPORT | #ifdef USE_WIFI_11KV_SUPPORT | ||||||
|   bool btm_{false}; |   bool btm_{false}; | ||||||
| @@ -412,10 +420,8 @@ class WiFiComponent : public Component { | |||||||
| #endif | #endif | ||||||
|   bool enable_on_boot_; |   bool enable_on_boot_; | ||||||
|   bool got_ipv4_address_{false}; |   bool got_ipv4_address_{false}; | ||||||
| #if USE_NETWORK_IPV6 |  | ||||||
|   uint8_t num_ipv6_addresses_{0}; |  | ||||||
| #endif /* USE_NETWORK_IPV6 */ |  | ||||||
|  |  | ||||||
|  |   // Pointers at the end (naturally aligned) | ||||||
|   Trigger<> *connect_trigger_{new Trigger<>()}; |   Trigger<> *connect_trigger_{new Trigger<>()}; | ||||||
|   Trigger<> *disconnect_trigger_{new Trigger<>()}; |   Trigger<> *disconnect_trigger_{new Trigger<>()}; | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user