@laaaaanceeee wrote:
A bit of an introduction here. I’ve tried the ionic native BLE, it worked and was able to scan my devices. So after that, I tried to create its counterpart, the peripheral.
I searched for it on ionic native docs and found out it wasn’t supported so I researched about using cordova plugins directly.
I found out in my plugin.xml
<clobbers target=“blePeripheral” />I used this and declared a variable blePeripheral on top of @Component then added Platform in order to set my ble code to run only when it is ready. To check how the functions are triggered, I put toasts inside the ble methods. (I might be wrong with the implementation, putting a method inside another one).
constructor(
public navCtrl: NavController,
public platform: Platform,
private toastCtrl: ToastController
) {
this.platform.ready().then(() => {
blePeripheral.onBluetoothStateChange(this.showToastState());
blePeripheral.onWriteRequest(this.showToastWrite());
});
}showToastState(){
let toast = this.toastCtrl.create({
message: ‘Something happened with the Bluetooth state.’,
duration: 5000,
position: ‘middle’
});toast.present();
}
showToastWrite(){
let toast = this.toastCtrl.create({
message: ‘something tried to write’,
duration: 5000,
position: ‘bottom’
});toast.present();
}
Then something weird happened, once the app finished loading, both methods were triggered even if there were no changes in the bluetooth state or write requests happening.
I tried other methods, like creating a service programmatically and by JSON. (I copied this from the flashlight example found inside the plugin folder)
SERVICE_UUID = ‘FF10’;
SWITCH_UUID = ‘FF11’;
DIMMER_UUID = ‘FF12’;
property = blePeripheral.properties;
permission = blePeripheral.permissions;
flashlightService = {
uuid: this.SERVICE_UUID,
characteristics: [
{
uuid: this.SWITCH_UUID,
properties: this.property.WRITE | this.property.READ,
permissions: this.permission.WRITEABLE | this.permission.READABLE,
descriptors: [
{
uuid: ‘2901’,
value: ‘Switch’
}
]
},
{
uuid: this.DIMMER_UUID,
properties: this.property.WRITE | this.property.READ,
permissions: this.permission.WRITEABLE | this.permission.READABLE,
descriptors: [
{
uuid: ‘2901’,
value: ‘Dimmer’
}
]
}
]
};By then, I knew that this plugin just didn’t work.I might have messed up something because I couldn’t see it in my scans, even though I programmed it to create and start advertising on click of a button.
Again, my question is. How do I use this plugin correctly and start advertising? If it is not possible to do so, then I might look in to using this
which has docs on peripherals
Peripheral Life Cycle
- initializePeripheral
- addService
- startAdvertising
- Listen for events on initializePeripheral callback
- Respond to events using respond or notify
- stopAdvertising
- removeService / removeAllServices
Thank you for taking your time in reading this question and have a good day!
*whispers
I hope they support this on ionic native
Posts: 1
Participants: 1