Android Question Bluetooth LE Manager_DeviceFound - error

wstein25

Member
Licensed User
I have a Bluetooth LE device that advertises every 3 seconds. The following is the beginning of the sub that handles it when found:

Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
If Name = "Etesian" Then

Everything works fine - for a time, an then seemingly randomly the app crashes. The log states:



Found: Etesian, F6:01:67:24:72:09, RSSI = -72, (MyMap) {1=[B@1b5cd027, 25=[B@131ab2d4, 9=[B@28d2ec7d, -1=[B@b8af772, 0=[B@15bc47c3}
4135
81
10
Found: Etesian, F6:01:67:24:72:09, RSSI = -65, (MyMap) {1=[B@22fe02ca, 25=[B@3d3cec3b, 9=[B@138cbf58, -1=[B@b4a78b1, 0=[B@9618196}
4135
81
8
Found: Etesian, F6:01:67:24:72:09, RSSI = -63, (MyMap) {1=[B@2a5ceeed, 25=[B@12ac2122, 9=[B@27aea7b3, -1=[B@3e82170, 0=[B@30a68ce9}
4135
81
8
Found: Etesian, F6:01:67:24:72:09, RSSI = -61, (MyMap) {1=[B@30daae88, 25=[B@3379f021, 9=[B@2c9b7c46, -1=[B@2356e07, 0=[B@18b02b34}
4135
81
8
Found: null, 68:F5:37:9E:51:DA, RSSI = -59, (MyMap) {1=[B@13b0e3a3, -1=[B@3abec6a0, 0=[B@237f8259}
Error occurred on line: 76 (Starter)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at b4a.BreezeView.starter._manager_devicefound(starter.java:176)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5253)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:948)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
** Activity (main) Resume **



Line 76 is If Name = "Etesian" Then

It would seem that some other Bluetooth ad was detected and this caused the crash? But why?

Thanks

Bill
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

There is no name data in the second peripheral device so it returns Null. I will fix the library so it returns an empty string in that case. For now you should check it with:
B4X:
If Name <> Null AND Name = "Etesian"

Note that you can pass the service UUID to Scan or Scan2 and it will then only find relevant devices.

Last tip. Use this sub to build the UUID:
B4X:
Private Sub UUID(id As String) As String
#if B4A
   Return "0000" & id.ToLowerCase & "-0000-1000-8000-00805f9b34fb"
#else if B4I
   Return id.ToUpperCase
#End If
End Sub

You can then pass the 16 bits UUID.
 
Upvote 0
Top