I am experimenting with BT iBeacons, I have a few to test with. But I`m getting a problem that the code isn`t recognizing the "-1" in the AdvertisingData, here is my code:
Here is the log, that I`m getting; there is definitely "-1" in the map; the code detects other keys if i change the number. My code filters, for the beacons called "Holy-IOT", but I`m a little stumped with why I can`t access the -1 map...
James
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
Log("Device: " & Name & " | Advertising: " & AdvertisingData)
If Name = "Holy-IOT" Then
Log("Found: " & Name & " | Advertising: " & AdvertisingData)
Dim bc As ByteConverter
Dim key As Int = -1 'type is important. Must be Int.
If AdvertisingData.ContainsKey(key) = True Then
Dim b() As Byte = AdvertisingData.Get(key)
If b.Length > 4 And b(0) = 0x4c And b(1) = 0 And b(2) = 0x02 And b(3) = 0x15 Then
Dim beacon2 As Beacon
beacon2.Initialize
Dim raf As RandomAccessFile
raf.Initialize3(b, False)
Dim hex As String = bc.HexFromBytes(b)
beacon2.uuid = hex.SubString2(8, 40) 'bytes 4 - 19
beacon2.uniqueid = hex.SubString2(8, 48) 'this also includes the major and minor parts
beacon2.major = raf.ReadShort(20)
beacon2.minor = raf.ReadShort(22)
Dim tx As Byte = raf.ReadSignedByte(24)
beacon2.distance = CalculateDistance(tx, RSSI)
beacon2.time = DateTime.Now
End If
End If
' Dim tmp As String = Name & " | ID = " & beacon2.uniqueid '& " | Distance = " & beacon2.distance
' clv.AddTextItem(tmp,0)
End If
End Sub
Here is the log, that I`m getting; there is definitely "-1" in the map; the code detects other keys if i change the number. My code filters, for the beacons called "Holy-IOT", but I`m a little stumped with why I can`t access the -1 map...
B4X:
Device: HUAWEI Band 6-849 | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 22=[[email protected], 10=[[email protected], 9=[[email protected], 0=[[email protected]}
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Device: | Advertising: (MyMap) {3=[[email protected], 22=[[email protected], -1=[[email protected], 0=[[email protected]}
Device: | Advertising: (MyMap) {-1=[[email protected], 0=[[email protected]}
[B]Device: Holy-IOT | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 9=[[email protected], 22=[[email protected], 0=[[email protected]}
Found: Holy-IOT | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 9=[[email protected], 22=[[email protected], 0=[[email protected]}[/B]
Device: [TV] Samsung AU7000 75 TV | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 8=[[email protected], 0=[[email protected]}
Device: | Advertising: (MyMap) {-1=[[email protected], 0=[[email protected]}
Device: | Advertising: (MyMap) {-1=[[email protected], 0=[[email protected]}
Device: | Advertising: (MyMap) {1=[[email protected], 3=[[email protected], 22=[[email protected], 0=[[email protected]}
[B]Device: Holy-IOT | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 9=[[email protected], 22=[[email protected], 0=[[email protected]}
Found: Holy-IOT | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 9=[[email protected], 22=[[email protected], 0=[[email protected]}[/B]
Device: IGM1-C2A5P1_fa5f69 | Advertising: (MyMap) {1=[[email protected], 10=[[email protected], 2=[[email protected], -1=[[email protected], 9=[[email protected], 18=[[email protected], 0=[[email protected]}
Device: LG HS8(CB:6F) | Advertising: (MyMap) {1=[[email protected]cfecd9e, -1=[[email protected], 9=[[email protected], 0=[[email protected]}
Device: | Advertising: (MyMap) {1=[[email protected], 3=[[email protected], 22=[[email protected], -1=[[email protected], 0=[[email protected]}
Device: HUAWEI Band 6-849 | Advertising: (MyMap) {1=[[email protected], -1=[[email protected], 22=[[email protected], 10=[[email protected], 9=[[email protected], 0=[[email protected]}
James