Android Question Serial Library shows duplicates Mac Address

Scantech

Well-Known Member
Licensed User
I have notice searching for Bluetooth will display numerous duplicates anywhere from 2 to 5 same name and ID.

Is this a bug with Serial library?

B4X:
Sub Admin_DeviceFound (Name As String, MacAddress As String)
    Log(Name & ":" & MacAddress)
    Dim nm As NameAndMac
    nm.Initialize
    nm.Name = Name
    nm.Mac = MacAddress
    If foundDevices.IsInitialized = False Then foundDevices.Initialize
    foundDevices.Add(nm)
    ProgressDialogShow2("Searching for devices (~ device found)...".Replace("~", foundDevices.Size), False)
End Sub
 

walterf25

Expert
Licensed User
I have notice searching for Bluetooth will display numerous duplicates anywhere from 2 to 5 same name and ID.

Is this a bug with Serial library?

B4X:
Sub Admin_DeviceFound (Name As String, MacAddress As String)
    Log(Name & ":" & MacAddress)
    Dim nm As NameAndMac
    nm.Initialize
    nm.Name = Name
    nm.Mac = MacAddress
    If foundDevices.IsInitialized = False Then foundDevices.Initialize
    foundDevices.Add(nm)
    ProgressDialogShow2("Searching for devices (~ device found)...".Replace("~", foundDevices.Size), False)
End Sub
I'm not sure if is a bug or not, but that shouldn't affect your app in any way, you can just simply check if the MacAddress is already added to your list and skip it if it is already in the list.

Regards,
Walter
 

Scantech

Well-Known Member
Licensed User
I'm not sure if is a bug or not, but that shouldn't affect your app in any way, you can just simply check if the MacAddress is already added to your list and skip it if it is already in the list.

Regards,
Walter

That is a good idea.

But I wonder what will happen if two identical Bluetooth device with same name and Id are being discovered and when connecting will it communicate with both device?
 

walterf25

Expert
Licensed User
That is a good idea.

But I wonder what will happen if two identical Bluetooth device with same name and Id are being discovered and when connecting will it communicate with both device?
I really doubt that in areal application there will be two devices with the same ID, each device ID is unique.

Walter
 

Scantech

Well-Known Member
Licensed User
I really doubt that in areal application there will be two devices with the same ID, each device ID is unique.

Walter
Elm 327 OBD2 Interperter Device is quite popular at eBay with identical ID and Name. Imagine a mechanic shop with those device in hand.
 

walterf25

Expert
Licensed User
Elm 327 OBD2 Interperter Device is quite popular at eBay with identical ID and Name. Imagine a mechanic shop with those device in hand.
Yes, i have several of those modules, but the MacAddresses are unique to each device.

Walter
 

Scantech

Well-Known Member
Licensed User
Last edited:

Scantech

Well-Known Member
Licensed User
Update: Tried it on Samsung S6 it show numerous duplicates only with available Mac Name.
Tried it on Alcatel and it shows numerous duplicates with or without available Mac Name.

Did you guys test the Serial Library for Discoveries?
 

Scantech

Well-Known Member
Licensed User
Of course.

I'm not sure that I understand. What is the output of this line:
B4X:
 Log(Name & ":" & MacAddress)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
LVS-Lush41:CC:CC:99:39:74:25
LVS-Lush41:CC:CC:99:39:74:25
LVS-Lush41:CC:CC:99:39:74:25
LVS-Domi41:F3:36:A1:5B:A0:C9
LVS-Lush41:CC:CC:99:39:74:25
LVS-Domi41:F3:36:A1:5B:A0:C9
LVS-Lush41:CC:CC:99:39:74:25
:74:6A:81:83:23:5B
:7C:A5:A1:11:56:70
XBR-55X810C:48:E2:44:09:2E:62
LVS-Lush41:CC:CC:99:39:74:25
:49:96:FE:7F:55:82
:74:6A:81:83:23:5B
LVS-Domi41:F3:36:A1:5B:A0:C9
LVS-Lush41:CC:CC:99:39:74:25
LVS-Lush41:CC:CC:99:39:74:25
:49:96:FE:7F:55:82
LVS-Lush41:CC:CC:99:39:74:25
LVS-Domi41:F3:36:A1:5B:A0:C9
LVS-Lush41:CC:CC:99:39:74:25
:74:6A:81:83:23:5B
:74:6A:81:83:23:5B
LVS-Lush41:CC:CC:99:39:74:25
LVS-Domi41:F3:36:A1:5B:A0:C9
LVS-Domi41:F3:36:A1:5B:A0:C9
LVS-Lush41:CC:CC:99:39:74:25
:49:96:FE:7F:55:82
LVS-Lush41:CC:CC:99:39:74:25
Tested with Acaltel A574BL
Android 7.1.1
 

techknight

Well-Known Member
Licensed User
This behavior is normal. I had to write filters to filter all that "noise" out.

Here is how I fixed it: (I am sure there are easier ways with Maps and Lists, but when I wrote this I wasnt familiar at all with those)

B4X:
Sub Admin_DeviceFound (Name As String, MacAddress As String)
    Dim I As Int
    MACDetected = False
    Log(Name & ":" & MacAddress)
    Dim nm As NameAndMac
    nm.Name = Name
    nm.Mac = MacAddress
    For I = 0 To 254 Step 1
        If MACArray(I) = MacAddress Then
            MACDetected = True
        End If
    Next
    If MACDetected = False Then
        MACArray(MacPosition) = MacAddress
        foundDevices.Add(nm)
        ProgressDialogShow2("Searching for devices (~ found)...".Replace("~", foundDevices.Size), False)
        MacPosition = MacPosition + 1
    End If
End Sub
The above code works, again it would be easier with a Map. But either way, it gets around the problem.
 
Last edited:

DonManfred

Expert
Licensed User
again it would be easier with a Map
B4X:
ivate Sub Admin_DeviceFound (Name As String, MacAddress As String)
    Log(Name & ":" & MacAddress)
    Dim nm As NameAndMac
    nm.Name = Name
    nm.Mac = MacAddress
    foundDevices.Put(MacAddress,nm) ' where foundDevices is a Map in the Adminclass and the map should be initialized in the Initialize sub ob the Class.
End Sub
 

Scantech

Well-Known Member
Licensed User
This means that the OS sent duplicate broadcasts. Should be trivial to remove duplicates. You can use a Map or B4XSet or List.IndexOf to remove duplicates.
Ok, thanks for the answer. One annoying thing about this issue is the DiscoveryFinished event can get triggered twice and i seen it happened 2 in every 30 attempts. My inputlist gets called twice because of this.
 
Top