espressif / esp-mdf

Espressif Mesh Development Framework, limited maintain, recommend to use https://github.com/espressif/esp-mesh-lite
Other
766 stars 249 forks source link

WiFi Mesh coexist with GATT server and GATT client #159

Open owensc84 opened 3 years ago

owensc84 commented 3 years ago

I would like to use WiFi mesh along side bluetooth low energy. Are there any examples that show how this is done? My requirements are to use a GATT server and a GATT client with WiFi mesh. Any guidance is appreciated.

When I attempt to add a GATT client to the router-less "get-started" project the device is in a constant reset loop. If I remove the init_ancs() call the WiFi mesh works as expected.

I am using esp-mdf at master

This is my app_main. I tried to highlight where I initialize the GATT client.

void app_main()
{

    mwifi_init_config_t cfg = MWIFI_INIT_CONFIG_DEFAULT();
    mwifi_config_t config   = {
        .channel   = CONFIG_MESH_CHANNEL,
        .mesh_id   = CONFIG_MESH_ID,
        .mesh_type = CONFIG_DEVICE_TYPE,
    };

    /**
     * @brief Set the log level for serial port printing.
     */
    esp_log_level_set("*", ESP_LOG_INFO);
    esp_log_level_set(TAG, ESP_LOG_DEBUG);

    /**
     * @brief Initialize wifi mesh.
     */
    MDF_ERROR_ASSERT(mdf_event_loop_init(event_loop_cb));
    MDF_ERROR_ASSERT(wifi_init());
    MDF_ERROR_ASSERT(mwifi_init(&cfg));
    MDF_ERROR_ASSERT(mwifi_set_config(&config));
    MDF_ERROR_ASSERT(mwifi_start());

////////////////////////////////////////
    init_ancs();
////////////////////////////////////////    
/**
     * @brief Data transfer between wifi mesh devices
     */
    if (config.mesh_type == MESH_ROOT) {
        xTaskCreate(root_task, "root_task", 4 * 1024,
                    NULL, CONFIG_MDF_TASK_DEFAULT_PRIOTY, NULL);
    } else {
        xTaskCreate(node_write_task, "node_write_task", 4 * 1024,
                    NULL, CONFIG_MDF_TASK_DEFAULT_PRIOTY, NULL);
        xTaskCreate(node_read_task, "node_read_task", 4 * 1024,
                    NULL, CONFIG_MDF_TASK_DEFAULT_PRIOTY, NULL);
    }

    TimerHandle_t timer = xTimerCreate("print_system_info", 10000 / portTICK_RATE_MS,
                                       true, NULL, print_system_info_timercb);
    xTimerStart(timer, 0);

}

To follow is the GATT client initialization. The GATT client comes from the ESP32 ANCS example project.

void init_ancs(void)
//void app_main(void)
{
    esp_err_t ret;

    // Initialize NVS.
    #if 0
    ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );
    #endif

    // init timer
    init_timer();

    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ret = esp_bt_controller_init(&bt_cfg);
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "%s init controller failed: %s", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret));
        return;
    }

    ESP_LOGI(BLE_ANCS_TAG, "%s init bluetooth", __func__);
    ret = esp_bluedroid_init();
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_bluedroid_enable();
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "%s enable bluetooth failed: %s", __func__, esp_err_to_name(ret));
        return;
    }

    //register the callback function to the gattc module
    ret = esp_ble_gattc_register_callback(esp_gattc_cb);
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "%s gattc register error, error code = %x\n", __func__, ret);
        return;
    }

    ret = esp_ble_gap_register_callback(gap_event_handler);
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "gap register error, error code = %x", ret);
        return;
    }

    ret = esp_ble_gattc_app_register(PROFILE_A_APP_ID);
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "%s gattc app register error, error code = %x\n", __func__, ret);
    }

    ret = esp_ble_gatt_set_local_mtu(500);
    if (ret) {
        ESP_LOGE(BLE_ANCS_TAG, "set local  MTU failed, error code = %x", ret);
    }

    /* set the security iocap & auth_req & key size & init key response key parameters to the stack*/
    esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;     //bonding with peer device after authentication
    esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE;           //set the IO capability to No output No input
    uint8_t key_size = 16;      //the key size should be 7~16 bytes
    uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
    uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
    //set static passkey
    uint32_t passkey = 123456;
    uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_DISABLE;
    uint8_t oob_support = ESP_BLE_OOB_DISABLE;
    esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
    /* If your BLE device acts as a Slave, the init_key means you hope which types of key of the master should distribute to you,
    and the response key means which key you can distribute to the master;
    If your BLE device acts as a master, the response key means you hope which types of key of the slave should distribute to you,
    and the init key means which key you can distribute to the slave. */
    esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
}

