BLE/NRF error

Posted on
Page
of 2
/ 2
Next
  • I am trying to send this command to my ESP32:

    NRF.setServices({
      "a1841901-9ed1-49b3-b998-172d8f29b213" : {
        "a1841902-9ed1-49b3-b998-172d8f29b213" : {
          readable : true,
          writable : true,
          notify : true,
          onWrite: (event) => {
            console.log("Got: ", event);
          }
        }
      }
    });
    NRF.setAdvertising({}, { name: "ISP" });
    

    Then the console reported an error:

    F 0
    F 0
    Uncaught Error: invalid Char UUID:UUID string should only contain hex characters and dashes at line 12 col 2
    });

    I changed the Char UUID to 0x1901, but it still doesn't work.

  • Is there a problem with the regular expression for verifying Char UUID's validity?

  • try removing quotes? at least with 16bit ones it worked without quotes for me (on nrf52)

  • so sad... it dosen't work, told me:

    Error parsing JavaScript, but uploading anyway.
    SyntaxError: Unexpected token (3:12)

    Uncaught SyntaxError: Got '-' expected ':'
    at line 3 col 13
    a1841902-9ed1-49b3-b998-172d8f29b213 : {

  • recent now, I've tried:

    a1841902-9ed1-49b3-b998-172d8f29b213 : {...

    and:

    "a1841902-9ed1-49b3-b998-172d8f29b213" : {...

    and:

    'a1841902-9ed1-49b3-b998-172d8f29b213' : {...

    and:

    0x1902 : {...

    and:

    "0x1902" : {...

    and:

    '0x190' : {...

    none of them succeeded.

  • Just tried your original code with quotes with nrf52 and it works as is with no change so it is issue of ESP32 port.
    Also this works on nrf52 (16bit ids without double quotes)

    NRF.setServices({
      0x1901 : {
        0x1902 : {
          readable : true,
          writable : true,
          notify : true,
          onWrite: (event) => {
            console.log("Got: ", event);
          }
        }
      }
    });
    NRF.setAdvertising({}, { name: "ISP" });
    

    and even this works with long ids without quotes and dashes

    NRF.setServices({
      a18419019ed149b3b998172d8f29b213 : {
        a18419029ed149b3b998172d8f29b213 : {
          readable : true,
          writable : true,
          notify : true,
          onWrite: (event) => {
            console.log("Got: ", event);
          }
        }
      }
    });
    

    and I verified in nrfConnect that those IDs are indeed used correctly when connecting to the device.

    So looks like parsing of BLE ids for ESP32 is done by different code than for nrf52 and it does not work as expected.

  • Oh that is strange. The code is common for all platforms
    https://github.com/espruino/Espruino/blob/master/libs/bluetooth/bluetooth_utils.c#L135
    and the error message you see in your first example is here
    https://github.com/espruino/Espruino/blob/master/libs/bluetooth/bluetooth_utils.c#L167

    Are you using recent/latest version of Espruino?

    EDIT: the specific ESP32 code printing the message starting with "invalid Char UUID:" is here
    https://github.com/espruino/Espruino/blob/master/targets/esp32/BLE/esp32_gatts_func.c#L453
    but for parsing it is calling the common bleVarToUUIDAndUnLock method

    and what is also strange is that it probably parses the service ID in same format
    on line 510, before it breaks few lines below on parsing characteristics here
    https://github.com/espruino/Espruino/blob/master/targets/esp32/BLE/esp32_gatts_func.c#L521
    so looks like maybe it reads the string from some wrong place and gets some garbage(?)

  • sorry, I don't use ESP32 very much but when looking at similar nrf52 code here
    https://github.com/espruino/Espruino/blob/master/targets/nrf5x/bluetooth.c#L3127
    I think it takes &serviceit which is JsvObjectIterator serviceit;
    while I think in ESP32 code it already takes pointer to iterator https://github.com/espruino/Espruino/blob/master/targets/esp32/BLE/esp32_gatts_func.c#L448 JsvObjectIterator *ble_char_it and it passes another reference to it
    https://github.com/espruino/Espruino/blob/master/targets/esp32/BLE/esp32_gatts_func.c#L452 jsvObjectIteratorGetKey(&ble_char_it)

    I guess there should be ble_char_it used instead of &ble_char_it in that method (possibly in more places).

    If you can build from source maybe you can try to fix it?

  • It is issue of ESP32 port. I have just tried the code without quotes and dashes:

    NRF.setServices({
      a18419019ed149b3b998172d8f29b213 : {
        a18419029ed149b3b998172d8f29b213 : {
          readable : true,
          writable : true,
          notify : true,
          onWrite: (event) => {
            console.log("Got: ", event);
          }
        }
      }
    });
    NRF.setAdvertising({}, { name: "ISP" });
    

    It does not work.

    F 6
    F 0
    Uncaught Error: invalid Char UUID:UUID string should only contain hex characters and dashes at line 12 col 2
    });

    May be there are some bugs in ESP32 code.

  • Yes, Espruino firmware version of my ESP32 board was updated to 2v21 version.
    Seems the problem is not with the public code, but rather with EPS32.

  • May be there are some bugs in ESP32 code

    yes, it is not so stable, there is no official ESP32 based Espruino device so this is just community effort.
    I don't have device to test but I think this could help

    diff --git a/targets/esp32/BLE/esp32_gatts_func.c b/targets/esp32/BLE/esp32_gatts_func.c
    index 7fd09fdc2..30d7171b5 100644
    --- a/targets/esp32/BLE/esp32_gatts_func.c
    +++ b/targets/esp32/BLE/esp32_gatts_func.c
    @@ -449,10 +449,10 @@ void gatts_char_init(JsvObjectIterator *ble_char_it){
       const char *errorStr;
       ble_uuid_t ble_uuid;
       gatts_char[ble_char_pos].service_pos = ble_service_pos;
    -  if((errorStr = bleVarToUUIDAndUnLock(&ble_uuid,jsvObjectIteratorGetKey(&ble_char_it)))){
    +  if((errorStr = bleVarToUUIDAndUnLock(&ble_uuid,jsvObjectIteratorGetKey(ble_char_it)))){
         jsExceptionHere(JSET_ERROR,"invalid Char UUID:%s",errorStr);
       }
    -  JsVar *charVar = jsvObjectIteratorGetValue(&ble_char_it);
    +  JsVar *charVar = jsvObjectIteratorGetValue(ble_char_it);
       gatts_char[ble_char_pos].char_uuid.len = ESP_UUID_LEN_16;
       gatts_char[ble_char_pos].char_uuid.uuid.uuid16 = ble_uuid.uuid;
       gatts_char[ble_char_pos].char_perm = 0;
    

    attached is result of the build with that patch applied. maybe it helps, maybe you'll hit another bug


    1 Attachment

  • It's so nice of you!
    Your guidance and tips have given me lots of inspiration and encouragement, yet it also poses certain challenges for me. I'll try to build from source and try to fix it during this summer vacation! ^_^

  • wow! Thank you!

  • I'll try to build from source

    it is actually very easy, on typical linux (ubuntu, debian) or in WSL you just checkout the Espruino github repo and run provision script that will download stuff for specific BOARD and its platform. I think on Ubuntu this works just with apt-get install build-essential python-is-python3 python3-pip git curl

    ~$ git clone https://github.com/espruino/Espruino ; cd Espruino
    ~/Espruino$ . scripts/provision.sh ESP32
    Provision BOARDNAME = ESP32
    Provision FAMILY = ESP32
    ===== ESP32
    pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
    python/pip installed
    pyserial installed
    installing app folder
    installing esp-idf folder
    installing xtensa-esp32-elf-gcc
    ESP_IDF_PATH=/home/fanoush/Espruino/esp-idf
    ESP_APP_TEMPLATE_PATH=/home/fanoush/Espruino/app
    PATH=$PATH:/home/fanoush/Espruino/xtensa-esp32-elf/bin/
    GCC is /home/fanoush/Espruino/xtensa-esp32-elf/bin//xtensa-esp32-elf-gcc
    ~/Espruino$ make BOARD=ESP32 RELEASE=1 clean
    Cleaning targets
    ~/Espruino$ make BOARD=ESP32 RELEASE=1
    

    Also you can trick it and just use github to build it for you, ESP32 is part of build checks, so if you go to
    https://github.com/espruino/Espruino and click the green checkmark next to some recent commit you go e.g. to
    https://github.com/espruino/Espruino/actions/runs/8781555980/job/24093818739
    if you expand the "Upload ESP32 Artifact" step there is

    Artifact ESP32 has been successfully uploaded! Final size is 2908638 bytes. Artifact ID is 1434877087
    Artifact download URL: https://github.com/espruino/Espruino/actions/runs/8781555980/artifacts/1434877087
    

    so just click that link to download zip of build results for that commit.

    So you can just fork Espruino repo, push change(s) to your forked repo and get the result zip of your custom ESP32 build.

  • @fanoush nice finding, will create a pr for this, so it will be part in one of the next ES32 builds.

  • Well but does it work? I did not test it.

  • I will run some test before creating a pr.

  • It works! It works! It's actually well done! WOW~ It's splended!

  • This is really wonderful! This further enhances my motivation to handle many tasks later on, Many thanks for you!

  • This is really wonderful. Thank you all very much for your selfless and kind work, which has inspired me so much!

  • After solving the existing problems, I found that callback function for onWrite() is not implemented.
    And Unable to implement the notify and indicate, my phone always reports error when sending notification listening requests to ESP32.

    NRF.setServices({
      0x1901: {
        0x1902: {
          value : "Hello",
          broadcast : true,
          readable : true,
          writable : true,
          notify : true,
          indicate: true,
          onWrite: (event) => {
            console.log("Got: ", event);
          }
        }
      }
    });
    
  • There are indeed some issues with ESP32, sad...

  • I plan to learn the source code when I have some free time in a while and try to solve this problem (since I don't have a hardware background myself, I actually find it a bit difficult, though you say it's easy).

  • There are indeed some issues with ESP32, sad

    Yes, not a long time ago only advertising worked well on ESP32 so even this state is much better. If setting up service with characteristics did not work (at all I guess?) and is fixed only now it means nobody used it before. Does at least reading and writing values of characteristics work? As a workaround for now it may be good enough to read characteristics periodically instead of using notifications.

    Oh but you said writing does not work because the callback is not called so you don't get the new value. Oh, well.

    I don't know what project are you working on but if you just need some bidirectional communication you may use the interpreter console itself over BLE to pass the data. Sorry I don't use ESP32 with Espruino for BLE so I am not sure what already works, @MaBe does at least the Nordic UART console work over BLE on ESP32?

    Or maybe @Gordon knows what is BLE state for ESP32 and what is still missing? I've seen some significant BLE related work done for ESP32 port in recent year.

  • Check issue #1777 Improve ESP32 implementation for fixed and open issues. Gordon implelemnted the uart part and it works perfect.

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

BLE/NRF error

Posted by Avatar for SI_Cheng-Yun @SI_Cheng-Yun

Actions