mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-10-20 22:31:30 +08:00
Merge branch 'feature/esp_smartconfig_refactor' into 'master'
feat(smartconfig): refactor smartconfig callback to use esp event See merge request sdk/ESP8266_RTOS_SDK!1553
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "esp_wifi_types.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_smartconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -39,7 +40,7 @@ typedef enum {
|
||||
WIFI_LOG_DEBUG, /*can be set in menuconfig*/
|
||||
WIFI_LOG_VERBOSE, /*can be set in menuconfig*/
|
||||
} wifi_log_level_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief WiFi log submodule definition
|
||||
*
|
||||
@@ -81,7 +82,7 @@ typedef enum {
|
||||
* - ESP_ERR_NO_MEM: out of memory
|
||||
* - others: refer to error code esp_err.h
|
||||
*/
|
||||
esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config);
|
||||
esp_err_t esp_wifi_init_internal(const wifi_init_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize Wi-Fi Driver
|
||||
@@ -117,14 +118,14 @@ wifi_rx_pbuf_mem_type_t esp_wifi_get_rx_pbuf_mem_type(void);
|
||||
int8_t esp_wifi_get_ap_rssi(void);
|
||||
|
||||
/**
|
||||
* @brief The RX callback function when receive probe request packet.
|
||||
* @brief The RX callback function when receive probe request packet.
|
||||
* When probe request packet is received, the callback function will be called.
|
||||
*
|
||||
* @param frame Data of received probe request.
|
||||
* @param len length of received probe request.
|
||||
* @param rssi rssi of received probe request.
|
||||
*/
|
||||
typedef void (*wifi_sta_rx_probe_req_t)(const uint8_t *frame, int len, int rssi);
|
||||
typedef void (*wifi_sta_rx_probe_req_t)(const uint8_t* frame, int len, int rssi);
|
||||
|
||||
/**
|
||||
* @brief Register the RX callback function when receive probe request.
|
||||
@@ -159,14 +160,14 @@ void esp_wifi_internal_free_rx_buffer(void* buffer);
|
||||
* - ERR_IF : WiFi driver error
|
||||
* - ERR_ARG : Invalid argument
|
||||
*/
|
||||
int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, uint16_t len);
|
||||
int esp_wifi_internal_tx(wifi_interface_t wifi_if, void* buffer, uint16_t len);
|
||||
|
||||
/**
|
||||
* @brief The WiFi RX callback function
|
||||
*
|
||||
* Each time the WiFi need to forward the packets to high layer, the callback function will be called
|
||||
*/
|
||||
typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
|
||||
typedef esp_err_t (*wifi_rxcb_t)(void* buffer, uint16_t len, void* eb);
|
||||
|
||||
/**
|
||||
* @brief Set the WiFi RX callback
|
||||
@@ -183,7 +184,7 @@ typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
|
||||
esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn);
|
||||
|
||||
/**
|
||||
* @brief Set current WiFi log level
|
||||
* @brief Set current WiFi log level
|
||||
*
|
||||
* @param level Log level.
|
||||
*
|
||||
@@ -207,7 +208,7 @@ esp_err_t esp_wifi_internal_set_log_level(wifi_log_level_t level);
|
||||
esp_err_t esp_wifi_internal_set_log_mod(uint32_t submodule);
|
||||
|
||||
/**
|
||||
* @brief Get current WiFi log info
|
||||
* @brief Get current WiFi log info
|
||||
*
|
||||
* @param log_level the return log level.
|
||||
* @param log_mod the return log module and submodule
|
||||
@@ -215,21 +216,49 @@ esp_err_t esp_wifi_internal_set_log_mod(uint32_t submodule);
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_get_log(wifi_log_level_t *log_level, uint32_t *log_mod);
|
||||
esp_err_t esp_wifi_internal_get_log(wifi_log_level_t* log_level, uint32_t* log_mod);
|
||||
|
||||
/**
|
||||
* @brief get wifi power management config.
|
||||
*
|
||||
*
|
||||
* @param ps_config power management config
|
||||
*/
|
||||
void esp_wifi_set_pm_config(esp_pm_config_t *pm_config);
|
||||
void esp_wifi_set_pm_config(esp_pm_config_t* pm_config);
|
||||
|
||||
/**
|
||||
* @brief set wifi power management config.
|
||||
*
|
||||
*
|
||||
* @param ps_config power management config
|
||||
*/
|
||||
void esp_wifi_get_pm_config(esp_pm_config_t *pm_config);
|
||||
void esp_wifi_get_pm_config(esp_pm_config_t* pm_config);
|
||||
|
||||
/**
|
||||
* @brief Start SmartConfig, config ESP device to connect AP. You need to broadcast information by phone APP.
|
||||
* Device sniffer special packets from the air that containing SSID and password of target AP.
|
||||
*
|
||||
* @attention 1. This API can be called in station or softAP-station mode.
|
||||
* @attention 2. Can not call esp_smartconfig_start twice before it finish, please call
|
||||
* esp_smartconfig_stop first.
|
||||
*
|
||||
* @param config pointer to smartconfig start configure structure
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - others: fail
|
||||
*/
|
||||
esp_err_t esp_smartconfig_internal_start(const smartconfig_start_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief Stop SmartConfig, free the buffer taken by esp_smartconfig_start.
|
||||
*
|
||||
* @attention Whether connect to AP succeed or not, this API should be called to free
|
||||
* memory taken by smartconfig_start.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - others: fail
|
||||
*/
|
||||
esp_err_t esp_smartconfig_internal_stop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -18,37 +18,48 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_event_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SC_STATUS_WAIT = 0, /**< Waiting to start connect */
|
||||
SC_STATUS_FIND_CHANNEL, /**< Finding target channel */
|
||||
SC_STATUS_GETTING_SSID_PSWD, /**< Getting SSID and password of target AP */
|
||||
SC_STATUS_LINK, /**< Connecting to target AP */
|
||||
SC_STATUS_LINK_OVER, /**< Connected to AP successfully */
|
||||
} smartconfig_status_t;
|
||||
|
||||
typedef enum {
|
||||
SC_TYPE_ESPTOUCH = 0, /**< protocol: ESPTouch */
|
||||
SC_TYPE_AIRKISS, /**< protocol: AirKiss */
|
||||
SC_TYPE_ESPTOUCH_AIRKISS, /**< protocol: ESPTouch and AirKiss */
|
||||
} smartconfig_type_t;
|
||||
|
||||
/**
|
||||
* @brief The callback of SmartConfig, executed when smart-config status changed.
|
||||
*
|
||||
* @param status Status of SmartConfig:
|
||||
* - SC_STATUS_GETTING_SSID_PSWD : pdata is a pointer of smartconfig_type_t, means config type.
|
||||
* - SC_STATUS_LINK : pdata is a pointer of struct station_config.
|
||||
* - SC_STATUS_LINK_OVER : pdata is a pointer of phone's IP address(4 bytes) if pdata unequal NULL.
|
||||
* - otherwise : parameter void *pdata is NULL.
|
||||
* @param pdata According to the different status have different values.
|
||||
*
|
||||
*/
|
||||
typedef void (*sc_callback_t)(smartconfig_status_t status, void *pdata);
|
||||
/** Smartconfig event declarations */
|
||||
typedef enum {
|
||||
SC_EVENT_SCAN_DONE, /*!< ESP32 station smartconfig has finished to scan for APs */
|
||||
SC_EVENT_FOUND_CHANNEL, /*!< ESP32 station smartconfig has found the channel of the target AP */
|
||||
SC_EVENT_GOT_SSID_PSWD, /*!< ESP32 station smartconfig got the SSID and password */
|
||||
SC_EVENT_SEND_ACK_DONE, /*!< ESP32 station smartconfig has sent ACK to cellphone */
|
||||
} smartconfig_event_t;
|
||||
|
||||
/** @brief smartconfig event base declaration */
|
||||
ESP_EVENT_DECLARE_BASE(SC_EVENT);
|
||||
|
||||
/** Argument structure for SC_EVENT_GOT_SSID_PSWD event */
|
||||
typedef struct {
|
||||
uint8_t ssid[32]; /**< SSID of the AP. Null terminated string. */
|
||||
uint8_t password[64]; /**< Password of the AP. Null terminated string. */
|
||||
bool bssid_set; /**< whether set MAC address of target AP or not. */
|
||||
uint8_t bssid[6]; /**< MAC address of target AP. */
|
||||
smartconfig_type_t type; /**< Type of smartconfig(ESPTouch or AirKiss). */
|
||||
uint8_t token; /**< Token from cellphone which is used to send ACK to cellphone. */
|
||||
uint8_t cellphone_ip[4]; /**< IP address of cellphone. */
|
||||
} smartconfig_event_got_ssid_pswd_t;
|
||||
|
||||
/** Configure structure for esp_smartconfig_start */
|
||||
typedef struct {
|
||||
bool enable_log; /**< Enable smartconfig logs. */
|
||||
} smartconfig_start_config_t;
|
||||
|
||||
#define SMARTCONFIG_START_CONFIG_DEFAULT() { \
|
||||
.enable_log = false \
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get the version of SmartConfig.
|
||||
@@ -56,24 +67,23 @@ typedef void (*sc_callback_t)(smartconfig_status_t status, void *pdata);
|
||||
* @return
|
||||
* - SmartConfig version const char.
|
||||
*/
|
||||
const char *esp_smartconfig_get_version(void);
|
||||
const char* esp_smartconfig_get_version(void);
|
||||
|
||||
/**
|
||||
* @brief Start SmartConfig, config ESP device to connect AP. You need to broadcast information by phone APP.
|
||||
* Device sniffer special packets from the air that containing SSID and password of target AP.
|
||||
*
|
||||
* @attention 1. This API can be called in station or softAP-station mode.
|
||||
* @attention 1. This API can be called in station mode.
|
||||
* @attention 2. Can not call esp_smartconfig_start twice before it finish, please call
|
||||
* esp_smartconfig_stop first.
|
||||
*
|
||||
* @param cb SmartConfig callback function.
|
||||
* @param ... log 1: UART output logs; 0: UART only outputs the result.
|
||||
* @param config pointer to smartconfig start configure structure
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - others: fail
|
||||
*/
|
||||
esp_err_t esp_smartconfig_start(sc_callback_t cb, ...);
|
||||
esp_err_t esp_smartconfig_start(const smartconfig_start_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief Stop SmartConfig, free the buffer taken by esp_smartconfig_start.
|
||||
|
44
components/esp8266/include/smartconfig_ack.h
Normal file
44
components/esp8266/include/smartconfig_ack.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SMARTCONFIG_ACK_H
|
||||
#define SMARTCONFIG_ACK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Send smartconfig ACK to cellphone.
|
||||
*
|
||||
* @attention The API can only be used when receiving SC_EVENT_GOT_SSID_PSWD event.
|
||||
*
|
||||
* @param type: smartconfig type(ESPTouch or AirKiss);
|
||||
* token: token from the cellphone;
|
||||
* cellphone_ip: IP address of the cellphone;
|
||||
*
|
||||
* @retuen ESP_OK: succeed
|
||||
* others: fail
|
||||
*/
|
||||
esp_err_t sc_send_ack_start(smartconfig_type_t type, uint8_t token, uint8_t* cellphone_ip);
|
||||
|
||||
/**
|
||||
* @brief Stop sending smartconfig ACK to cellphone.
|
||||
*/
|
||||
void sc_send_ack_stop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Reference in New Issue
Block a user