更改ESP8266相关路由信息

本文介绍了ESP8266作为Soft-AP时的配置方法,包括softap_config结构体成员解析及API使用说明。通过实例演示如何设置SSID与密码等参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

ESP8266上电的时候可以通过手机的WIFI看到ESP8266的SSID,但是因为加了密码而连接不上,用户可以通过对ESP8266编程来更改ESP8266的SSID以及密码。

相关数据类型介绍

一、softap_config

成员名称数据类型功能
ssiduint8大小的数组WIFI AP SSID
passworduint8大小的数组WIFI AP 密码
ssid_lenuint8SSID 长度
channeluint8通道
authmodeAUTH_MODE-
ssid_hiddenuint8-
max_connectionuint8-
beacon_intervaluint16-

结构体原型

struct softap_config 
{
    uint8 ssid[32];
    uint8 password[64];
    uint8 ssid_len; // Note: Recommend to set it according to your ssid
    uint8 channel;  // Note: support 1 ~ 13
    AUTH_MODE authmode; // Note: Don't support AUTH_WEP in softAP mode.
    uint8 ssid_hidden;  // Note: default 0
    uint8 max_connection;   // Note: default 4, max 4
    uint16 beacon_interval; // Note: support 100 ~ 60000 ms, default 100
};

相关API介绍

一、wifi_softap_get_config

功能查询 ESP8266 WiFi soft-AP 接口当前的配置-
函数原型bool wifi_softap_get_config(struct softap_config *config)-
参数*config获取到的soft-ap当前的配置
返回值true获取配置成功
-false获取配置失败

二、wifi_softap_set_config

功能配置 ESP8266 WiFi soft-AP并保存到flash中-
函数原型bool wifi_softap_set_config(struct softap_config *config)-
参数*configsoft-ap的配置
返回值true配置成功
-false配置失败
注意需要在 ESP8266 soft_AP使能的情况下调用此API-

三、 wifi_softap_set_config_current

功能配置 ESP8266 WiFi soft-AP不保存到flash中-
函数原型bool wifi_softap_set_config_current(struct softap_config *config)-
参数*configsoft-ap的配置
返回值true配置成功
-false配置失败
注意需要在 ESP8266 soft_AP使能的情况下调用此API-

相关例程

#include "ets_sys.h"
#include "osapi.h"
#include "user_interface.h"
#include "uart.h"
#include "gpio.h"
#include "app_socket.h"
#include "string.h"

void user_init( void )
{
    struct softap_config config;

    /** 初始化ESP8266工作模式 */
    if ( wifi_get_opmode() != 0x03 )
    {
        wifi_set_opmode( 0x03 );
    }

    /** 获取当前soft-AP配置 */
    wifi_softap_get_config( &config );

    /** 清零参数 */
    os_memset( config.ssid, 0, 32 );
    os_memset( config.password, 0, 64 );

    /** 写入数据 */
    os_memcpy( config.ssid, "SMART_SOCKET_ID", os_strlen( "SMART_SOCKET_ID" ) );
    os_memcpy( config.password, "12345678", os_strlen( "12345678" ) );

    config.authmode = AUTH_WPA_WPA2_PSK;
    config.ssid_len = 0;  // or its actual length
    config.beacon_interval = 100;
    config.max_connection = 4;  // how many stations can connect to ESP8266 softAP at most.

    /** 写入配置 */
    wifi_softap_set_config( &config );
}

参考资料

[1]. ESP8266Non-OS SDK API参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值