Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peripheral doesn't contain any services (tested on android) #242

Open
AvigarD611 opened this issue Mar 15, 2022 · 7 comments
Open

peripheral doesn't contain any services (tested on android) #242

AvigarD611 opened this issue Mar 15, 2022 · 7 comments

Comments

@AvigarD611
Copy link

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:

  1. Create new ns project - ns create testapp
  2. Enter folder - npm install
  3. tns plugin add @nativescript-community/ble
  4. 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?

@farfromrefug
Copy link
Member

@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

@ray007
Copy link

ray007 commented Nov 25, 2022

@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.

@farfromrefug
Copy link
Member

farfromrefug commented Nov 25, 2022

@ray007 what s your point? you cant discover services if you dont connect to a device

@liamcharmer
Copy link

Sorry for being silly, how are we able to retrieve the services whether its discover or when we connect to a device?

@farfromrefug
Copy link
Member

@liamcharmer as mention here either using autoDiscoverAll option on connection or after with the discoverServices method

@liamcharmer
Copy link

liamcharmer commented Mar 24, 2023

@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!!!

@farfromrefug
Copy link
Member

@liamcharmer thank you and sorry too. Dont have much time for docs but should definitely improve it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants