可以正常WiFi扫描的程序
This commit is contained in:
parent
09cc51331d
commit
8c8e58fec2
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -22,6 +22,8 @@
|
||||
"array": "c",
|
||||
"string": "c",
|
||||
"string_view": "c",
|
||||
"span": "c"
|
||||
"span": "c",
|
||||
"esp_vfs_fat.h": "c",
|
||||
"cstdlib": "c"
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
static const char *TAG = "POWER_IO";
|
||||
|
||||
/*电量变化引起的界面控件参数变化*/
|
||||
extern lv_obj_t * ui_Batinfo_valueVoltage;
|
||||
extern lv_obj_t * ui_Batinfo_valueVolume;
|
||||
extern lv_obj_t * ui_Batinfo_SpinboxBAT;
|
||||
@ -38,9 +39,9 @@ void powerTask(void)
|
||||
lv_slider_set_value(ui_Home_SliderHeaderBat,Bat_Voltage_Value/4.2*100,LV_ANIM_ON);
|
||||
lv_label_set_text_fmt(ui_Home_LabelHeaderBatValue,"%.0f%%",Bat_Voltage_Value/4.2*100);
|
||||
|
||||
ESP_LOGI("dd","%d",Bat_Adc_Value);
|
||||
// ESP_LOGI("dd","%d",Bat_Adc_Value);
|
||||
|
||||
printf("in powerTask the min free stack size is %ld \r\n", (int32_t)uxTaskGetStackHighWaterMark(NULL));
|
||||
//printf("in powerTask the min free stack size is %ld \r\n", (int32_t)uxTaskGetStackHighWaterMark(NULL));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -131,6 +131,10 @@ static esp_err_t s_example_read_file(const char *path)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint64_t total_bytes = 0;
|
||||
uint64_t free_bytes = 0;
|
||||
float free_percent = 0;
|
||||
|
||||
void flux_sd_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
@ -161,7 +165,6 @@ void flux_sd_init(void)
|
||||
ESP_LOGI(TAG, "Mounting filesystem");
|
||||
ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
|
||||
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
if (ret == ESP_FAIL) {
|
||||
ESP_LOGE(TAG, "Failed to mount filesystem. "
|
||||
@ -186,6 +189,16 @@ void flux_sd_init(void)
|
||||
if (ret != ESP_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
esp_vfs_fat_info(MOUNT_POINT,&total_bytes,&free_bytes);
|
||||
|
||||
free_percent = (float)free_bytes / (float)total_bytes * 100;
|
||||
|
||||
printf("Total space: %llu\n", total_bytes);
|
||||
printf("Free space: %llu\n", free_bytes);
|
||||
printf("Free percent: %.3f\n", free_percent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
components/FluxWifi/CMakeLists.txt
Normal file
3
components/FluxWifi/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "FluxWifi.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES driver lwip freertos esp_wifi nvs_flash)
|
||||
190
components/FluxWifi/FluxWifi.c
Normal file
190
components/FluxWifi/FluxWifi.c
Normal file
@ -0,0 +1,190 @@
|
||||
#include <stdio.h>
|
||||
#include "FluxWifi.h"
|
||||
|
||||
|
||||
wifi_ap_record_t ap_info[DEFAULT_SCAN_LIST_SIZE];
|
||||
int number = 0,ap_count=0;
|
||||
|
||||
static const char* TAG = "wifi_scan";
|
||||
/**
|
||||
* @brief 将Wi-Fi初始化为sta并设置扫描方法
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
void wifi_scan(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
/* wifi配置初始化 */
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
memset(ap_info, 0, sizeof(ap_info));
|
||||
|
||||
/* 设置WIFI为STA模式 */
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
|
||||
/* 启动WIFI */
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
/* 开始扫描附件的WIFI, 并等待扫描结束 */
|
||||
esp_wifi_scan_start(NULL, true);
|
||||
|
||||
/* 获取扫描结果 */
|
||||
get_wifi_scan_result();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取Wi-Fi扫描结果
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void get_wifi_scan_result(void)
|
||||
{
|
||||
number = DEFAULT_SCAN_LIST_SIZE;
|
||||
ap_count = 0;
|
||||
|
||||
/* 获取上次扫描中找到的AP数量 */
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
|
||||
/* 获取上次扫描中找到的AP列表 */
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
|
||||
|
||||
/* 打印WIFI扫描结果 */
|
||||
print_wifi_scan_result(ap_count, number);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 身份认证模式
|
||||
* @param authmode :身份验证模式
|
||||
* @retval 无
|
||||
*/
|
||||
static void print_auth_mode(int authmode)
|
||||
{
|
||||
switch (authmode) {
|
||||
case WIFI_AUTH_OPEN:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_OPEN");
|
||||
break;
|
||||
case WIFI_AUTH_OWE:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_OWE");
|
||||
break;
|
||||
case WIFI_AUTH_WEP:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WEP");
|
||||
break;
|
||||
case WIFI_AUTH_WPA_PSK:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA_PSK");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_PSK:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_PSK");
|
||||
break;
|
||||
case WIFI_AUTH_WPA_WPA2_PSK:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA_WPA2_PSK");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_ENTERPRISE:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_ENTERPRISE");
|
||||
break;
|
||||
case WIFI_AUTH_WPA3_PSK:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_PSK");
|
||||
break;
|
||||
case WIFI_AUTH_WPA2_WPA3_PSK:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_WPA3_PSK");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_UNKNOWN");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打印WIFI密码类型
|
||||
* @param pairwise_cipher :密码类型
|
||||
* @param group_cipher :群密码类型
|
||||
* @retval 无
|
||||
*/
|
||||
static void print_cipher_type(int pairwise_cipher, int group_cipher)
|
||||
{
|
||||
switch (pairwise_cipher) {
|
||||
case WIFI_CIPHER_TYPE_NONE:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_NONE");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_WEP40:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_WEP40");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_WEP104:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_WEP104");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_TKIP:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_TKIP");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_CCMP:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_CCMP");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_TKIP_CCMP:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_TKIP_CCMP");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Pairwise Cipher \tWIFI_CIPHER_TYPE_UNKNOWN");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (group_cipher) {
|
||||
case WIFI_CIPHER_TYPE_NONE:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_NONE");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_WEP40:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_WEP40");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_WEP104:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_WEP104");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_TKIP:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_TKIP");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_CCMP:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_CCMP");
|
||||
break;
|
||||
case WIFI_CIPHER_TYPE_TKIP_CCMP:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_TKIP_CCMP");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Group Cipher \tWIFI_CIPHER_TYPE_UNKNOWN");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打印Wi-Fi扫描结果
|
||||
* @param ap_count :实际扫描出的AP数量
|
||||
* @param number :可打印输出的AP信息数量
|
||||
* @retval 无
|
||||
*/
|
||||
static void print_wifi_scan_result(uint16_t ap_count, uint16_t number)
|
||||
{
|
||||
/* 打印附件的WIFI信息 */
|
||||
ESP_LOGI(TAG, "wifi scan result, ap_count = %u, number = %u", ap_count, number);
|
||||
|
||||
for (int i = 0; (i < DEFAULT_SCAN_LIST_SIZE) && (i < ap_count); i++) {
|
||||
ESP_LOGI(TAG, "SSID \t\t%s", ap_info[i].ssid);
|
||||
ESP_LOGI(TAG, "RSSI \t\t%d", ap_info[i].rssi);
|
||||
|
||||
/* 加密方式 */
|
||||
print_auth_mode(ap_info[i].authmode);
|
||||
/* 密码类型 */
|
||||
if (ap_info[i].authmode != WIFI_AUTH_WEP) {
|
||||
print_cipher_type(ap_info[i].pairwise_cipher, ap_info[i].group_cipher);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Channel \t\t%d\n", ap_info[i].primary);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
23
components/FluxWifi/FluxWifi.h
Normal file
23
components/FluxWifi/FluxWifi.h
Normal file
@ -0,0 +1,23 @@
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
|
||||
|
||||
#define DEFAULT_SCAN_LIST_SIZE 10
|
||||
|
||||
|
||||
static void print_wifi_scan_result(uint16_t ap_count, uint16_t number);
|
||||
static void print_cipher_type(int pairwise_cipher, int group_cipher);
|
||||
static void print_auth_mode(int authmode);
|
||||
static void get_wifi_scan_result(void);
|
||||
void wifi_scan(void);
|
||||
|
||||
@ -4,7 +4,7 @@ if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY)
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS "i80_controller_example_main.c" "lvgl_demo_ui.c" ${embedded_images}
|
||||
REQUIRES FluxUI FluxPower spiffs FluxSD FluxMod FluxButton
|
||||
REQUIRES FluxUI FluxPower spiffs FluxSD FluxMod FluxButton FluxWifi
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM)
|
||||
|
||||
@ -38,6 +38,9 @@
|
||||
/*添加电量监测头文件*/
|
||||
#include "FluxPower.h"
|
||||
|
||||
/*添加WiFi管理头文件*/
|
||||
#include "FluxWifi.h"
|
||||
|
||||
static const char *TAG = "example";
|
||||
|
||||
#include "modbus_params.h"
|
||||
@ -373,6 +376,9 @@ void app_main(void)
|
||||
/*拉起开机状态*/
|
||||
POWER_ON;
|
||||
|
||||
/*进行WIFI扫描*/
|
||||
wifi_scan();
|
||||
|
||||
static lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s)
|
||||
static lv_disp_drv_t disp_drv; // contains callback functions
|
||||
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, 0x9000, 0x6000,
|
||||
phy_init, data, phy, 0xf000, 0x1000,
|
||||
factory, app, factory, 0x10000, 1M,
|
||||
factory, app, factory, 0x10000, 2M,
|
||||
storage, data, spiffs, , 0xF0000,
|
||||
|
||||
|
12
sdkconfig
12
sdkconfig
@ -518,12 +518,12 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
||||
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_lvgl_example.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_lvgl_example.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
CONFIG_PARTITION_TABLE_MD5=y
|
||||
# end of Partition Table
|
||||
@ -1124,7 +1124,7 @@ CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK=y
|
||||
|
||||
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384
|
||||
CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1 is not set
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
|
||||
@ -2475,7 +2475,7 @@ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_160=y
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=160
|
||||
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=4096
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=16384
|
||||
CONFIG_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_CONSOLE_UART_NONE is not set
|
||||
|
||||
Loading…
Reference in New Issue
Block a user