so i finally got the function to run however it doesnt display any connected devices. currently i have a hc-06 Bluetooth module connected. but it does not display any data of any device. from the Docs https://github.com/don/BluetoothSerial#list apparently i get four bits of data. id, class, address and name. i upload it to ionic view and test my app. it comes back with the successful list function however nothing is displayed.
import { Component } from '@angular/core';
import { BluetoothSerial } from 'ionic-native';
import { NavController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { BLE } from '@ionic-native/ble';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
infomation: any = [];
constructor(public alertCtrl: AlertController, public navCtrl: NavController){}
ionViewDidLoad(){
this.infomation = {id: "hey it works"};
BluetoothSerial.isEnabled().then(() => {
console.log("bluetooth is enabled all G");
}, () => {
console.log("bluetooth is not enabled trying to enable it");
BluetoothSerial.enable().then(() => {
console.log("bluetooth got enabled hurray");
}, () => {
console.log("user did not enabled");
})
});
}
search(){
BluetoothSerial.list().then((data) => {
JSON.stringify( data );
console.log("hurray" + data);
this.showDevices("Found Devices", data.id, data.class, data.address, data.name);
},
(error) => {
console.log("could not find paired devices because: " + error);
this.showError(error);
});
}
discover(){
BluetoothSerial.discoverUnpaired().then ((device) => {
BluetoothSerial.setDeviceDiscoveredListener().subscribe( (device) => {
JSON.stringify( device );
this.infomation = {id: device.id};
this.showDevices("Unparied devices", device.id,device.class,device.address,device.name);
console.log(device.id);
});
},
(error) => {
this.showError(error);
console.log("could not find unparied devices " + error);
});
}
showDevices(title, id, type, address, name) {
let alert = this.alertCtrl.create({
title: title,
message: id + type + address + name,
buttons: ['OK']
});
alert.present();
}
showError(info) {
let alert = this.alertCtrl.create({
title: "Error",
message: info,
buttons: ['OK']
});
alert.present();
}
}
any help would be great thank you.