Logs

I (31) boot: ESP-IDF v4.3-dev-134-g625bd5eb1 2nd stage bootloader I (31) boot: compile time 17:32:16 I (31) boot: chip revision: 3 I (35) boot_comm: chip revision: 3, min. bootloader chip revision: 0 I (42) boot.esp32: SPI Speed : 40MHz I (47) boot.esp32: SPI Mode : DIO I (51) boot.esp32: SPI Flash Size : 4MB I (56) boot: Enabling RNG early entropy source... I (62) boot: Partition Table: I (65) boot: ## Label Usage Type ST Offset Length I (72) boot: 0 nvs WiFi data 01 02 00009000 00004000 I (80) boot: 1 otadata OTA data 01 00 0000d000 00002000 I (87) boot: 2 phy_init RF data 01 01 0000f000 00001000 I (95) boot: 3 ota_0 OTA app 00 10 00010000 001e0000 I (102) boot: 4 ota_1 OTA app 00 11 001f0000 001e0000 I (110) boot: 5 coredump Unknown data 01 03 003d0000 00010000 I (117) boot: 6 reserved Unknown data 01 fe 003e0000 00020000 I (125) boot: End of partition table I (129) boot_comm: chip revision: 3, min. application chip revision: 0 I (136) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x3a59c (239004) map I (236) esp_image: segment 1: paddr=0x0004a5c4 vaddr=0x3ffbdb60 size=0x04ed8 ( 20184) load I (245) esp_image: segment 2: paddr=0x0004f4a4 vaddr=0x40080000 size=0x00404 ( 1028) load 0x40080000: _WindowOverflow4 at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (246) esp_image: segment 3: paddr=0x0004f8b0 vaddr=0x40080404 size=0x00768 ( 1896) load I (253) esp_image: segment 4: paddr=0x00050020 vaddr=0x400d0020 size=0x101360 (1053536) map 0x400d0020: _stext at ??:?

I (662) esp_image: segment 5: paddr=0x00151388 vaddr=0x40080b6c size=0x1bd64 (114020) load I (727) boot: Loaded app from partition at offset 0x10000 I (727) boot: Disabling RNG early entropy source... I (728) cpu_start: Pro cpu up. I (731) cpu_start: Application information: I (736) cpu_start: Project name: get_started I (742) cpu_start: App version: 1 I (746) cpu_start: Compile time: Jul 30 2020 17:37:52 I (752) cpu_start: ELF file SHA256: 87dba5e5ad2353e1... I (758) cpu_start: ESP-IDF: v4.3-dev-134-g625bd5eb1 I (764) cpu_start: Single core mode I (769) heap_init: Initializing. RAM available for dynamic allocation: I (776) heap_init: At 3FF80000 len 00002000 (8 KiB): RTCRAM I (782) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM I (788) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM I (794) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM I (800) heap_init: At 3FFD0FA8 len 0000F058 (60 KiB): DRAM I (806) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM I (813) heap_init: At 40078000 len 00008000 (32 KiB): IRAM I (819) heap_init: At 4009C8D0 len 00003730 (13 KiB): IRAM I (825) cpu_start: Pro cpu start user code I (843) spi_flash: detected chip: gd I (844) spi_flash: flash io: dio I (844) esp_core_dump_flash: Init core dump to flash I (846) esp_core_dump_flash: Found partition 'coredump' @ 3d0000 65536 bytes I (860) esp_core_dump_flash: Found core dump 25844 bytes in flash @ 0x3d0000 I (862) cpu_start: Starting scheduler on PRO CPU. I (890) wifi:wifi driver task: 3ffd3130, prio:23, stack:6656, core=0 I (891) system_api: Base MAC address is not set I (892) system_api: read default base MAC address from EFUSE I (904) wifi:wifi firmware version: 0507408 I (905) wifi:wifi certification version: v7.0 I (906) wifi:config NVS flash: enabled I (909) wifi:config nano formating: disabled I (914) wifi:Init dynamic tx buffer num: 32 I (917) wifi:Init data frame dynamic rx buffer num: 32 I (922) wifi:Init management frame dynamic rx buffer num: 32 I (928) wifi:Init management short buffer num: 32 I (932) wifi:Init static rx buffer size: 1600 I (936) wifi:Init static rx buffer num: 10 I (940) wifi:Init dynamic rx buffer num: 32 I (946) wifi:Set ps type: 0

