don / cordova-plugin-ble-peripheral

Apache Cordova plugin for implementing BLE (Bluetooth Low Energy) peripherals.
Other
31 stars 31 forks source link

Getting "Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattServer.addService(android.bluetooth.BluetoothGattService)' on a null object reference" on Android #9

Open huseyincandan opened 6 years ago

huseyincandan commented 6 years ago

Hi,

I'm trying the sample code and blePeripheral.startAdvertising(SERVICE_UUID, 'UART') line gives error on Android. On iOS everything is working without any error.

I've installed "Adafruit Bluefruit LE Connect" app. When I tap Peripheral Mode getting "Error starting advertising" error.

I've tried on both a tablet and a Samsung mobile phone and got same result.

Can you help me about the point I am missing?

Thanks,

curious-monggo commented 6 years ago

Hi Sir huserincadan. I too am trying to use cordova-plugin-ble-peripheral and was not able to create it on ionic. It would be of great help if you hit me up if you are able to create and start advertising :) -A fellow and new ble enthusiast

curious-monggo commented 6 years ago

Also, for some reason, the blePeripheral.onBluetoothStateChange(app.onBluetoothStateChange); gets triggered even if there was no change in bluetooth state. I wonder if you came across that behavior too?

huseyincandan commented 6 years ago

Hi laaaaanceeee, I am also using ionic. You can access blePeripheral object by following code. I hope it helps. If you need I may share whole code.

let blePeripheral = (window).blePeripheral;

I could not try onBluetoothStateChange because I could not start advertising.

Actullay, using mobile phone as ble peripheral is very important part of my project. I'll control my web app (nodejs) by mobile app. Everything was fine on iOS and I'am developing on mac and iPhone, so I've almost completed the code.

I hope Don will help !

curious-monggo commented 6 years ago

For the meantime, you can use this : ) https://github.com/somq/ionic-plugin-bluetoothle This is an ionic native plugin(wrapper for a cordova plugin) that supports central and peripheral.

Happy coding! (Don seems to be busy with other things and may not reply to you for the time being)

adrian-fratila commented 4 years ago

Hi guys,

I am a newbie in Ionic, and I try to get working a BLE peripheral in Ionic 3. For some reason the cordova bluetoothle plugin returns as not found when I try to build, although it appears as installed correctly when I try to reinstall it. Nevertheless somehow I got the @ionic-native/bluetooth-le to build the code.

I followed the steps of initialise, initializePeripheral, addService, startAdvertising and they return like everything as expected (ending up with AdvertisingStarted), but for some reason the device doesn't appear when I scan from another smartphone.

Also I could not figure out how to assign the callback function which is called when the device gets connected to, or receives something from the other side / the client.

I would highly appreciate if you could point me to an example code which implements the peripheral functionality in Ionic 3, as I have been struggling already a couple of days on this issue..

Thank you, Adrian

caseylai commented 4 years ago

same problem. Finally I found out that the phone hardware does not support the peripheral mode.