Wi-Fi Service

[English]

Wi-Fi 服务 (Wi-Fi service) 提供了网络配置和网络管理的功能。配置网络支持 SmartConfig、BluFi 和 AirKiss。

应用示例

以下示例展示了该 API 的实现方式。

Header File

Functions

periph_service_handle_t wifi_service_create(wifi_service_config_t *config)
esp_err_t wifi_service_destroy(periph_service_handle_t handle)
esp_err_t wifi_service_register_setting_handle(periph_service_handle_t handle, esp_wifi_setting_handle_t setting, int *out_index)
esp_err_t wifi_service_setting_start(periph_service_handle_t handle, int index)
esp_err_t wifi_service_update_sta_info(periph_service_handle_t handle, wifi_config_t *wifi_conf)
esp_err_t wifi_service_setting_stop(periph_service_handle_t handle, int index)
esp_err_t wifi_service_connect(periph_service_handle_t handle)
esp_err_t wifi_service_disconnect(periph_service_handle_t handle)
esp_err_t wifi_service_set_sta_info(periph_service_handle_t handle, wifi_config_t *info)
periph_service_state_t wifi_service_state_get(periph_service_handle_t handle)
wifi_service_disconnect_reason_t wifi_service_disconnect_reason_get(periph_service_handle_t handle)
esp_err_t wifi_service_erase_ssid_manager_info(periph_service_handle_t handle)
esp_err_t wifi_service_get_last_ssid_cfg(periph_service_handle_t handle, wifi_config_t *wifi_cfg)

Structures

struct wifi_service_config_t

WiFi service configurations.

Public Members

int task_stack

>0 Service task stack; =0 with out task created

int task_prio

Service task priority (based on freeRTOS priority)

int task_core

Service task running in core (0 or 1)

bool extern_stack

Task stack allocate on the extern ram

periph_service_cb evt_cb

Service callback function

void *cb_ctx

Callback context

char *user_data

User data

int setting_timeout_s

Timeout of setting WiFi

int max_retry_time

Maximum times of reconnection

int max_prov_retry_time

Maximum times of reconnection after wifi provision

uint8_t max_ssid_num

Maximum ssid that can be stored

Macros

WIFI_SERVICE_DEFAULT_CONFIG()

Enumerations

enum wifi_service_event_t

WiFi STA service status.

Values:

WIFI_SERV_EVENT_UNKNOWN
WIFI_SERV_EVENT_CONNECTING
WIFI_SERV_EVENT_CONNECTED
WIFI_SERV_EVENT_DISCONNECTED
WIFI_SERV_EVENT_SETTING_TIMEOUT
WIFI_SERV_EVENT_SETTING_FAILED
WIFI_SERV_EVENT_SETTING_FINISHED
enum wifi_service_disconnect_reason_t

WiFi STA disconnection reasons.

Values:

WIFI_SERV_STA_UNKNOWN
WIFI_SERV_STA_COM_ERROR
WIFI_SERV_STA_AUTH_ERROR
WIFI_SERV_STA_AP_NOT_FOUND
WIFI_SERV_STA_BY_USER
WIFI_SERV_STA_SET_INFO

Header File

Functions

esp_wifi_setting_handle_t esp_wifi_setting_create(const char *tag)

brief Create wifi setting handle instance

Return

  • NULL, Fail

  • Others, Success

Parameters
  • tag: Tag of the wifi setting handle

esp_err_t esp_wifi_setting_destroy(esp_wifi_setting_handle_t handle)

brief Destroy wifi setting handle instance

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The wifi setting handle instance

esp_err_t esp_wifi_setting_register_function(esp_wifi_setting_handle_t handle, wifi_setting_func start, wifi_setting_func stop, wifi_setting_teardown_func teardown)

Register the wifi setting execute functions.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The wifi setting handle instance

  • start: The start wifi setting

  • stop: The stop

  • teardown: The destroy

esp_err_t esp_wifi_setting_register_notify_handle(esp_wifi_setting_handle_t handle, void *on_handle)

Register the notify execute handle.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The peripheral handle

  • on_handle: The notify execute handle

esp_err_t esp_wifi_setting_info_notify(esp_wifi_setting_handle_t handle, wifi_config_t *info)

Call this to notify the wifi_config_t to on_handle

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The wifi setting handle instance

  • info: The wifi_config_t

esp_err_t esp_wifi_setting_set_data(esp_wifi_setting_handle_t handle, void *data)

Set the user data.

Note