I (1030) phy: phy_version: 4182, f1ba940, Jun 4 2020, 19:40:07, 0, 0 I (1032) wifi:mode : sta (fc:f5:c4:3c:55:00) I (1034) [mwifi, 292]: esp-mdf version: v1.0-67-g3894d47 I (1037) wifi:mode : sta (fc:f5:c4:3c:55:00) + softAP (fc:f5:c4:3c:55:01) I (1045) wifi:Total power save buffer number: 16 I (1047) wifi:Init max length of beacon: 752/752 I (1052) wifi:Init max length of beacon: 752/752 I (1056) mesh: read layer:0, err:0x1102 I (1060) mesh: read assoc:0, err:0x1102 I (1064) mesh: [IO]disable self-organizing I (1069) mesh: [CONFIG]invalid router settings, ssid_len:0, ssid:, bssid:00:00:00:00:00:00 I (1681) mesh: [MANUAL]designated as root and router is not set I (1681) [mwifi, 221]: MESH is started I (1682) [get_started, 188]: event_loop_cb, event: 0 I (1686) [get_started, 192]: MESH is started I (1691) [get_started, 31]: Root is running I (1696) BTDM_INIT: BT controller compile version [826d7c6] I (1708) coexist: [854006] Error! Should enable WiFi modem sleep when both WiFi and Bluetooth ar

abort() was called at PC 0x40153706 on core 0 0x40153706: coex_init at ??:?

Backtrace:0x4008d31f:0x3ffb7040 0x4008d981:0x3ffb7060 0x4009460e:0x3ffb7080 0x40153706:0x3ffb70f0 0x40136bc4:0x3ffb7110 0x40136e71:0x3ffb7140 0x400d8462:0x3ffb7170 0x400d7a1a:0x3ffb7190 0x400d700f:0x3ffb71f0 0x400d51d3:0x3ffb72f0 0x4008d989:0x3ffb7320 0x4008d31f: panic_abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_system/panic.c:330

0x4008d981: esp_system_abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_system/system_api.c:100

0x4009460e: abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/newlib/abort.c:46

0x40153706: coex_init at ??:?

0x40136bc4: esp_phy_rf_init at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_wifi/src/phy_init.c:334

0x40136e71: esp_phy_load_cal_and_init at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_wifi/src/phy_init.c:821

0x400d8462: esp_bt_controller_enable at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/bt/controller/bt.c:1376

0x400d7a1a: init_ancs at c:\eds\call_light\git\esp_mesh\get-started\build/../main/ble_ancs_demo.c:625

0x400d700f: app_main at c:\eds\call_light\git\esp_mesh\get-started\build/../main/get_started.c:252

0x400d51d3: main_task at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp32/cpu_start.c:584

0x4008d989: vPortTaskWrapper at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/freertos/xtensa/port.c:143

owensc84 commented 3 years ago

I see the error "I (1708) coexist: [854006] Error! Should enable WiFi modem sleep when both WiFi and Bluetooth ar"

I have set the modem sleep, see image below. Is there another place I need to modify the modem sleep options? image

owensc84 commented 3 years ago

My sdkconfig can be found here, https://github.com/espressif/esp-mdf/issues/159#issuecomment-666777234

owensc84 commented 3 years ago

I turned on wifi modem sleep by, MDF_ERROR_ASSERT(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));. I also moved the bluetooth initialization to before the wifi. It still crashes the ESP32 with an error about the modem sleep.

Logs

