Android Question BLE2 activate DataAvailable routine

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi all,
after connecting to a chip via ble2, I'm trying to talk to him. In the first instance I printed all the characteristics of the service.
Then I wrote a command: "E".
Now I am trying to get an answer, but I have some difficulties.
To activate the DataAvailable routine I need to set:
B4X:
    manager.SetNotify(ServiceId, C301_risposta, True)
It's true?
previously I have defined the characterisctic:
B4X:
    C301_risposta= UUID("C301")
UUID is the Erel routine that construct UUID.
The characteristic exists.

But SetNotify has an error:
B4X:
starter_manager_connected (java line: 470)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
    at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:322)
    at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:311)
    at com.mamavi.slimup.starter._manager_connected(starter.java:470)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:7000)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

So far I have always connected with the features of BleCentral (by Erel - ReadChar and WriteChar) and now I need support to use other characteristics.
Now I have near 25 characteristics on the chip and I need to know how manage read, write and DataAvailable.
Does anyone have any examples?
Does anyone know why I get this error?
I have B4A 9.01 and Ble2 1,38
Thanks all
Marcom
 

emexes

Expert
Licensed User
yes the chip technician has configurated the chip in this way


A better model than a football ground scoreboard, would be an industrial control panel, like in a electricity power plant or the controls of a train locomotive: a panel of inputs (switches, buttons, control knobs 0..100%) and outputs (gauges, numeric readings, indicator lights).

BLE GATT is not well-suited to protocol-oriented communication. There is a HM10/HC08 module that emulates a serial link, but it is slow and probably a bit unreliable too. I haven't actually got my hands on a module to try it, but I do know that BLE uses public radio bandwidth that it has to "share" with other stuff like WiFi and AV extenders, and consequently sometimes packets get clobbered and timeouts get exceeded.

When my life is quieter (!) I had in mind to write a generic BLE application that would construct a reasonable-looking panel from the public information emitted by the device of its services and characteristics. For example, the BLE pressure sensor I have here, actually describes the pressure characteristic as being a 16-bit signed integer, scaled in 0.1 PSI. It gives similar information about the battery state and ambient temperature characteristics.

Nrf Connect lets you explore the same information, but it is a more programmer-like interface, rather than presenting it as a control panel.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…