I have used subscribeRawData to read the data from the connected device but whiling reading, it gives the buffer length 0 always .
Below is the sample code :-
connect() {
this.platform.ready().then(() => {
this.Bs.isEnabled().then(
() => {
console.log('BT is enabled !');
this.scanForBTDevices();
},
(error) => {
console.log('BT is not enabled On load . Enabling now .. !');
this.Bs.enable().then(
() => {
console.log('Bluetooth is enabled now');
this.scanForBTDevices();
},
(error) => {
console.log('Not able to enbable bluetooth !');
console.log(JSON.stringify(error));
}
)
}
);
});
}
scanForBTDevices() {
this.Bs.list().then(
(data) => {
console.log('Getting the list of devices paired with the mobile. Note you need to pair first the device you want to use , then it will be available in this list');
console.log(JSON.stringify(data));
this.deviceList = data;
this.Bs.connect('MAC-Address').subscribe(
(data) => {
console.log('Connected to device !');
console.log(JSON.stringify(data));
this.subscribeForData();
},
(error) => {
console.log('Error in connecting the device');
console.log(JSON.stringify(error));
}
)
},
(error) => {
console.log('Error in getting the list of paired Devices !');
console.log(JSON.stringify(error));
}
)
}
subscribeForData() {
this.Bs.subscribeRawData().subscribe(
(data) => {
console.log('Subscribing for the data successfull' + JSON.stringify(data));
this.Bs.read().then(
(data) => {
console.log('Getting the Data now');
console.log(JSON.stringify(data));
let buffer = new Uint8Array(data);
console.log("Converting it into Uint8Array")
console.log(console.log(buffer));
},
(error) => {
console.log('error in getting the data');
console.log(JSON.stringify(error));
}
)
},
(error) => {
console.log("Error in Subscribing for the data !");
}
)
}
disconnect() {
this.Bs.disconnect().then(
(data) => {
console.log('Successfully Disconnected from Device');
},
(error) => {
console.log('Error in disconnecting from device');
console.log(JSON.stringify(error));
}
);
}
Any help would be appreciated. Thanks