I (31) boot: ESP-IDF v4.3-dev-134-g625bd5eb1 2nd stage bootloader
I (31) boot: compile time 17:32:16
I (31) boot: chip revision: 3
I (35) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (42) boot.esp32: SPI Speed      : 40MHz
I (47) boot.esp32: SPI Mode       : DIO
I (52) boot.esp32: SPI Flash Size : 4MB
I (56) boot: Enabling RNG early entropy source...
I (62) boot: Partition Table:
I (65) boot: ## Label            Usage          Type ST Offset   Length
I (72) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (80) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (87) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (95) boot:  3 ota_0            OTA app          00 10 00010000 001e0000
I (102) boot:  4 ota_1            OTA app          00 11 001f0000 001e0000
I (110) boot:  5 coredump         Unknown data     01 03 003d0000 00010000
I (117) boot:  6 reserved         Unknown data     01 fe 003e0000 00020000
I (125) boot: End of partition table
I (129) boot_comm: chip revision: 3, min. application chip revision: 0
I (136) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x3a5b4 (239028) map
I (237) esp_image: segment 1: paddr=0x0004a5dc vaddr=0x3ffbdb60 size=0x04ed8 ( 20184) load
I (245) esp_image: segment 2: paddr=0x0004f4bc vaddr=0x40080000 size=0x00404 (  1028) load
0x40080000: _WindowOverflow4 at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (246) esp_image: segment 3: paddr=0x0004f8c8 vaddr=0x40080404 size=0x00750 (  1872) load
I (253) esp_image: segment 4: paddr=0x00050020 vaddr=0x400d0020 size=0x1013c0 (1053632) map
0x400d0020: _stext at ??:?

I (662) esp_image: segment 5: paddr=0x001513e8 vaddr=0x40080b54 size=0x1bd7c (114044) load
I (727) boot: Loaded app from partition at offset 0x10000
I (728) boot: Disabling RNG early entropy source...
I (728) cpu_start: Pro cpu up.
I (732) cpu_start: Application information:
I (736) cpu_start: Project name:     get_started
I (742) cpu_start: App version:      1
I (746) cpu_start: Compile time:     Jul 30 2020 18:31:54
I (752) cpu_start: ELF file SHA256:  d1019f1c637662aa...
I (758) cpu_start: ESP-IDF:          v4.3-dev-134-g625bd5eb1
I (765) cpu_start: Single core mode
I (769) heap_init: Initializing. RAM available for dynamic allocation:
I (776) heap_init: At 3FF80000 len 00002000 (8 KiB): RTCRAM
I (782) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (788) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (794) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (801) heap_init: At 3FFD0FA8 len 0000F058 (60 KiB): DRAM
I (807) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (813) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (819) heap_init: At 4009C8D0 len 00003730 (13 KiB): IRAM
I (825) cpu_start: Pro cpu start user code
I (843) spi_flash: detected chip: gd
I (844) spi_flash: flash io: dio
I (844) esp_core_dump_flash: Init core dump to flash
I (847) esp_core_dump_flash: Found partition 'coredump' @ 3d0000 65536 bytes
I (861) esp_core_dump_flash: Found core dump 29104 bytes in flash @ 0x3d0000
I (862) cpu_start: Starting scheduler on PRO CPU.
I (885) BTDM_INIT: BT controller compile version [826d7c6]
I (887) system_api: Base MAC address is not set
I (887) system_api: read default base MAC address from EFUSE
I (986) phy: phy_version: 4182, f1ba940, Jun  4 2020, 19:40:07, 0, 0
I (1221) BLE_ANCS: init_ancs init bluetooth
I (1349) BLE_ANCS: REG_EVT
I (1384) wifi:wifi driver task: 3ffd85b0, prio:23, stack:6656, core=0
I (1401) wifi:wifi firmware version: 0507408
I (1402) wifi:wifi certification version: v7.0
I (1402) wifi:config NVS flash: enabled
I (1402) wifi:config nano formating: disabled
I (1406) wifi:Init dynamic tx buffer num: 32
I (1410) wifi:Init data frame dynamic rx buffer num: 32
I (1415) wifi:Init management frame dynamic rx buffer num: 32
I (1421) wifi:Init management short buffer num: 32
I (1425) wifi:Init static rx buffer size: 1600
I (1429) wifi:Init static rx buffer num: 10
I (1433) wifi:Init dynamic rx buffer num: 32
I (1440) BLE_ANCS: advertising start success
I (1445) wifi:Set ps type: 1

