Wi-Fi Service

[中文]

The Wi-Fi service can configure and manage the network. SmartConfig, BluFi, and AirKiss are supported for network configuration.

Application Example

Implementation of this API is demonstrated in the following example:

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:

enumerator WIFI_SERV_EVENT_UNKNOWN
enumerator WIFI_SERV_EVENT_CONNECTING
enumerator WIFI_SERV_EVENT_CONNECTED
enumerator WIFI_SERV_EVENT_DISCONNECTED
enumerator WIFI_SERV_EVENT_SETTING_TIMEOUT
enumerator WIFI_SERV_EVENT_SETTING_FAILED
enumerator WIFI_SERV_EVENT_SETTING_FINISHED
enum wifi_service_disconnect_reason_t

WiFi STA disconnection reasons.

Values:

enumerator WIFI_SERV_STA_UNKNOWN
enumerator WIFI_SERV_STA_COM_ERROR
enumerator WIFI_SERV_STA_AUTH_ERROR
enumerator WIFI_SERV_STA_AP_NOT_FOUND
enumerator WIFI_SERV_STA_BY_USER
enumerator 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

Parameters

tag – Tag of the wifi setting handle

Returns

  • NULL, Fail

  • Others, Success

esp_err_t esp_wifi_setting_destroy(esp_wifi_setting_handle_t handle)

brief Destroy wifi setting handle instance

Parameters

handle – The wifi setting handle instance

Returns

  • ESP_OK

  • ESP_FAIL

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.

Parameters
  • handle – The wifi setting handle instance

  • start – The start wifi setting

  • stop – The stop

  • teardown – The destroy

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t esp_wifi_setting_register_notify_handle(esp_wifi_setting_handle_t handle, void *on_handle)

Register the notify execute handle.

Parameters
  • handle – The peripheral handle

  • on_handle – The notify execute handle

Returns

  • ESP_OK

  • ESP_FAIL

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

Parameters
  • handle – The wifi setting handle instance

  • info – The wifi_config_t

Returns

  • ESP_OK

  • ESP_FAIL

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

Parameters
  • handle[in] The wifi setting handle instance

  • data – The user data

Returns

  • ESP_OK

  • ESP_FAIL

void *esp_wifi_setting_get_data(esp_wifi_setting_handle_t handle)

Get the user data stored on handle

Parameters

handle[in] The wifi setting handle instance

Returns

user data pointer

esp_err_t esp_wifi_setting_start(esp_wifi_setting_handle_t handle)

Call this to execute start function of wifi setting instance.

Parameters

handle – The wifi setting handle instance

Returns

  • ESP_OK

  • ESP_FAIL

esp_err_t esp_wifi_setting_stop(esp_wifi_setting_handle_t handle)

Call this to execute stop function of wifi setting instance.

Parameters

handle – The wifi setting handle instance

Returns

  • ESP_OK

  • ESP_FAIL

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.

Parameters
  • handle – The wifi setting handle instance

  • info – The wifi_config_t

Returns

  • ESP_OK

  • ESP_FAIL

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

Parameters

info – Configuration of the smartconfig

Returns

  • NULL, Fail

  • Others, Success

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.

Parameters

info[in] A pointer to void

Returns

  • NULL, Fail

  • Others, Success

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.

Parameters
  • handle[in] Wifi setting handle

  • flag[in] bool type of station connection state

Returns

  • NULL, Fail

  • Others, Success

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.

Parameters
  • handle[in] Wifi setting handle

  • data[in] Customized data

  • data_len[in] Customized data length

Returns

  • ESP_FAIL, Fail

  • ESP_OK, Success

esp_err_t blufi_send_customized_data(esp_wifi_setting_handle_t handle)

Send customized data that be set before.

Parameters

handle[in] Wifi setting handle

Returns

  • ESP_FAIL, Fail

  • ESP_OK, Success

Header File

Functions

esp_wifi_setting_handle_t airkiss_config_create(airkiss_config_info_t *info)

brief Create airkiss setting handle instance

Parameters

info – Configuration of the airkiss

Returns

  • NULL, Fail

  • Others, Success

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