Make sure the data lifetime is sufficient, this function does not copy all data, it only stores the data pointer

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] handle: The wifi setting handle instance

  • data: The user data

void *esp_wifi_setting_get_data(esp_wifi_setting_handle_t handle)

Get the user data stored on handle

Return

user data pointer

Parameters
  • [in] handle: The wifi setting handle instance

esp_err_t esp_wifi_setting_start(esp_wifi_setting_handle_t handle)

Call this to execute start function of wifi setting instance.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The wifi setting handle instance

esp_err_t esp_wifi_setting_stop(esp_wifi_setting_handle_t handle)

Call this to execute stop function of wifi setting instance.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The wifi setting handle instance

esp_err_t esp_wifi_setting_teardown(esp_wifi_setting_handle_t handle, wifi_config_t *info)

Call this to execute teardown function of wifi setting instance.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • handle: The wifi setting handle instance

  • info: The wifi_config_t

Type Definitions

typedef struct esp_wifi_setting *esp_wifi_setting_handle_t
typedef esp_err_t (*wifi_setting_func)(esp_wifi_setting_handle_t handle)
typedef esp_err_t (*wifi_setting_teardown_func)(esp_wifi_setting_handle_t handle, wifi_config_t *info)

Header File

Functions

esp_wifi_setting_handle_t smart_config_create(smart_config_info_t *info)

brief Create smartconfig setting handle instance

Return

  • NULL, Fail

  • Others, Success

Parameters
  • info: Configuration of the smartconfig

Structures

struct smart_config_info_t

esp smartconfig configuration

Public Members

smartconfig_type_t type

Type of smartconfig

Macros

SMART_CONFIG_INFO_DEFAULT()

Header File

Functions

esp_wifi_setting_handle_t blufi_config_create(void *info)

Create blufi setting handle instance.

Return

  • NULL, Fail

  • Others, Success

Parameters
  • [in] info: A pointer to void

esp_err_t blufi_set_sta_connected_flag(esp_wifi_setting_handle_t handle, bool flag)

Set flag to judge whether the station has connected to the AP.

Return

  • NULL, Fail

  • Others, Success

Parameters
  • [in] handle: Wifi setting handle

  • [in] flag: bool type of station connection state

esp_err_t blufi_set_customized_data(esp_wifi_setting_handle_t handle, char *data, int data_len)

Set customized data to be sent after configurate wifi successfully.

Return

  • ESP_FAIL, Fail

  • ESP_OK, Success

Parameters
  • [in] handle: Wifi setting handle

  • [in] data: Customized data

  • [in] data_len: Customized data length

esp_err_t blufi_send_customized_data(esp_wifi_setting_handle_t handle)

Send customized data that be set before.

Return

  • ESP_FAIL, Fail

  • ESP_OK, Success

Parameters
  • [in] handle: Wifi setting handle

Header File

Functions

esp_wifi_setting_handle_t airkiss_config_create(airkiss_config_info_t *info)

brief Create airkiss setting handle instance

Return

  • NULL, Fail

  • Others, Success

Parameters
  • info: Configuration of the airkiss

Structures

struct airkiss_lan_pack_param_t

airkiss lan data pack

Public Members

void *appid

APP identifer data

void *deviceid

Device identifer data

struct airkiss_config_info_t

airkiss configurations

Public Members

airkiss_lan_pack_param_t lan_pack

User lan pack parameter

bool ssdp_notify_enable

Notify enable flag

char *aes_key

Airkiss aes key data

Macros

AIRKISS_CONFIG_INFO_DEFAULT()

Header File

Functions

wifi_ssid_manager_handle_t wifi_ssid_manager_create(uint8_t max_ssid_num)
esp_err_t wifi_ssid_manager_get_latest_config(wifi_ssid_manager_handle_t handle, wifi_config_t *config)
esp_err_t wifi_ssid_manager_save(wifi_ssid_manager_handle_t handle, const char *ssid, const char *pwd)
esp_err_t wifi_ssid_manager_get_best_config(wifi_ssid_manager_handle_t handle, wifi_config_t *config)
int wifi_ssid_manager_get_ssid_num(wifi_ssid_manager_handle_t handle)
esp_err_t wifi_ssid_manager_list_show(wifi_ssid_manager_handle_t handle)
esp_err_t wifi_ssid_manager_erase_all(wifi_ssid_manager_handle_t handle)
esp_err_t wifi_ssid_manager_destroy(wifi_ssid_manager_handle_t handle)

Type Definitions

typedef struct wifi_ssid_manager *wifi_ssid_manager_handle_t