Android Question Serial Library shows duplicates Mac Address

Discussion in 'Android Questions' started by Scantech, Feb 11, 2019.

  1. Scantech

    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?

    Code:
    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
     
  2. walterf25

    walterf25 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
     
  3. Scantech

    Scantech Well-Known Member 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?
     
  4. walterf25

    walterf25 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
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Make sure not to initialize BluetoothAdmin multiple times. It will cause the events to be raised multiple times.
     
  6. Scantech

    Scantech Well-Known Member 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.
     
  7. walterf25

    walterf25 Well-Known Member Licensed User

    Yes, i have several of those modules, but the MacAddresses are unique to each device.

    Walter
     
  8. Scantech

    Scantech Well-Known Member Licensed User

    Last edited: Feb 13, 2019
  9. Scantech

    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?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Of course.

    I'm not sure that I understand. What is the output of this line:
    Code:
    Log(Name & ":" & MacAddress)
     
  11. Scantech

    Scantech Well-Known Member Licensed User

    Tested with Acaltel A574BL
    Android 7.1.1
     
  12. DonManfred

    DonManfred Expert Licensed User

    If you now upload a small project which shows the issue then we maybe can help.

    Are you sure this is not the case?
     
  13. Scantech

    Scantech Well-Known Member Licensed User

  14. Erel

    Erel Administrator Staff 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.
     
    Scantech likes this.
  15. techknight

    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)

    Code:
    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: Feb 14, 2019
  16. DonManfred

    DonManfred Expert Licensed User

    Code:
    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 likes this.
  17. Scantech

    Scantech Well-Known Member Licensed User

    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.
     
  18. techknight

    techknight Well-Known Member Licensed User

    Yeap, thats normal too!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice