@SpotOnCreative wrote:
Hi. I’m using the following ionic wrapper for the Cordova BLE plugin
https://www.npmjs.com/package/ionic-plugin-bluetoothleThis is the third plugin i’ve tried and I can never connect to any device, it always gives back the error message “Connection Failed”.
Now, I’m targetting 6.0.1 (APK level 24), which means I need to use the “new” permission settings when wanting to pair / connect to Bluetooth devices. I know this, and thus I have told the app to ask for location permission. The app always asks for CORSE_LOCATION, BLUETOOTH and BLUETHOOTH_ADMIN.
When the app starts it asks the user if I can access location (so we have CORSE_LOCATION), and as the other Bluetooth permissions aren’t classed as dangerous, they’re granted.
This is where I have no idea what to do. When I use Bluetooth in the settings within Android its self, when pairing to a new phone / device it prompts with a Pin Request which I have to click ok too. This never happens with any of the plugins I’ve tried (BLE Central and BLE Serial).
I’m absolutely stumped here. Here’s my code
if(!this.isScanning) { // State we have initiated a scan - don't want to call a scan ontop of calling a scan! this.isScanning = true; this.canRefresh = false; this.bluetoothle.startScan({services:[]}).subscribe( device => { if(device.status == "scanResult") { this.addDeviceToAvailableList(device) } }, error => { console.log("Uh oh: " + JSON.stringify(error)) }); this.startTimer(); // after the alloted time, stop the Bluetooth Scan } else{ console.log("Already scanning"); }
This somewhat works (I can only ever gain access to the MAC Address, never the actual friendly device name, which is bloody annoying.
When I click a device to connect to, this code gets run
let loading = this.loadingCtrl.create({content: "Connecting..."}); loading.present(); this.bluetoothle.connect({address: deviceID}).subscribe( device => { loading.dismiss(); if(device.status == "connected") { console.log("Connecting: " + JSON.stringify(device)); this.addDeviceToPairedList(this.findDeviceByID(deviceID)); } else if (device.status == "disconnected") { console.log("disconnected"); } }, error => { console.log("Connecting Error: " + JSON.stringify(error)); loading.dismiss(); }
This code block always reports “Disconnected”. Why on Earth is this? I think it is to do with a pair request prompt (Surely it has to be this?). But like I said, that prompt never appears.
I’ve been banging my head for two weeks now.
Posts: 1
Participants: 1