BLE with BangleJS and GPS Device

Posted on
  • I have a issue when a trying to connect BangleJS2 to GPS device(BLE).

    In promise 'getPrimaryService' always get Disconnected (in catch)

    I tried with : NRF.findDevices, NRF.connect and NRF.requestDevice but its the same result.

    But, when i use bluetooth web, and NRF App(smartphone) its work.

  • I don't really know what to suggest - it's rare but usually if there is a disconnection at that point it's:

    • due to some kind of disagreement between the devices about what they support in terms of connection - like what the connection interval is
    • the device wants a secure connection (eg it wants a passkey) and nothing's been implemented on Bangle.js to provide that passkey

    Does the GPS device usually want a passkey or something like that when you connect with the phone?

  • Hi Gordon.

    The GPS device does not require any passkey or similar for connect to my phone.

    This is the link of the device: http://base.galileosky.com/articles/#!en­-documentation/developing-a-mobile-app-f­or-interacting-with-galileosky-tracking-­devices-via-bluetooth

    And this is the script that i used in web ( its work)

        <script>
            const print = (...args) => {
                console.log(...args);
            }
            const UUI_SPS = "0783b03e-8535-b5a0-7140-a304d2495cb7";
            const UUI_SERVER_TX = "0783b03e-8535-b5a0-7140-a304d2495cb8";
            const UUI_SERVER_RX = "0783b03e-8535-b5a0-7140-a304d2495cba";
            const UUI_FLOW_CTRL = "0783b03e-8535-b5a0-7140-a304d2495cb9";
            const DEVICE_NAME = "GS7X 354762118079554";
            const filters = [{ name:  [ DEVICE_NAME ] }];
            const optionalServices = [ UUI_SPS,UUI_SERVER_TX,UUI_SERVER_RX,UUI_­FLOW_CTRL ];
    
            const button = document.querySelector('button');
    
            button.addEventListener('click', demo);
    
            function demo() {
                navigator.bluetooth.requestDevice({ filters, optionalServices })
                    .then(device => device.gatt.connect())
                    .then(server => server.getPrimaryService(UUI_SPS))
                    .then(service => service.getCharacteristic(UUI_SERVER_TX)­)
                    .then(characteristic => characteristic.startNotifications())
                    .then(characteristic => {
                        characteristic.addEventListener('charact­eristicvaluechanged',
                            handleCharacteristicValueChanged);
                        print('Notifications have been started.');
                    })
                    .catch(error => { console.error(error); });
            }
    
    
            function handleCharacteristicValueChanged(event) {
                const value = event.target.value;
                let a = [];
    
                for (let i = 0; i < value.byteLength; i++) {
                   a.push(value.getUint8(i).toString(16));
                }
                console.log('> ' + a);
        }
        </script>
    

    1 Attachment

  • I'm not sure what to suggest I'm afraid. You could hook onto gattserverdisconnected and see if reason gives you anything useful: http://www.espruino.com/Reference#l_Blue­toothDevice_gattserverdisconnected

    However their choice of UUIDs is a bit concerning. If you're developing a device there's a specific part of the UUID you should change (https://www.espruino.com/About+Bluetooth­+LE#128-bit-uuids) so as not to end up registering multiple 128 bit UUIDs - and they're not doing that so instead of 1 UUID the GPS is using 4.

    That shouldn't be an issue as we have 10 slots in Espruino, but it also doesn't fill you full of confidence that the folks that made it really knew what they were doing.

    When you connect with nRF Connect, do they have a bunch of other services/characteristics? I guess if they did have 10 different 128 bit UUIDs that would be enough to overwhelm Bangle.js and it would disconnect.

    ... out of interest, why are you wanting to connect an external GPS receiver when Bangle.js has its own?

  • Hi Gordon.

    The 'gattserverdisconnected' reason is : 62 (#define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED 0x3E)

    I need to debug : CAN Bus data, One-Wire, Input/Output from GPS device. Not only GPS data.

  • I made an apache-cordova app, and I got this object in connect method:

    {
       "name":"GS7X 354762118079554",
       "id":"80:EA:CA:00:3E:4E",
       "advertising":{
          
       },
       "rssi":-61,
       "services":[
          "1800",
          "1801",
          "0783b03e-8535-b5a0-7140-a304d2495cb7"
       ],
       "characteristics":[
          {
             "service":"1800",
             "characteristic":"2a00",
             "properties":[
                "Read"
             ]
          },
          {
             "service":"1800",
             "characteristic":"2a01",
             "properties":[
                "Read"
             ]
          },
          {
             "service":"1801",
             "characteristic":"2a05",
             "properties":[
                "Read",
                "Indicate"
             ],
             "descriptors":[
                {
                   "uuid":"2902"
                }
             ]
          },
          {
             "service":"0783b03e-8535-b5a0-7140-a304d­2495cb7",
             "characteristic":"0783b03e-8535-b5a0-714­0-a304d2495cb8",
             "properties":[
                "Notify"
             ],
             "descriptors":[
                {
                   "uuid":"2902"
                },
                {
                   "uuid":"2901"
                }
             ]
          },
          {
             "service":"0783b03e-8535-b5a0-7140-a304d­2495cb7",
             "characteristic":"0783b03e-8535-b5a0-714­0-a304d2495cba",
             "properties":[
                "WriteWithoutResponse"
             ],
             "descriptors":[
                {
                   "uuid":"2902"
                },
                {
                   "uuid":"2901"
                }
             ]
          },
          {
             "service":"0783b03e-8535-b5a0-7140-a304d­2495cb7",
             "characteristic":"0783b03e-8535-b5a0-714­0-a304d2495cb9",
             "properties":[
                "Read",
                "WriteWithoutResponse",
                "Notify"
             ],
             "descriptors":[
                {
                   "uuid":"2902"
                },
                {
                   "uuid":"2901"
                }
             ]
          }
       ]
    }
    

    Notifications work. And this is the code in apache-cordova:

    ID="80:EA:CA:00:3E:4E";
    document.addEventListener('deviceready',­ onDeviceReady, false);
    
    function onDeviceReady() {
        // Cordova is now initialized. Have fun!
    
        setTimeout(__ =>{
            ble.scan([], 5, device=> console.log(JSON.stringify(device)), failure=> console.log('FAILURE: ',failure));
        },2500);
    
        setTimeout(__ =>{
            ble.connect(ID, device=> console.log(JSON.stringify(device)), failure=> console.log('FAILURE: ',failure));
        },5000)
        document.getElementById('deviceready').c­lassList.add('ready');
    
        setTimeout(__ =>{
            var onData = function(buffer) {
                // Decode the ArrayBuffer into a typed Array based on the data you expect
                var data = new Uint8Array(buffer);
                console.log("Galileo data: " , JSON.stringify(data));
            }
            
            ble.startNotification(ID, "0783b03e-8535-b5a0-7140-a304d2495cb7", "0783b03e-8535-b5a0-7140-a304d2495cb8", onData, failure=> console.log('FAILURE: ',failure));
        },10000);
    }
    

    Do you have an idea?

  • I'm afraid I don't have many ideas... You could try waiting (with setTimeout) for a second after you establish the connection before you try and use getPrimaryService and see if that helps?

    But if you google BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED there are a bunch of posts. One interesting one says this:

    OK, I see what is happening.

    My Peripheral device is "bonding" with only one device. I have to go thru a reset sequence on it to allow it to bond to a different Central.

    Do you think that could be a possibility? That the GPS device is actually only allowing itself to be connected to just one device (like your phone)?

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

BLE with BangleJS and GPS Device

Posted by Avatar for Ricardo @Ricardo

Actions