I (1452) wifi:mode : sta (fc:f5:c4:3c:55:00)
I (1453) [mwifi, 292]: esp-mdf version: v1.0-67-g3894d47
I (1456) wifi:mode : sta (fc:f5:c4:3c:55:00) + softAP (fc:f5:c4:3c:55:01)
I (1463) wifi:Total power save buffer number: 16
I (1466) wifi:Init max length of beacon: 752/752
I (1471) wifi:Init max length of beacon: 752/752
I (1475) mesh: <nvs>read layer:0, err:0x1102
I (1479) mesh: <nvs>read assoc:0, err:0x1102
I (1483) mesh: [IO]disable self-organizing<reconnect>
I (1488) mesh: [CONFIG]invalid router settings, ssid_len:0, ssid:, bssid:00:00:00:00:00:00
I (2204) wifi:Set ps type: 0

E (2205) wifi:Error! Should enable WiFi modem sleep when both WiFi and Bluetooth are enabled!!!!!!

abort() was called at PC 0x4019f607 on core 0
0x4019f607: pm_set_sleep_type at ??:?

Backtrace:0x4008d31f:0x3ffd83e0 0x4008d981:0x3ffd8400 0x4009460e:0x3ffd8420 0x4019f607:0x3ffd8490 0x4018ae24:0x3ffd84b0 0x4018994e:0x3ffd84d0 0x40096346:0x3ffd84f0 0x4008d989:0x3ffd8520
0x4008d31f: panic_abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_system/panic.c:330

0x4008d981: esp_system_abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_system/system_api.c:100

0x4009460e: abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/newlib/abort.c:46

0x4019f607: pm_set_sleep_type at ??:?

0x4018ae24: wifi_set_ps_process at ??:?

0x4018994e: ieee80211_ioctl_process at ??:?

0x40096346: ppTask at ??:?

0x4008d989: vPortTaskWrapper at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/freertos/xtensa/port.c:143

ELF file SHA256: d1019f1c637662aa

I (2220) esp_core_dump_flash: Save core dump to flash...
I (2226) esp_core_dump_elf: Found tasks: 17
I (2232) esp_core_dump_flash: Erase flash 32768 bytes @ 0x3d0000
I (2646) esp_core_dump_flash: Write end offset 0x71a8, check sum length 4
I (2646) esp_core_dump_flash: Core dump has been saved to flash.
Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:7256
load:0x40078000,len:13696
ho 0 tail 12 room 4
load:0x40080400,len:4000
0x40080400: _init at ??:?

entry 0x40080688
I (31) boot: ESP-IDF v4.3-dev-134-g625bd5eb1 2nd stage bootloader
I (31) boot: compile time 17:32:16
I (31) boot: chip revision: 3
I (35) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (42) boot.esp32: SPI Speed      : 40MHz
I (47) boot.esp32: SPI Mode       : DIO
I (51) boot.esp32: SPI Flash Size : 4MB
I (56) boot: Enabling RNG early entropy source...
I (62) boot: Partition Table:
I (65) boot: ## Label            Usage          Type ST Offset   Length
I (72) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (80) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (87) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (95) boot:  3 ota_0            OTA app          00 10 00010000 001e0000
I (102) boot:  4 ota_1            OTA app          00 11 001f0000 001e0000
I (110) boot:  5 coredump         Unknown data     01 03 003d0000 00010000
I (117) boot:  6 reserved         Unknown data     01 fe 003e0000 00020000
I (125) boot: End of partition table
I (129) boot_comm: chip revision: 3, min. application chip revision: 0
I (136) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x3a5b4 (239028) map
I (236) esp_image: segment 1: paddr=0x0004a5dc vaddr=0x3ffbdb60 size=0x04ed8 ( 20184) load
I (245) esp_image: segment 2: paddr=0x0004f4bc vaddr=0x40080000 size=0x00404 (  1028) load
0x40080000: _WindowOverflow4 at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (246) esp_image: segment 3: paddr=0x0004f8c8 vaddr=0x40080404 size=0x00750 (  1872) load
I (253) esp_image: segment 4: paddr=0x00050020 vaddr=0x400d0020 size=0x1013c0 (1053632) map
0x400d0020: _stext at ??:?

