I am currently working on a phone app, using nativescript and bluetooth(both of which I am very new to) and I am having an issue with discovering nearby devices being discovered. On another phone app many devices are discovered very fast, however, on my app only discovers a subset of those that are discovered by other app and they discovered slower as well. So my primary question is what could cause my app only discovers some of the devices around me and not others? Also, secondarily why is it slow to discover them? Or perhaps any easy ways to diagnose the problem?
Also here's my code...
import { Component, OnInit } from "@angular/core";
import { ListViewEventData, RadListView } from "nativescript-ui-listview";
import { Device } from "../shared/device.model";
var bluetooth = require('nativescript-bluetooth');
//var bluetooth = require("nativescript-bluetooth");
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
deviceList: Array<Device> = [];
isLoading = false;
listLoaded = true;
constructor() {
}
onTapCell(name): void{
alert(name);
return;
}
ngOnInit(): void{
console.log(bluetooth.isBluetoothEnabled().then(
function(enabled){
console.log("enabled " + enabled);
}
));
var t = this.deviceList;
setTimeout(
function(){
bluetooth.startScanning({
serviceUUIDs: [],
seconds : 120,
onDiscovered: function(peripheral){
console.log(peripheral.UUID);
console.log(peripheral.RSSI);
peripheral.RSSI += 128;
t.push(peripheral);
},
onScanFailed: function(){
}
});
},
125*1000
)
}
}
My system: Android 8, motoZ2
Thanks, Issiah
@Katherine Yes and no, it turns out that it uses low energy bluetooth (bluetooth LE), which won't be backward compatible with older devices that use a higher powered bluetooth. Also, if I remember correctly(don't quote me on this) the library doesn't deal with the initial signals that it receives from the devices I think the creator had this as a TODO inside the git repo, which would explain why it was slow as well. Here's a link to the repo github.com/eddyverbruggen/nativescript-bluetooth. Note: the native android library should have backward compatible bluetooth.