【WiFi】AP和STA的创建

wifi的模式

modedescription
AP(Server)(Acess Point),无线接入点,是无线网络的创造者,网络的中心节点,例如路由器
STA(Client)(station),站点,任何一个介入无线AP的设备都是一个STA,例如带有无线网卡的笔记、带有无线网卡的手机等。
PROMISCUOUS混杂模式,即抓包模式,手机wifi发出的数据包,通过家里的路由器转发出时,wifi设备必须要在混杂模式才能接受这些数据包。

AP模式

  1. 确保wifi不在连接状态
  2. 设置为AP模式
  3. 配置信息
        typedef struct {
            uint8_t ssid[32];           /**< wifi的名称,最大32个字节*/
            uint8_t password[64];       /**< wifi的密码,最大64个字节,最小8位,需要程序上做限制*/
            uint8_t ssid_len;           /**< wifi名称的长度 */
            uint8_t channel;            /**< Channel of ESP32 soft-AP */
            wifi_auth_mode_t authmode;  /**< 安全类型,加密方法,. Do not support AUTH_WEP in soft-AP mode */
            uint8_t ssid_hidden;        /**< 是否广播SSID,也即是说是否隐藏WiFi名字,这样就需要用户自己去主动连接,并配置wifi信息 */
            uint8_t max_connection;     /**< AP模式下可以连接的数量,结合硬件有一个最大限定值 default 4, max 4 */
            uint16_t beacon_interval;   /**< 信标间隔,100 ~ 60000 ms,默认为100ms,SSID广播包发送的间距 */
        } wifi_ap_config_t;
    
Created with Raphaël 2.2.0 开始 wifi初始化 wifi模式 wifi配置 启动wifi 结束

STA模式

  1. 确保wifi不在连接状态
  2. 设置为AP模式
  3. 配置信息
    typedef struct {
        uint8_t ssid[32];      /**< SSID of target AP*/
        uint8_t password[64];  /**< password of target AP*/
        wifi_scan_method_t scan_method;    /**< do all channel scan or fast scan */
        bool bssid_set;        /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
        uint8_t bssid[6];     /**< MAC address of target AP*/
        uint8_t channel;       /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
        uint16_t listen_interval;   /**< Listen interval for ESP32 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0. */
        wifi_sort_method_t sort_method;    /**< sort the connect AP in the list by rssi or security mode */
        wifi_scan_threshold_t  threshold;     /**< When scan_method is set, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
    } wifi_sta_config_t;
    
    typedef enum {
        WIFI_FAST_SCAN = 0,                   /**< Do fast scan, scan will end after find SSID match AP 快速扫描*/
        WIFI_ALL_CHANNEL_SCAN,                /**< All channel scan, scan will end after scan all the channel 全部信道扫描*/
    }wifi_scan_method_t;
    
    typedef enum {
        WIFI_CONNECT_AP_BY_SIGNAL = 0,        /**< Sort match AP in scan list by RSSI 通过RSSI信号强度排序*/
        WIFI_CONNECT_AP_BY_SECURITY,          /**< Sort match AP in scan list by security mode 通过安全模式排序*/
    }wifi_sort_method_t;
    
以esp32为例
esp_wifi_init(constwifi_init_config_t *config);//初始化

esp_wifi_set_mode(wifi_mode_tmode);//模式

esp_err_t esp_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf);//配置信息

++配置DHCP IP池(看例程没有,看过其他芯片创建ap的时候有用过)

esp_err_t esp_wifi_start(void);//启动wifi
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值