Status of Bluetooth for ESP32

Posted on
  • I spend lot of days to get Bluetooth up and running in a very first simple step
    So is time to give a first status.
    To be open, I'm not sure, we will ever get it running in a nice way.
    Memory consumption in binary file and in RAM is huuuuge

    This is what I did in some short steps:

    1. got the example from esp-idf for UART-Server running
    2. got connected from my mobile, using nRF Toolbox
    3. rebuilt source and added to Espruino/targets/ESP32
    4. got huge binary, up to 1400KB
    5. created a new partition table to support this big application size
    6. flashed and got "no heap" and reset, reset, ....
    7. changed config and removed classic Bluetooth and some other memory eater
    8. tons of problems, sometimes even without any error message
    9. had to reduce jsvars from 5000 down to 2000 and now its working

    There is still no functionality available in Javascript, and UART is receiving data only.
    Question is, should I spend more time on this, or wait for availibility of breadboards with ESP32 wrover which has additional PSRAM.

  • Hi @JumJum
    Well at least it is progress of sorts. Which ever way you go, it would be great to capture what you have learnt, so we can get back to this point later...

    So, perhaps start a new branch esp32-ble and put the espruino changes under that, and also a new branch under espruino build tools with the same name, that will capture the partition changes and sdkconfig changes.

    I can get this all working with Travis if you like - then if we want to return to this point, or someone else want to pick up the gauntlet, we have a starting point.

    I think the bluedroid libraries might be quite large - but at the end of the day there is plenty of flash, it's the ram there the issue.

    It would be great to get it working, as a ble to wifi bridge would be awesome.

    Contact me on gitter if you would like some help.

  • Actual status of my work for Bluetooth is here­e/ESP32/targets/esp32/docs/Bluetooth_fir­st_attempt
    @wilberforce, tried to contact you on gitter, without success.

  • Just tested mem release function for BLE and got about 30k back.
    Will do some more testing, but looks like we will get up to 2000 vars back :)

    BTW, after some chatting with Gordon, I'll try to come closer to already existing Bluetooth in Espruino (for Puck.js). World is different between nrf and esp-idf, so this will take some time.

  • I was able to get the ESP32 branch of Espruino to build with functional BT but I had to modify line 45 of targets/esp32/bluetooth.c

    if(ret) {jsWarn("mem release failed:%x\n",ret); /*return;*/}

    It always fails trying to release ESP_BT_MODE_BTDM and if it returns none of the following initialization gets executed.

    Is there any newer version of this? It seems like a work in progress...

  • First of all, BLE is work in progress. From time to time changes are uploaded.
    At same time, esp-idf is changed very often.
    Since this is my hobby only, please don't expect a full blown up implementation soon.
    Your problem seems to be one of those changes in esp-idf. Sequence of calls during setup (and params for release ??) changed.
    You could try this

    void jsble_init(){
        esp_err_t ret;
        ret = esp_bt_controller_mem_release(ESP_BT_MOD­E_CLASSIC_BT);
        if(ret) {jsWarn("mem release failed:%x\n",ret); return;}
        esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
        ret = esp_bt_controller_init(&bt_cfg);if(ret) {jsWarn("initialize controller failed:%x\n",ret); return;}
        ret = esp_bt_controller_enable(ESP_BT_MODE_BLE­);if(ret) {jsWarn("enable controller failed:%x\n",ret); return;}
        ret = esp_bluedroid_init();if (ret) {jsWarn("init bluetooth failed:%x\n",ret);return;}
        ret = esp_bluedroid_enable();if (ret) {jsWarn("enable bluetooth failed:%x\n",ret);return;}
        ret = esp_ble_gap_register_callback(gap_event_­handler);if (ret){jsWarn("gap register error:%x\n", ret);return;}
        ret = esp_ble_gatts_register_callback(gatts_ev­ent_handler);if(ret){jsWarn("gatts register error:%x\n", ret);return;}
  • ret = esp_bt_controller_mem_release(ESP_BT_MOD­E_CLASSIC_BT);
     if(ret) {jsWarn("mem release failed:%x\n",ret); return;}

    This version does work. I left the ret = esp_ble_gatt_set_local_mtu(500); section in place at the end.


  • I've abandoned Espruino, its performance is just insufficient for my application. I've switched to a duktape javascript engine.­

    Their bluetooth implementation hasn't been fleshed out. I think your work on the Espruino would translate well.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Status of Bluetooth for ESP32

Posted by Avatar for JumJum @JumJum