noble / bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
MIT License
2.12k stars 447 forks source link

Cannot see custom Services or Characteristics on scan (Android) #405

Closed alexdeweert closed 6 years ago

alexdeweert commented 6 years ago

Hello,

I've been having a very hard time getting my Android phone to recognize custom UUIDs and their associated services and characteristics (using either nRF Connect and even just a custom built Android app using Android.Bluetooth library for Xamarin).

No matter what I do, I cannot get the nRF app to see ANYTHING other than the following: 20180812_163917

The iOS app LightBlue recognizes the custom UUIDs and characteristic values no problem! Same with the iOS cross platform version of my own custom Xamarin app.

So this doesn't seem to be an issue with either Xamarin, iOS, or nRF Connect...it seems to be an issue with the way that the Android hardware is scanning for the beacon.

blueoothd IS disabled...hci0 is up and running.

Results of hcidump -i hci0 following "connect" from nRF Connect app on Android

HCI sniffer - Bluetooth packet analyzer ver 5.43 device: hci0 snap_len: 1500 filter: 0xffffffff HCI Event: Command Status (0x0f) plen 4 LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1

Code running on Raspberry pi

const bleno = require("bleno");
const UUID = '0001000089BD43C8923140F6E305F96D';
const HGHT = '0001000089BD43C8923140F6E305F96D';

var heightChar = new bleno.Characteristic({
        uuid: HGHT,
        properties: ['read'],
        value: new Buffer('77', 'ascii')
});

var primaryService = new bleno.PrimaryService ({
        uuid: UUID,
        characteristics: [heightChar]
});

bleno.on("advertisingStart", err => {

        console.log("advertisingStart");
        if( err ) {
                console.log(err);
                return;
        }
        bleno.setServices([primaryService], err => {
                if(err) console.log(err);
                else console.log("Services set to PrimaryService with one characteristic");
        });
});

bleno.on("stateChange", state => {
        if( state == 'poweredOn' ) {
                bleno.startAdvertising('SmartDesk', [primaryService.uuid], err => {
                        if( err ) { console.log(err); }
                        else {
                                console.log('Broadcasting iBeacon. UUID: ' + UUID);
                        }
                });
        }
        else {
                console.log('Stopped advertising');
                bleno.stopAdvertising();
        }
});

Any help would be greatly appreciated. Thanks.

alexdeweert commented 6 years ago

In nRF Connect the solution was to "Refresh" the device, and then I could see the characteristics. On the C# Xamarin side the solution was to use the hidden Java reflection method within a function

private void RefreshGattCache() {
    Method m = gatt.Class.GetMethod("refresh",null);
    m.Invoke(gatt,null)
}