官方默认的 AT 启动会默认是 802.11bg 模式, 不支持 802.11n 模式, 如果要想启动后直接支持 802.11bgn 模式, 可以使用 AT+CWSTAPROTO=7 指令 来支持, 但是如果想要 at 固件启动起来默认就支持 n 模式,就需要在 esp-at/main/app_main.c 中的 at_wifi_event_handler 接口中自行添加代码, 如下:
#ifdef CONFIG_AT_WIFI_COMMAND_SUPPORT
static esp_err_t at_wifi_event_handler(void *ctx, system_event_t *event)
{
uint8_t temp_bit=0;
if (event->event_id == SYSTEM_EVENT_STA_START) {
ESP_ERROR_CHECK( esp_wifi_set_protocol(ESP_IF_WIFI_STA,7));
ESP_ERROR_CHECK(esp_wifi_get_protocol(ESP_IF_WIFI_STA, &temp_bit));
printf("--------protocol is %d-------\r\n",temp_bit);
}
#ifdef CONFIG_AT_WEB_SERVER_SUPPORT
if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) {
at_web_update_sta_got_ip_flag(true);
}
#endif
esp_err_t ret = esp_at_wifi_event_handler(ctx, event);
return ret;
}
编写完代码之后, 使用 ./build.py build flash 指令编译并烧写代码, 上电运行有如下信息说明:
<0x1b>[0;32mI (31) boot: SPI Mode : DIO<0x1b>[0m␊
[17:23:29:248] <0x1b>[0;32mI (35) boot: SPI Flash Size : 2MB<0x1b>[0m␊
[17:23:29:248] <0x1b>[0;32mI (39) boot: Partition Table:<0x1b>[0m␊
[17:23:29:248] <0x1b>[0;32mI (42) boot: ## Label Usage Type ST Offset Length<0x1b>[0m␊
[17:23:29:264] <0x1b>[0;32mI (50) boot: 0 otadata OTA data 01 00 00009000 00002000<0x1b>[0m␊
[17:23:29:264] <0x1b>[0;32mI (57) boot: 1 ota_0 OTA app 00 10 00010000 000e0000<0x1b>[0m␊
[17:23:29:264] <0x1b>[0;32mI (64) boot: 2 at_customize unknown 40 00 000f0000 00020000<0x1b>[0m␊
[17:23:29:280] <0x1b>[0;32mI (72) boot: 3 ota_1 OTA app 00 11 00110000 000e0000<0x1b>[0m␊
[17:23:29:280] <0x1b>[0;32mI (79) boot: 4 nvs WiFi data 01 02 001f0000 00010000<0x1b>[0m␊
[17:23:29:296] <0x1b>[0;32mI (86) boot: End of partition table<0x1b>[0m␊
[17:23:29:296] <0x1b>[0;32mI (91) boot: No factory image, trying OTA 0<0x1b>[0m␊
[17:23:29:296] <0x1b>[0;32mI (95) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0xa3f30 (671536) map<0x1b>[0m␊
[17:23:29:312] <0x1b>[0;32mI (104) esp_image: segment 1: paddr=0x000b3f48 vaddr=0x402b3f40 size=0x23f1c (147228) map<0x1b>[0m␊
[17:23:29:312] <0x1b>[0;32mI (113) esp_image: segment 2: paddr=0x000d7e6c vaddr=0x3ffe8000 size=0x00768 ( 1896) load<0x1b>[0m␊
[17:23:29:328] <0x1b>[0;32mI (122) esp_image: segment 3: paddr=0x000d85dc vaddr=0x40100000 size=0x00080 ( 128) load<0x1b>[0m␊
[17:23:29:344] <0x1b>[0;32mI (130) esp_image: segment 4: paddr=0x000d8664 vaddr=0x40100080 size=0x059f0 ( 23024) load<0x1b>[0m␊
[17:23:29:344] <0x1b>[0;32mI (139) boot: Loaded app from partition at offset 0x10000<0x1b>[0m␊
[17:23:29:392] --------testing-------␍␍␊
[17:23:29:392] --------enter testing111111111111111111111-------␍␍␊
[17:23:29:440] phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊
[17:23:29:456] --------protocol is 7-------␍␍␊
[17:23:29:456] --------protocol is 7-------␍␍␊
[17:23:29:456] --------testing111111111111111111111-------␍␍␊
[17:23:29:472] module_name:WROOM-02␍␍␊
[17:23:29:472] max tx power=78,ret=0␍␍␊
[17:23:29:472] 2.2.1