• Hello,
    I am trying to communicate with a Ble peripheral that need a password to be bounded.
    I used the BleScanner code to find the device without a single problem. Now I am trying to access to the device's characteristics.
    I tried to do the following :
    -NRF.scan -> returns BluetoothDevice.
    -NRF.connect(device.id) -> returns BluetoothRemoteGattServer (let's call it g as in examples).
    -g.startBonding() -> returns a resolved promise.
    -g.getPrimaryService("UUID")->generates an uncaught error : BLE error 0x11 (BUSY).
    I also tried without the bonding part, with the same result.

    I tried to add the 'passKeyRequest' handler in order to use sendPasskey function (after I scanned and after I used NRF.connect(device.id) ), but it didn't work : 'the callback function is never called (I put a console.log inside it).

    you can find attached a simplier version of the code I made.
    Best regards,
    Nicolas


    1 Attachment

  • Hi,

    Which firmware version do you have on the Bangle? This may actually be unrelated to pairing.

    On 2v09 I added increased MTUs, but those require some negotiating and we found that when both devices support larger MTUs you actually needed a delay to let them finish.

    I think Cutting Edge firmwares have this fixed, but maybe the code below will work for you? It just adds a setTimeout

    scan = ()=>{
      NRF.findDevices(devices => {
        for (let device of devices) {
          // Only display devices that advertise a name
            if (device.name) {
              addMenuItem(device);
            }
        }
      }, {timeout:3000,active: true });
    };
    
    addMenuItem = (device)=>{
      console.log(device);
    
      //first attemp of sending the password
      /*device.on('passkeyRequest', function() {
        console.log("passKeyRequested");
        device.sendPasskey("012034");
      });
      */
      //adding a item to the menu, trying to connect when item is pressed
      scanMenu[device.name]= ()=>{
        console.log(device); // is displayed the device
        NRF.connect(device.id)
          .then((g)=>{
            console.log("NRF connection ok!");//is displayed
            var gatt = g;
            console.log(gatt);
            var device = g.device;
            //Second attempt of sending password
            device.on('passkeyRequest', function() {
              console.log("passKeyRequested");
              device.sendPasskey("012034");
            });
    
          gatt.startBonding()
          .then(()=>{
            console.log("bonded", gatt.getSecurityStatus()); //displays : bonded { "connected": true, "encrypted": false, "mitm_protected": false, "bonded": true }
            return new Promise(resolve => setTimeout(resolve, 1000)); // wait 1 sec
         }).then(() => {
            return gatt.getPrimaryService("00000000-3608-4b­ee-bb82-4d09b486bc1f"); //also tried getPrimaryServices()
        //console.log(services);
          })
          .then( (services)=>{
            console.log(services); //
            return services.getCharacteristics();
          })
          .then((chars)=>{
            console.log(chars);
          })
        })
        .catch((error)=>{
          console.log(error);
        });
      };
    
  • I am using the espruino_2V09 firmware, I downloaded it this morning.
    I just tried your suggestion, it's not working. I tried different timeouts, in any case I was able to enter the callback for the passKey request.

    I have access to the peripheral so I will check with debugger what is happening from his point of view (don't expect too much I am far from expert aha), and will also try to remove the password in order to move on with the communication between devices.
    I hope it is possible to not request a password from specific devices (my goal is to prevent phones to pair but not potential other bangles).
    I will update this thread after getting infos from the peripheral.

  • Hi,
    Using the debugger, I was able to see differences between the evt displayed for an android binding and the espruino binding. As a newbie in the nrf library it's quite obscure. Something that I didn't mind till now is that on my android I have to press pair two times before connection happens, first time the pop-up has no password, pressing pair throw a pop-up with a password to enter in order to bind.

    I told you the passkey request listener wasn't called, I can see the peripheral (NRF 5SDK) is handling a "BLE_GAP_EVT_LESC_DHKEY_REQUEST" event in the case of the android, but not for the espuino.
    I can also see the BLE_GAP_EVT_TIMEOUT happening for the espruino, ending in a no bond status. What is weird is that the security status from espruino side is "bonded : true", that i can notify, read and write without throwing errors (read returns empty array).

    If you already dealt with nrf event ids, at some point the android-peripheral connection has an event with ID = 0x3A and for the espruino-peripheral it's 0x55 (GAP or GATT event).
    Sometimes I can't connect to my peripheral with both devices and the peripheral is not even throwing a peer manager event. In that case the espruino is throwing BLE error 0x11 (BUSY). But that seems not to be a related issue.

    I know most of my issues are not related to your API, I mentioned them just in case someone went through the same.
    I will now try to configure my peripheral for biding without password, this nrf...
    Best regards,

  • Ahh, I did just spot something...

    scanMenu[device.name]= ()=>{
      console.log(device); // is displayed the device
      NRF.connect(device.id)
          .then((g)=>{
            console.log("NRF connection ok!");//is displayed
            var gatt = g;
            console.log(gatt);
            var device = g.device;
            //Second attempt of sending password
            device.on('passkeyRequest', function() {
    

    By the time you add the passkeyRequest listener it's already connected - that could be it.

    Maybe try:

    scanMenu[device.name]= ()=>{
      console.log(device); // is displayed the device
      device.on('passkeyRequest', function() {
          console.log("passKeyRequested");
          device.sendPasskey("012034");
        });
      device.gatt.connect().then((g)=>{
            console.log("NRF connection ok!");//is displayed
            var gatt = g;
            console.log(gatt);
            return new Promise(resolve => setTimeout(resolve, 1000)); // wait 1 sec - just in case
     }).then(()=>{
            return gatt.startBonding()
     }).then(()=>{
    

    You also had some slightly odd nested promise stuff that could have been a bit confusing too, so I unrolled that above as well.

  • Hi,
    I modified my peripheral code to change the pairing process, I still have some issues but no more related to the bangle ! thanks for your help :)

  • Hi,
    now I have a "on value change" characteristic listener and depending on the user's action, a writeValue function call to another characteristic (from the same service).
    Sometimes I have an error : "BLE task X is already in progress" (X being 3 or 8 from my tests).
    What I understand from this error is that the "Ble manager" is already busy doing something (what may not matter).
    Could you explain me how to avoid this issue ?

  • The tasks (from https://github.com/espruino/Espruino/blo­b/master/libs/bluetooth/jswrap_bluetooth­.h#L18) are:

    3: Disconnect (eg for this task you must have actually called .disconnect() and it's now waiting for the device to disconnect)

    8: Discover descriptors and start notifications

    I wouldn't expect any of those in 'normal' operation though - so it looks like maybe your code is doing something like attempting a disconnect or reconnect in the background?

  • Hi, it's been a while I didn't use the watch for my project, and today I experienced a lot of troubles regarding Ble. I set my peripheral in pairing no bonding mode (I first tried in pairing/bonding but no password).
    My phone has succeded in connecting all the time, but not the bangle. I should say the success of the pairing is around 40%. This success rate is not bothering to conduct the tests I want.
    For the rest, i am facing a "Not connected" error (caught after get primaryService method), or a Ble error 0x11 (Busy ).

    Unfortunately, even during the data exchange of values, I faced weird behavior.
    The communication stopped without having the 'gattserverdisconnected' callback triggered.
    Even the Bluetooth communication used for debug to my computer stopped !
    The peripheral, the computer and the bangle always stay close (never farer than 3m).

    I started looking at my RSSI values for the different devices (values for devices 0 to 1m away):
    Phone detecting my peripheral (-50 to -75 using nrf connect ).
    Bangle detecting my peripheral (-85 to -95 using the value from BleScanner app ).
    Phone detecting bangle (-70 to -100 using nrf connect).

    I also used the setRSSIHandler to log the RSSI values of the signal during connection, It disconnect when values are around -85 and above (I can see the rate of the logs decreasing with the RSSI value).

    So the problem for my disconnection seems to be that the signal strengh of the Bangle is too low.
    Is there any way I can improve the signal strengh ? My issue is that the peripheral is behind the user (on his back), the body seems to affect the signal too strongly.

    You can find attached my function I use to pair, but we already exchange about it, I don't think I am doing wrong.

    Sincerely

    Edit :
    I've been able to modify the peripheral strengh of the signal through software (nothing very crazy though) using the sd_ble_gap_tx_power_set function of the nrf SDK library. I also did the same with the bangle library.
    The change on the bangle did not have visible effect. Maybe the disconnection issue is related to the min and max intervals set at the beginning of the connection ?


    1 Attachment

  • i am facing a "Not connected" error (caught after get primaryService method)

    Argh, thanks for the update! Yes, if it's related to signal strength issues then that could be quite problematic. The original Bangle.js signal strength is fine to a phone in your pocket, but it's not that strong - and there's not much you can do in software to work around that :(

    The change on the bangle did not have visible effect.

    The default for the Bangle is already the highest (4 dBm) - so that could be why?

  • So the problem for my disconnection seems to be that the signal strengh of the Bangle is too low.
    Is there any way I can improve the signal strengh ? My issue is that the peripheral is behind the user (on his back), the body seems to affect the signal too strongly.

    In real world situation this may indeed be a problem even if in more normal conditions the device sensitivity is quite good (which the bangle sadly isn't that much). maybe @enaon could comment as he uses P8, DS-D6 and other watches/fitness trackers with unicycles and connection drops outside when moving even if it works otherwise fine in house when not moving. To make it short - he finetuned antenna length as the default length was not optimal at all. looks like they cut the wire at random length and even in different pieces of same model (P8) the size of the wire was different by quite a lot and changing it did significant difference in reliability of the connection. Not sure how Bangle antenna looks but maybe similar tuning can be done.

  • Hi,
    Glad to hear that a "simple" modification as the antenna length can make a difference !
    (found this article on this topic : http://gaidi.ca/weblog/designing-a-bluet­ooth-antenna-how-to-go-about-it).

    My peripheral is using a ceramic chip antenna, bangle js too ?(from opening video, no long antenna visible...). I don't know how easy this type of antenna can be replaced.
    from https://www.digi.com/support/forum/6926/­is-it-possible-to-replace-a-chip-antenna­-with-a-wire-one , it looks possible.

    I read some old post on the forum talking about BLe efficiency, where you talked about the +4dbm max that offers the nrf chip and the fact that it is the default value.
    I did same with my peripheral (the nRF52840 chip can go up to +8dbm), the modification of the tx power only affects one Ble role . https://devzone.nordicsemi.com/f/nordic-­q-a/36531/how-do-you-set-tx-power-for-al­l-power-roles.
    Do you know if the call to the function affects everywhere ? (Anyways a change of +4dbm is not sensible, so it won't solve the issue).

  • Hi, I am using the p8 watch as a dash for electric unicycles, not very similar to the bangle.js, no gps or compass, and a monopole for the antenna, not very precise in shape or length like Fanoush said . I was too having signal problems when in open space (less reflections, more environment/motor noise).

    The p8 has good bt signal, some 10 meters indoors, yet I wanted more to keep a solid connection outdoors, so I played a bit with the monopole length. It is possible to get it to a phone level signal, the best way is trial and error, start with the longest length you can fit in a nice shape and trim off mm by mm, till you get the results you need.

    I looked at the disassembly video of the bangle.js. and I cannot see the bt antenna.
    https://www.espruino.com/Bangle.js+Disas­sembly
    I also see it has a metal bottom cap, this may explain the bt range problems. I thing it is worth the trouble to try and find the antenna, and maybe change it to a monopole and move it to the front somehow, it may help others too.

    this is a p8 in action :)
    https://www.youtube.com/watch?v=mjdcSiPK­gE4

  • Not sure how Bangle antenna looks but maybe similar tuning can be done.

    The Bangle.js is a ceramic antenna - so unfortunately it doesn't leave much room for tuning :(

    The metal back could be an issue, but there's also the battery in the way in that direction. One thing that could help is the 'NSEW' ring actually contains a bit of metal. I guess you could ping that off (although obviously it affects the watch itself).

    Not that this is much help, but the Bangle.js 2 will launch soon (developer devices are already available at https://shop.espruino.com/banglejs2-dev) and that has an nRF52840 with a plastic case and massively better signal strength

  • My only issue with the bangle 2 is the fact that the buttons disappeared.
    Idea is to use the watch possibly with gloves, I didn't find watches with a resistive touchscreen (precision of pointing with gloves on a such small screen may be ridiculous).
    So the three buttons to navigate in a menu and change parameters values is a really simple and effective way...

  • as for ceramic antenna, can one just remove it and add wire instead? or even keep it in and add wire on top of it to same PCB solder point? or is it complete nonsense that can't make things better

  • yes the ceramic antenna can be removed and replaced with a wire. It will have two contacts, one is ground, this should be left unused.

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

Trying to communicate to with a password protected Ble Device

Posted by Avatar for user132484 @user132484

Actions