ble
ble copied to clipboard
peripheral doesn't contain any services (tested on android)
I have old project which is running on nativescript 7.0.0 + nodejs 12.. and npm 6.13.4 and everything there works perfect.
Now i tried to to upgrade the nodejs to lastest version (16..) and npm is 8.1/8.2 with this version of node. After I create fresh project there are no services in peripheral object.
Steps to reproduce:
- Create new ns project - ns create testapp
- Enter folder - npm install
- tns plugin add @nativescript-community/ble
- tns debug android
I'm using the same code from READ.me file, just removing the filters (to display all devices). After choosing mine it connects and i have console.log(peripheral) - there are no services inside. Just UUID, name and all others NO optional params.
My device is working well with my old app, which uses the same plugin. I think they've made something in core and "services" are not getting populated. Can you please check?
@AvigarD611 it is normal. Services are not discovered by default anymore as very expensive https://github.com/nativescript-community/ble/blob/master/src/bluetooth.common.ts#L362
@farfromrefug
@AvigarD611 it is normal. Services are not discovered by default anymore as very expensive https://github.com/nativescript-community/ble/blob/master/src/bluetooth.common.ts#L362
The autoDiscoverAll property you're linking to is part of the ConnectOptions, not the StartScanningOptions.
@ray007 what s your point? you cant discover services if you dont connect to a device
Sorry for being silly, how are we able to retrieve the services whether its discover or when we connect to a device?
@liamcharmer as mention here either using autoDiscoverAll option on connection or after with the discoverServices method
@liamcharmer as mention here either using autoDiscoverAll option on connection or after with the discoverServices method
Ahhh i see sorry! The hyperlink above wasn't working and i tried my best to look at the demo but im a failure
this.bluetooth.connect({
UUID: item.UUID,
autoDiscoverAll: true,
onConnected: function (peripheral) {
// the peripheral object now has a list of available services:
peripheral.services.forEach(function (service) {
console.log("service found: " + JSON.stringify(service));
});
},
onDisconnected: function (peripheral) {
console.log("Periperhal disconnected with UUID: " + peripheral.UUID);
},
});
Many thanks as always!!!
@liamcharmer thank you and sorry too. Dont have much time for docs but should definitely improve it !