Hi there, im a newbie to Ionic2 and Angular2. Im currently writing a simple app that receive data from a BLE device and use socket.io to push the data to a local server.
When i run the app on my device, this error pop up on my developer tools.
i realize its an error from the NavController.
I was able to load the rootpage which is my homepage. However, when i wan to navigate to the devicepage with a click button, this error pop up on my console log and i cannot navigate to the device page on click.
Here is my home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { DevicePage } from '../device/device';
import { BLE } from '@ionic-native/ble';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
devices: any[];
isScanning:boolean;
constructor(
public navCtrl: NavController,
public ble: BLE)
{
this.devices = [];
this.isScanning = false;
}
startScanning() {
console.log('Scanning Started');
this.devices = [];
this.isScanning = true;
this.ble.startScan([]).subscribe(device => {
console.log("Found device: " + JSON.stringify(device));
this.devices.push(device);
},
err => {
console.log("Error occurred during BLE scan: " + JSON.stringify(err));
},
);
setTimeout(() => {
this.ble.stopScan().then(() => {
console.log('Scanning has stopped');
console.log(JSON.stringify(this.devices));
this.isScanning = false;
});
}, 3000);
}
connectToDevice(device) {
this.navCtrl.push(DevicePage, {
device: device
});
}
}
my device.ts
import { Component, Inject } from '@angular/core';
import { NavParams } from 'ionic-angular';
import { BLE } from '@ionic-native/ble';
import * as io from 'socket.io-client';
@Component({
selector: 'page-device',
templateUrl: 'device.html'
})
export class DevicePage {
connecting:boolean;
device:any;
characteristic:any;
beatsPerMinute:any;
characteristics:any[];
data:any[];
socketHost: string;
constructor(
public navParams: NavParams,
public ble: BLE,
@Inject(io)public socket: SocketIOClient.Socket)
{
this.connecting = true;
this.device = this.navParams.get('device');
this.characteristic = this.navParams.get('characteristic');
this.beatsPerMinute = this.navParams.get('beatsPerMinute');
this.connect(this.device.id);
this.socketHost = "http://localhost:3000";
}
connect(deviceID) {
this.characteristics = [];
this.ble.connect(deviceID).subscribe(peripheralData => {
this.characteristics = peripheralData.characteristics;
console.log('Connected' + JSON.stringify(this.characteristics));
this.connecting = false;
this.ble.startNotification(deviceID, "180D", "2A37").subscribe(buffer => {
var data = new Uint8Array(buffer);
console.log(JSON.stringify(data));
this.beatsPerMinute.innerHTML = data[1];
this.socket = io(this.socketHost);
this.socket.on('connect', () => {
console.log('socket ok');
this.socket.emit("BLE", this.beatsPerMinute);
});
});
},
err => {
console.log("Error occurred during BLE connect: " + JSON.stringify(err));
});
}
diconnect(deviceID){
this.ble.disconnect(deviceID).then(() => {
console.log('Disconnected' + JSON.stringify(deviceID));
},
err => {
console.log("Error occurred during BLE scan: " + JSON.stringify(err));
});
}
}
Been struggle this error…hope anyone can help to solve this issue…