最近ESP32很活,所以购买了一块ESP32的开发板(芒果的 Widora Air),环境的搭建就Pass了。下面直接贴代码:
#include "freertos/FreeRTOS.h" #include "esp_wifi.h" #include "esp_system.h" #include "esp_event.h" #include "esp_event_loop.h" #include "nvs_flash.h" #include "driver/gpio.h" esp_err_t event_handler(void *ctx, system_event_t *event) { return ESP_OK; } void app_main(void) { nvs_flash_init(); tcpip_adapter_init(); ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) ); wifi_config_t ap_config = { .ap = { .ssid = "TEST", .channel = 6 } }; ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &ap_config) ); ESP_ERROR_CHECK( esp_wifi_start() ); }