这是我的代码
#include
#include
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_ne
tif.h"
#include "nvs_flash.h"
#include "esp_mac.h"
#define ESP_WIFI_SSID "12345678"
#define ESP_WIFI_PAWD "qwertyui"
void wifi_call(void* event_handler_arg,
esp_event_base_t event_base,
int32_t event_id,
void* event_data)
{
if(event_base == IP_EVENT event_id == IP_EVENT_AP_STAIPASSIGNED)
{
printf("有设备连接成功!n");
ip_event_ap_staipassigned_t* info = (ip_event_ap_staipassigned_t*)event_data;
printf("已连接的STA的IP:"IPSTR"n",IP2STR( info->ip));
printf("已连接的STA的MAC:"MACSTR"n",MAC2STR(info->mac));
}
}
void app_main(void)
{
//初始化nvs_flash
nvs_flash_init();
//创建一个默认循环事件
esp_event_loop_create_default();
//初始化虚拟网卡
esp_netif_init();
//创建一个AP类型的虚拟网卡
esp_netif_create_default_wifi_ap();
wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT();
esp_wifi_init( wifi_config);
esp_wifi_set_mode(WIFI_MODE_AP);
wifi_config_t config1 = {
.ap = {
.ssid = ESP_WIFI_SSID,
.ssid_len = strlen(ESP_WIFI_SSID),
.channel = 1,
.password = ESP_WIFI_PAWD,
.authmode = WIFI_AUTH_WPA_WPA2_PSK,
}
};
esp_wifi_set_config(WIFI_IF_AP, config1);
esp_wifi_start();
esp_event_handler_instance_register(IP_EVENT,IP_EVENT_AP_STAIPASSIGNED,wifi_call,NULL,NULL);
}
这是我的日志
ESP-ROM:esp8684-api2-20220127
Build:Jan 27 2022
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5c80,len:0x16c4
load:0x403acb70,len:0x974
load:0x403aeb70,len:0x2980
entry 0x403acb70
I (21) boot: ESP-IDF v5.1.2-dirty 2nd stage bootloader
I (21) boot: compile time Jun 11 2024 09:34:50
I (21) boot: chip revision: v1.0
I (24) boot.esp32c2: MMU Page Size : 32K
I (29) boot.esp32c2: SPI Speed : 60MHz
I (34) boot.esp32c2: SPI Mode : DIO
I (39) boot.esp32c2: SPI Flash Size : 2MB
I (43) boot: Enabling RNG early entropy source...
I (49) boot: Partition Table:
I (52) boot: ## Label Usage Type ST Offset Length
I (60) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (67) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (75) boot: 2 factory factory app 00 00 00010000 00100000
I (82) boot: End of partition table
I (86) esp_image: segment 0: paddr=00010020 vaddr=3c078020 size=1da40h (121408) map
I (122) esp_image: segment 1: paddr=0002da68 vaddr=3fcacd80 size=02470h ( 9328) load
I (124) esp_image: segment 2: paddr=0002fee0 vaddr=40380000 size=00138h ( 312) load
I (128) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=71890h (465040) map
I (240) esp_image: segment 4: paddr=000a18b8 vaddr=40380138 size=0cc40h ( 52288) load
I (258) boot: Loaded app from partition at offset 0x10000
I (258) boot: Disabling RNG early entropy source...
I (269) cpu_start: Unicore app
I (269) cpu_start: Pro cpu up.
I (278) cpu_start: Pro cpu start user code
I (278) cpu_start: cpu freq: 120000000 Hz
I (278) cpu_start: Application information:
I (281) cpu_start: Project name: main
I (286) cpu_start: App version: 1
I (290) cpu_start: Compile time: Jun 11 2024 09:34:43
I (296) cpu_start: ELF file SHA256: 7a4759530f442de2...
I (302) cpu_start: ESP-IDF: v5.1.2-dirty
I (308) cpu_start: Min chip rev: v1.0
I (312) cpu_start: Max chip rev: v1.99
I (317) cpu_start: Chip rev: v1.0
I (322) heap_init: Initializing. RAM available for dynamic allocation:
I (329) heap_init: At 3FCB2F90 len 00029BE0 (166 KiB): D/IRAM
I (335) heap_init: At 3FCDCB70 len 0000294C (10 KiB): STACK/DRAM
I (343) spi_flash: detected chip: gd
I (346) spi_flash: flash io: dio
W (350) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (364) sleep: Configure to isolate all GPIO pins in sleep state
I (370) sleep: Enable automatic switching of GPIO sleep configuration
I (378) app_start: Starting scheduler on CPU0
I (382) main_task: Started on CPU0
I (382) main_task: Calling app_main()
I (402) pp: pp rom version: de8c800
I (402) net80211: net80211 rom version: de8c800
I (412) wifi:wifi driver task: 3fcb90e8, prio:23, stack:6144, core=0
I (412) wifi:wifi firmware version: 91b9630
I (412) wifi:wifi certification version: v7.0
I (412) wifi:config NVS flash: enabled
I (412) wifi:config nano formating: enabled
I (422) wifi:Init data frame dynamic rx buffer num: 32
I (422) wifi:Init static rx mgmt buffer num: 5
I (432) wifi:Init management short buffer num: 32
I (432) wifi:Init dynamic tx buffer num: 32
I (432) wifi:Init static tx FG buffer num: 2
I (442) wifi:Init static rx buffer size: 1600
I (442) wifi:Init static rx buffer num: 10
I (452) wifi:Init dynamic rx buffer num: 32
I (452) wifi_init: rx ba win: 6
I (452) wifi_init: tcpip mbox: 32
I (462) wifi_init: udp mbox: 6
I (462) wifi_init: tcp mbox: 6
I (472) wifi_init: tcp tx win: 5744
I (472) wifi_init: tcp rx win: 5744
I (472) wifi_init: tcp mss: 1440
I (482) wifi_init: WiFi IRAM OP enabled
I (482) wifi_init: WiFi RX IRAM OP enabled
I (492) phy_init: phy_version 270,39d177a,Oct 13 2023,16:18:10
I (532) wifi:mode : softAP (08:3a:8d:65:51:01)
I (532) wifi:Total power save buffer number: 16
I (532) wifi:Init max length of beacon: 752/752
I (532) wifi:Init max length of beacon: 752/752
I (532) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.4.1
I (542) main_task: Returned from app_main()
日志显示ap模式开启成功了 也获取到IP了 但是搜索不到这个Wi-Fi 并且设置为STA模式时也连接不上Wi-Fi
只有使用官方的AT指令才可以连接Wi-Fi以及开启热点
求解答