douglasjunior / react-native-easybluetooth-classic

⚛ A Library for easy implementation of Serial Bluetooth Classic on React Native (Android Only).
https://www.npmjs.com/package/easy-bluetooth-classic
MIT License
43 stars 7 forks source link

Can't found any device #18

Closed vimcaw closed 6 years ago

vimcaw commented 6 years ago

My phone has connected with HC-05 Bluetooth module and can receive data from other Bluetooth Terminal app.

import EasyBluetooth from 'easy-bluetooth-classic';

let config = {
  "uuid": "00001101-0000-1000-8000-00805F9B34FB",
  "deviceName": "SmartCleaner",
  "bufferSize": 1024,
  "characterDelimiter": "\n"
}

EasyBluetooth.init(config)
  .then(function (config) {
    console.log("config done!");
  })
  .catch(function (ex) {
    console.warn(ex);
  });

  EasyBluetooth.startScan()
      .then(function (devices) {
        console.log("all devices found:");
        console.log(devices);
      })
      .catch(function (ex) {
        console.warn(ex);
      });
05-17 10:35:27.335 27467 29713 I ReactNativeJS: config done!
05-17 10:35:42.924 27467 29713 I ReactNativeJS: all devices found:
05-17 10:35:42.926 27467 29713 I ReactNativeJS: []

But log cann't display any devices, does it not support my HC-05 Bluetooth module?

vimcaw commented 6 years ago

I can't understand the effect of config, does it only scan the device which met the config?

douglasjunior commented 6 years ago

But log cann't display any devices, does it not support my HC-05 Bluetooth module?

The library does not restrict the type of searched devices. The restriction might be on your smartphone hardware.

I can't understand the effect of config, does it only scan the device which met the config?

No, in Bluetooth Classic all discovered devices are returned.

See: https://github.com/douglasjunior/AndroidBluetoothLibrary/blob/db1df73c5c833a6c995103618dd68959e910fda7/BluetoothClassicLibrary/src/main/java/com/github/douglasjunior/bluetoothclassiclibrary/BluetoothClassicService.java#L421-L443

TiagoDvl commented 6 years ago

This maybe a little late but i found out that you have to grant your app location permition in order to retrieve all devices.