I (662) esp_image: segment 5: paddr=0x001513e8 vaddr=0x40080b54 size=0x1bd7c (114044) load
I (727) boot: Loaded app from partition at offset 0x10000
I (727) boot: Disabling RNG early entropy source...
I (728) cpu_start: Pro cpu up.
I (731) cpu_start: Application information:
I (736) cpu_start: Project name:     get_started
I (742) cpu_start: App version:      1
I (746) cpu_start: Compile time:     Jul 30 2020 18:31:54
I (752) cpu_start: ELF file SHA256:  d1019f1c637662aa...
I (758) cpu_start: ESP-IDF:          v4.3-dev-134-g625bd5eb1
I (764) cpu_start: Single core mode
I (769) heap_init: Initializing. RAM available for dynamic allocation:
I (776) heap_init: At 3FF80000 len 00002000 (8 KiB): RTCRAM
I (782) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (788) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (794) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (800) heap_init: At 3FFD0FA8 len 0000F058 (60 KiB): DRAM
I (807) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (813) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (819) heap_init: At 4009C8D0 len 00003730 (13 KiB): IRAM
I (825) cpu_start: Pro cpu start user code
I (843) spi_flash: detected chip: gd
I (844) spi_flash: flash io: dio
I (844) esp_core_dump_flash: Init core dump to flash
I (847) esp_core_dump_flash: Found partition 'coredump' @ 3d0000 65536 bytes
I (860) esp_core_dump_flash: Found core dump 29096 bytes in flash @ 0x3d0000
I (862) cpu_start: Starting scheduler on PRO CPU.
I (884) BTDM_INIT: BT controller compile version [826d7c6]
I (886) system_api: Base MAC address is not set
I (886) system_api: read default base MAC address from EFUSE
I (980) phy: phy_version: 4182, f1ba940, Jun  4 2020, 19:40:07, 0, 0
I (1213) BLE_ANCS: init_ancs init bluetooth
I (1342) BLE_ANCS: REG_EVT
I (1380) wifi:wifi driver task: 3ffd85a8, prio:23, stack:6656, core=0
I (1394) wifi:wifi firmware version: 0507408
I (1394) wifi:wifi certification version: v7.0
I (1394) wifi:config NVS flash: enabled
I (1395) wifi:config nano formating: disabled
I (1399) wifi:Init dynamic tx buffer num: 32
I (1403) wifi:Init data frame dynamic rx buffer num: 32
I (1408) wifi:Init management frame dynamic rx buffer num: 32
I (1413) wifi:Init management short buffer num: 32
I (1418) wifi:Init static rx buffer size: 1600
I (1422) wifi:Init static rx buffer num: 10
I (1426) wifi:Init dynamic rx buffer num: 32
I (1433) BLE_ANCS: advertising start success
I (1437) wifi:Set ps type: 1

I (1445) wifi:mode : sta (fc:f5:c4:3c:55:00)
I (1446) [mwifi, 292]: esp-mdf version: v1.0-67-g3894d47
I (1448) wifi:mode : sta (fc:f5:c4:3c:55:00) + softAP (fc:f5:c4:3c:55:01)
I (1456) wifi:Total power save buffer number: 16
I (1458) wifi:Init max length of beacon: 752/752
I (1463) wifi:Init max length of beacon: 752/752
I (1468) mesh: <nvs>read layer:0, err:0x1102
I (1471) mesh: <nvs>read assoc:0, err:0x1102
I (1476) mesh: [IO]disable self-organizing<reconnect>
I (1481) mesh: [CONFIG]invalid router settings, ssid_len:0, ssid:, bssid:00:00:00:00:00:00
I (2196) wifi:Set ps type: 0

E (2197) wifi:Error! Should enable WiFi modem sleep when both WiFi and Bluetooth are enabled!!!!!!

abort() was called at PC 0x4019f607 on core 0
0x4019f607: pm_set_sleep_type at ??:?

Backtrace:0x4008d31f:0x3ffd83e0 0x4008d981:0x3ffd8400 0x4009460e:0x3ffd8420 0x4019f607:0x3ffd8490 0x4018ae24:0x3ffd84b0 0x4018994e:0x3ffd84d0 0x40096346:0x3ffd84f0 0x4008d989:0x3ffd8520
0x4008d31f: panic_abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_system/panic.c:330

