ESP32_BLUFI代码移植过程遇到的问题

1.先是运行esp32官方给的例程,出现了错误报错如下:
esp_image: Image length 1053648 doesn’t fit in partition length 1048576
boot: Factory app partition is not bootable
boot: No bootable app partitions in the partition table
ets Jun 8 2016 00:22:57

网上搜索问题,发现可能是定义的固件分区大小比实际编译生成的固件大小要大而出现错误;
具体参考:ESP32C3乐鑫分区表

修改方法:
1).partitions_singleapp.csv

Name, Type, SubType, Offset, Size, Flags

Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap

nvs, data, nvs, , 0x6000,
phy_init, data, phy, , 0x1000,
factory, app, factory, , 2M,

2). flash size 设为4M(适当大小)
在这里插入图片描述

  1. 在把blufi例程代码移植到自己的工程当中,发现有些头文件找不到
    问题:配置里要开蓝牙

3.编译完后连接过程出现报错。
包含blufi函数在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ESP32 Blufi是一种基于蓝牙通道的Wi-Fi网络配置功能,适用于ESP32。它通过安全协议将Wi-Fi配置和证书传输到ESP32,然后ESP32可以基于这些信息连接到AP或建立SoftAP。使用ESP32 Blufi可以方便地进行Wi-Fi网络配置,而无需连接到串行端口。以下是使用ESP32 Blufi进行Wi-Fi网络配置的步骤: 1.下载并烧录ESP32 Blufi BIN文件到ESP32开发板中。 2.使用蓝牙调试应用程序连接ESP32开发板。 3.在蓝牙调试应用程序中输入Wi-Fi网络的SSID和密码。 4.ESP32将自动连接到Wi-Fi网络。 以下是ESP32 Blufi的示例代码: ```c #include <WiFi.h> #include <esp_wifi.h> #include <esp_wpa2.h> #include <esp_event_loop.h> #include <esp_log.h> #include <nvs_flash.h> #include <blufi.h> #define EXAMPLE_ESP_WIFI_SSID "your_ssid" #define EXAMPLE_ESP_WIFI_PASS "your_password" #define EXAMPLE_ESP_MAXIMUM_RETRY 5 static EventGroupHandle_t s_wifi_event_group; static int s_retry_num = 0; static const char *TAG = "wifi station"; static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { esp_wifi_connect(); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { esp_wifi_connect(); s_retry_num++; ESP_LOGI(TAG, "retry to connect to the AP"); } ESP_LOGI(TAG,"connect to the AP fail\n"); } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); } } void wifi_init_sta(void) { s_wifi_event_group = xEventGroupCreate(); tcpip_adapter_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); wifi_config_t wifi_config = { .sta = { .ssid = EXAMPLE_ESP_WIFI_SSID, .password = EXAMPLE_ESP_WIFI_PASS, }, }; ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config)); ESP_ERROR_CHECK(esp_wifi_start()); xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT, false, true, portMAX_DELAY); ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); } void blufi_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param) { switch (event) { case ESP_BLUFI_EVENT_INIT_FINISH: ESP_LOGI(TAG, "Blufi init finish\n"); esp_ble_gap_set_device_name("ESP32-BLUEFI"); esp_ble_gap_config_adv_data(&blufi_adv_data); break; case ESP_BLUFI_EVENT_DEINIT_FINISH: break; case ESP_BLUFI_EVENT_BLE_CONNECT: ESP_LOGI(TAG, "Blufi ble connect\n"); break; case ESP_BLUFI_EVENT_BLE_DISCONNECT: ESP_LOGI(TAG, "Blufi ble disconnect\n"); break; case ESP_BLUFI_EVENT_SET_WIFI_OPMODE: ESP_LOGI(TAG, "Blufi set wifi opmode %d\n", param->wifi_mode.op_mode); wifi_init_sta(); break; case ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP: ESP_LOGI(TAG, "Blufi requset wifi connect to AP\n"); wifi_config_t sta_config; memset(&sta_config, 0, sizeof(sta_config)); memcpy(sta_config.sta.ssid, param->connect_to_ap.ssid, param->connect_to_ap.ssid_len); memcpy(sta_config.sta.password, param->connect_to_ap.password, param->connect_to_ap.password_len); sta_config.sta.bssid_set = param->connect_to_ap.bssid_set; if (sta_config.sta.bssid_set == true) { memcpy(sta_config.sta.bssid, param->connect_to_ap.bssid, 6); } esp_wifi_disconnect(); esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config); esp_wifi_connect(); break; case ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP: ESP_LOGI(TAG, "Blufi requset wifi disconnect from AP\n"); esp_wifi_disconnect(); break; default: break; } } void app_main() { ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT)); esp_bluedroid_init(); esp_bluedroid_enable(); esp_ble_gap_register_callback(blufi_event_callback); esp_blufi_register_callbacks(&blufi_callbacks); esp_blufi_profile_init(); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值