feat(twt): twt add parameter to enable keep alive

This commit is contained in:
yinqingzhao
2024-10-25 19:33:55 +08:00
parent 07821e8408
commit 2a715e4203
5 changed files with 29 additions and 1 deletions

View File

@@ -143,6 +143,15 @@ esp_err_t esp_wifi_enable_rx_statistics(bool rx_stats, bool rx_mu_stats);
*/ */
esp_err_t esp_wifi_enable_tx_statistics(esp_wifi_aci_t aci, bool tx_stats); esp_err_t esp_wifi_enable_tx_statistics(esp_wifi_aci_t aci, bool tx_stats);
/**
* @brief Set WiFi TWT config
*
* @param[in] config pointer to the WiFi TWT configure structure.
*
* @return
* - ESP_OK: succeed
*/
esp_err_t esp_wifi_sta_twt_config(wifi_twt_config_t *config);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -252,6 +252,7 @@ typedef enum {
/** Argument structure for twt configuration */ /** Argument structure for twt configuration */
typedef struct { typedef struct {
bool post_wakeup_event; /**< post twt wakeup event */ bool post_wakeup_event; /**< post twt wakeup event */
bool twt_enable_keep_alive; /**< twt enable send qos null to keep alive */
} wifi_twt_config_t; } wifi_twt_config_t;
/** Argument structure for WIFI_EVENT_TWT_WAKEUP event */ /** Argument structure for WIFI_EVENT_TWT_WAKEUP event */

View File

@@ -38,6 +38,12 @@ menu "Example Configuration"
help help
Set static gateway address. Set static gateway address.
config EXAMPLE_TWT_ENABLE_KEEP_ALIVE_QOS_NULL
bool "enable keep alive qos null"
default n
help
Enable send QOS NULL to keep alive during TWT.
menu "iTWT Configuration" menu "iTWT Configuration"
config EXAMPLE_ITWT_TRIGGER_ENABLE config EXAMPLE_ITWT_TRIGGER_ENABLE
bool "trigger-enabled" bool "trigger-enabled"

View File

@@ -48,6 +48,12 @@ static const char *TAG = "itwt";
#define DEFAULT_PWD CONFIG_EXAMPLE_WIFI_PASSWORD #define DEFAULT_PWD CONFIG_EXAMPLE_WIFI_PASSWORD
#define ITWT_SETUP_SUCCESS 1 #define ITWT_SETUP_SUCCESS 1
#if CONFIG_EXAMPLE_TWT_ENABLE_KEEP_ALIVE_QOS_NULL
bool keep_alive_enabled = true;
#else
bool keep_alive_enabled = false;
#endif
#if CONFIG_EXAMPLE_ITWT_TRIGGER_ENABLE #if CONFIG_EXAMPLE_ITWT_TRIGGER_ENABLE
uint8_t trigger_enabled = 1; uint8_t trigger_enabled = 1;
#else #else
@@ -259,6 +265,12 @@ static void wifi_itwt(void)
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
wifi_twt_config_t wifi_twt_config = {
.post_wakeup_event = false,
.twt_enable_keep_alive = keep_alive_enabled,
};
ESP_ERROR_CHECK(esp_wifi_sta_twt_config(&wifi_twt_config));
esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT20); esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT20);
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX); esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX);
esp_wifi_set_ps(WIFI_PS_MIN_MODEM); esp_wifi_set_ps(WIFI_PS_MIN_MODEM);