0x4008d981: esp_system_abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/esp_system/system_api.c:100

0x4009460e: abort at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/newlib/abort.c:46

0x4019f607: pm_set_sleep_type at ??:?

0x4018ae24: wifi_set_ps_process at ??:?

0x4018994e: ieee80211_ioctl_process at ??:?

0x40096346: ppTask at ??:?

0x4008d989: vPortTaskWrapper at C:/eds/call_light/git/esp_mesh/esp-mdf/esp-idf/components/freertos/xtensa/port.c:143
owensc84 commented 3 years ago

My entire project for reference. get-started.zip

EspHuifeng commented 3 years ago

can you delete this line in your code and try again. https://github.com/espressif/esp-mdf/blob/3894d4762cbd0682b042e8681f930f5a1d939505/examples/get-started/main/get_started.c#L170

owensc84 commented 3 years ago

can you delete this line in your code and try again.

https://github.com/espressif/esp-mdf/blob/3894d4762cbd0682b042e8681f930f5a1d939505/examples/get-started/main/get_started.c#L170

@EspHuifeng , thank you for the suggestion.

I have tried to remove that line and update that line with MDF_ERROR_ASSERT(esp_wifi_set_ps(WIFI_PS_MIN_MODEM)); with the same result.

owensc84 commented 3 years ago

I took a closer look at the logs, and it looks like wifi sets the power save to 1 (min. modem) and shortly after sets it back to 0 (none). See logs below. Any ideas on how to prevent the wifi power save mode from changing to none?

I (1030) phy: phy_version: 4182, f1ba940, Jun  4 2020, 19:40:07, 0, 0
I (1032) wifi:mode : sta (fc:f5:c4:3c:55:00)
///////////////////////////////////////////////////////////
I (1033) wifi:Set ps type: 1
///////////////////////////////////////////////////////////

I (1034) [mwifi, 292]: esp-mdf version: v1.0-69-gf8e8807
I (1039) wifi:mode : sta (fc:f5:c4:3c:55:00) + softAP (fc:f5:c4:3c:55:01)
I (1047) wifi:Total power save buffer number: 16
I (1050) wifi:Init max length of beacon: 752/752
I (1054) wifi:Init max length of beacon: 752/752
I (1059) mesh: <nvs>read layer:0, err:0x1102
I (1062) mesh: <nvs>read assoc:0, err:0x1102
I (1067) mesh: [IO]disable self-organizing<reconnect>
I (1072) mesh: [CONFIG]invalid router settings, ssid_len:0, ssid:, bssid:00:00:00:00:00:00
////////////////////////////////////////////////////////////////
I (1683) wifi:Set ps type: 0
////////////////////////////////////////////////////////////////
EspHuifeng commented 3 years ago

Can you checkout esp-idf/components/esp_wifi/lib to 511dd9e12 and try again.

owensc84 commented 3 years ago

Can you checkout esp-idf/components/esp_wifi/lib to 511dd9e12 and try again.

I have started using the esp-mdf at tag release/v1.0 and the issue cleared itself up. I will continue to use release/v1.0 in my development and let you know if I have any other issues.

Thanks again for your help!

KaranRajPradhan commented 3 years ago

I'm facing the same issue however. Using branch release/v1.0 with commit hash gd0196da. Using the following components: Bluetooth: BLE GATT server WiFi aws_iot Mesh (esp-mdf)

Getting the following crash logs:

I (15555) BLE_COMMON: Now initialising BLE
I (15555) BTDM_INIT: BT controller compile version [66c0831]
I (15555) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (15565) coexist: [15540003] Error! Should enable WiFi modem sleep when both WiFi and Bluetooth 
abort() was called at PC 0x400f83f6 on core 0
0x400f83f6: coex_init at ??:?

ELF file SHA256: d3e29ff9752c314f

