Filtering Alt beacon with manufacturer identifier and UUID begins with specific format - altbeacon

One of my use case requires to filter all the beacons which is generated by specific manufacturer and UUID starts with specific string.
The ALT beacon library (https://altbeacon.github.io/android-beacon-library/javadoc/reference/org/altbeacon/beacon/Region.html) provides Region class to filter the beacon based on the ID1, ID2, ID3.
I could not find any option to filter all the beacons at the library level which has specific manufacturer ID and the UUID begins with specific characters.
The API documentation with sample code to configure ALT Beacon library for filtering is appreciated and this helps to avoid additional filtering logic implementation at the application.

Filtering on a prefix of the UUID is unusual, but it is possible by defining a custom beacon layout and defining an additional identifier to be the UUID prefix. Because this new extra identifier will be treated as an independent identifier, it won't work like a string prefix -- its default representation will.be a hex string (without dashes).
If you want to filter on the first five bytes of the UUID for iBeacon, you'd set up a beacon parser like this:
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-8,i:4-19,i:20-21,i:22-23,p:24-24")); // note the new 5 byte prefix identifier: i:4-8
Now each beacon will have four identifiers instead of three, the first of which will be the beginning 5 bytes of the UUID, the second the full UUID, the third the major and the fourth the minor.
You can set up a region to match the first five bytes of this UUID, 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 like this:
Region region = new Region("prefixRegion", "0x2F234454CF", null, null);
If you want the prefix to be a different length than 5, simply adjust the i:4-8 part of the layout above to end in a different offset than 8.

Related

dataFields holding only one long value in AltBeacon

I am trying to send two long values (latitude and longitude) in the beacon's data fields, as a list of long, but only the first long value gets through.
I tried to put both values, latitude and longitude, in the dataFields:
.setDataFields(listOf(latitude.toLong(), longitude.toLong()))
and the result is [53], which is just the latitude.
I tried to put the latitude in the dataFields and the longitude in the extraDataFields:
.setDataFields(listOf(latitude.toLong())) .setExtraDataFields(listOf(longitude.toLong()))
and the latitude is correctly set, while the extraDataFields remains empty.
Is there a constraint regarding the dataFields, such as being able to only hold one value, despite being a list of long?
Different beacon formats support different numbers of data fields and sizes.
iBeacon - 0 data fields
AltBeacon - 1 data field of one byte
Eddystone UID - 0 data fields
Eddystone TLM - 5 data fields of sizes 1, 1, 1, 4 and 4 bytes, respectively
You may also define custom formats with any number of data fields that fit into the packet.
If you use the setDataFields method to put more data bytes into the beacon than the format allows, the extra data will be ignored and not be included in the advertisement.
A common alternative approach for encoding latitude and longitude is to encode these in the major and minor identifier fields (ID2 and ID3) for iBeacon and AltBeacon.

Can we send simple string at a time of advertise data via bluetooth low energy

I want to check that can we advertise simple string like "ttfgpV5hm8Z4mMlD" at the time of peripheral advertising I'm trying to pass this string into CBUUID string but whenever central scan for peripheral it gives an error like _C.CBUUID.CreationError.invalidString: I write down code which I use in peripheral and central.
Peripheral side :
Peripheral(configuration: configuration, advertisementData: [.localName("Test"), .servicesUUIDs("ttfgpV5hm8Z4mMlD")])
Central side :
let configuration = try! Configuration(services: [service], advertisement: "ttfgpV5hm8Z4mMlD")
please give me a guideline for how to pass a simple string at the time of scanning and advertising.
CBUUIDs are UUIDs that contain hexadecimal digits - they aren't arbitrary strings. So unless your "simple string" only contains hex digits and you don't mind handling the hyphen separators, then you can't. What you can do is include the string as a value of a characteristic that is included by the service.

NSUUID duplication chance form different device.

I need to generate Unique ID for the device when the application installed, and store this value on the device, then need to communicate with server using this UUID. And it seems NSSUUD suit for the sitiation, but I am confused is there any chance of duplication of the UUID from multiple device. I already found the answer https://stackoverflow.com/a/6963990/1573209 where it describe that the version 1 type uses MAC address and 60 bit clock to generate UUID, so the duplication chance is negligible. Where as the Version4 uses some fixed number and some random number to generate the UUID, and the doc says that UUIDs created by NSUUID conform to RFC 4122 version 4 and are created with random bytes
Does that mean the chance of duplication higher?.
Then how can I use version 1 type of UUID generator, I cant see any documentation for it.
You can have look at this RFC 4122. UUID conforming to RFC 4122 are practically unique in given space and time. You can also see Random UUID probability of duplicates.
Out of a total of 128 bits, two bits indicate an RFC 4122 ("Leach-Salz") UUID and four bits the version (0100 indicating "randomly generated"), so randomly generated UUIDs have 122 random bits. The chance of two such UUIDs having the same value can be calculated using probability theory (birthday problem). Probabilities of an accidental clash after calculating n UUIDs, with x = 122 is found to be very close to zero
For n=2^36 which is 68,719,476,736 probability of collision is found to be 0.0000000000000004. For lesser value of n, this value will be even less and probability increases as more UUID's are generated. In above estimation n represents number of UUID's generated.

Are UUID's, and the most basic level, just a string of unique characters?

I am currently learning about UUID in iOS, and of course I'm trying to make sense of them. From what I can gather, when you call NSUUID(), it returns a 128 bit string that is completely unique (though I'm not currently interested in how it can ensure a completely unique string, I figure it takes into account the date, time, and device identity). To make use of this string, you can append it to the end of the Document Directory (which I believe is unique to each application) to ensure a unique file path that can be used to access files later. Is this a correct understanding of the concept?
Globally Unique Identifiers are 128-bit binary strings.
Microsoft COM uses them to prevent "name collisions" between components without needing some "central naming authority" (like we have for DNS names, IP addresses, broadcast frequencies, etc etc).
GUIDs are likely to be unique ... but it's not guaranteed.
Here is a good article explaining more:
http://betterexplained.com/articles/the-quick-guide-to-guids/
And yes, your understanding of iOS NSUUIDs is exactly right:
http://nshipster.com/nstemporarydirectory/
http://nshipster.com/uuid-udid-unique-identifier/
It depends on the version of Universally unique identifier. Version 4 is almost guaranteed to be unique but not completely. Wikipedia states the following:
"Out of a total of 128 bits, two bits indicate an RFC 4122 ("Leach-Salz") UUID and four bits the version (0100 indicating "randomly generated"), so randomly generated UUIDs have 122 random bits. The chance of two such UUIDs having the same value can be calculated using probability theory (birthday paradox). Using the approximation"
Reference: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29

sqlite query for range search having text for ios app

I have a table with columns as LowerFrequency, HigherFrequency and ID. The frequencies entered have a suffix of khz or mhz. I want to search a specific frequency by checking the range it falls in i.e between the lower and higher frequencies and fetch the respective ID.
The query I implemented was as below but it returns a wrong output:
select tablename.ID where "100 khz" between tablename.LowerFrequency and tablename.HigherFrequency;
I know the reason is because of the khz that follows the integer. But I need some suggestions to handle this as I am not in a situation of changing the whole DB file because it is time consuming.
I will be integrating this DB with my iPhone app. So any solutions in Objective C would also be appreciated. I mean some kind of conversion.

Resources