Backtrace: 0x4008cf5f:0x3fff27f0 0x4008d0e5:0x3fff2810 0x400f83f6:0x3fff2830 0x400d162f:0x3fff2850 0x400d1671:0x3fff2870 0x400d18a5:0x3fff28a0 0x40140448:0x3fff28d0 0x4013e259:0x3fff28f0 0x401925c2:0x3fff2940
0x4008cf5f: invoke_abort at /home/karan/esp/esp-mdf/esp-idf/components/esp32/panic.c:136

0x4008d0e5: abort at /home/karan/esp/esp-mdf/esp-idf/components/esp32/panic.c:171

0x400f83f6: coex_init at ??:?

0x400d162f: esp_phy_rf_init at /home/karan/esp/esp-mdf/esp-idf/components/esp32/phy_init.c:570

0x400d1671: esp_phy_rf_init at /home/karan/esp/esp-mdf/esp-idf/components/esp32/phy_init.c:570

0x400d18a5: esp_phy_load_cal_and_init at /home/karan/esp/esp-mdf/esp-idf/components/esp32/phy_init.c:716

0x40140448: esp_bt_controller_enable at /home/karan/esp/esp-mdf/esp-idf/components/bt/bt.c:1415

0x4013e259: init_ble at /home/karan/code/iotready/joovv/joovv-mesh/firmware/source/components/ble/ble_common.c:113

0x401925c2: aws_iot_task at /home/karan/code/iotready/joovv/joovv-mesh/firmware/source/components/aws/aws_control.c:455

Rebooting...

Can you checkout esp-idf/components/esp_wifi/lib to 511dd9e12 and try again. @EspHuifeng There seems to be no esp_wifi directory in esp-idf/components/ Screenshot from 2020-08-19 22-48-47

EspHuifeng commented 3 years ago

It would be ok if you init ble before start mesh. But we don't recommend open ble and wifi-mesh at the same time, because wifi-mesh and ble will effect each other.

owensc84 commented 3 years ago

It would be ok if you init ble before start mesh. But we don't recommend open ble and wifi-mesh at the same time, because wifi-mesh and ble will effect each other.

Why do you say this? We are currently developing a product that will utilize BLE and wifi-mesh at the same time. The esp-mdf documentation states that "Simultaneously run Wi-Fi and BLE protocol stacks." Source of that quote.

Are you saying we should go a different direction if we need to access a mesh network an BLE?

EspHuifeng commented 3 years ago

We recommend not to use WiFi-MESH and BLE at the same time, these two do not currently work well.

hilgertd commented 3 years ago

@EspHuifeng please explain what you mean? Are you saying BLE and WiFi-Mesh can never be used at the same time?

EspHuifeng commented 3 years ago

If wifi-mesh and ble work together, the rate and stability of wifi-mesh and ble will be affected both. The current idf ble and wifi libraries will require that WiFi modem sleep (PS type is not 0) mode must be enabled when coexisting, and this parameter will be checked during initialization. due to the wifi-mesh will set PS type to 0 after start. If you don't care about these effects, you can bypass this check, that is, first enable the wifi modem sleep mode, then set the ble, and finally start the mesh.

bbinet commented 3 years ago

@EspHuifeng Is this compatibility issue planned to be fixed in the (near) future? so that we can use BLE to manage the wifi mesh locally with no internet connection required?

ClaesIvarsson commented 3 years ago

I would also like to know when this is planned to be fixed. In my project we plan to use BLE GATT server together with mesh wifi.

browningweb commented 3 years ago

so, any progress? We also plan to use ble together with mesh. ble & mesh wifi gateway.

ghost commented 2 years ago

I have faced the same problem with IDF WIFI-MESH component. Even with enabling power-saving on both WiFi and Gatt a system panic will occur. I fixed this by enabling the WiFi-MESH power-saving mode [esp_mesh_enable_ps()]. Since WiFi-MESH uses WiFi internally it will affect the WiFi settings. So, try to find-out how to enable mesh power-saving mode on MDF.

benhugsmart commented 2 years ago

I'm also wondering if BLE + Mesh stability is likely to be improved in the near future? Our application requires both to be used at the same time.

Leadrive commented 1 year ago

@EspHuifeng 我测试过 esp-mesh-lite项目,启用wifi后,照样是可以用ble的。 麻烦你们更新一下吧,我都为你们感到脸红,那么多人用来做项目,你们说停就停了,有问题也不解决。 关键是这部分还不开源,别人想改还改不了。