How to send service UUID - ios

We are developing an app which needs to scan for beacons in the background. This requires us for iOS to specify a service UUID while scanning. See Apple documentation:
Apps that have specified the bluetooth-central background mode are allowed to scan while in the background. That said, they must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter. The CBCentralManagerOptionShowPowerAlertKey scan option is ignored while scanning in the background.
We are using a Raspberry Pi with a bluetooth adapter to send a beacon signal (conforming the AltBeacon spec). Unfortunately we are not able to find out how the service UUID should be set in the BLE Advertising PDU, is it part of the Bluetooth specification or part of the Manufacturer specific data structure? We did find examples for setting the service UUID for when you use an iOS device as beacon, but since we are using a generic bluetooth adapter we cannot use that.
Could anyone clarify us how and where the service UUID should be set in the beacon transmission?

is it part of the Bluetooth specification or part of the Manufacturer specific data structure?
the later.
generally when you setting the advertising parameters, you can set the UUID(or name, tx power, etc) to it.

Related

BLE: Advertising local name and service UUID from background iOS

According to iOS documentation, when an iOS application that utilizes BLE as a peripheral moves to background mode, peripheral name is not advertised and all service UUIDs are placed in a special ‘overflow’ area, they can be discovered only by an iOS device which is explicitly scanning for them.
I sniffed the BLE packets sent over the air when application is in background. There is no local name and service UUID data. There is an 'overflow' area which encodes the service UUID. A brief discussion can be found here: https://github.com/crownstone/bluenet-ios-basic-localization/blob/master/BROADCASTING_AS_BEACON.md
I wish to know if there is any way we can determine the actual service UUID being advertised from the data in 'overflow' area. iOS documentation states that when an app is advertising as BLE peripheral in background, another iOS app can find it by explicitly specifying the service UUIDs to scan for. So, there must be a way to figure out the actual UUID from overflow data.
Any pointers on this would be helpful.
No. The data in the overflow area is hashed (sending several 128-bit UUIDs would be much too large for an advertising packet). I don't believe the hash is documented, but I strongly suspect that it's based on a Bloom filter, so that Apple can probabilistically pack a unlimited number of UUIDs into the very limited space of an advertising packet.
The upside of all of this is that it means the data isn't there in the advertising packet (and really can't be). You will need to connect to the device to discover its services.

How to scan and connect to iBeacon using BLE services in the background

I have a iBeacon device with services advertising. I need to know to how to connect to the iBeacon from the iOS app in the background mode.
I know the service UUID of the iBeacon but I am not able to scan using serviceUUID in foreground and background mode.
If I scan for nil and filter using the name, working in the foreground but not in the background.
Please help me, I am new to iOS programming. Any ideas?
Don't confuse the ProximityUUID of the iBeacon transmission with a GATT Service UUID. While both are 16 byte identifiers typically represented in the same hex format, the two have entirely different meanings. An iBeacon ProximityUUID cannot be used as a GATT Service UUID.
There is no requirement at all that a bluetooth beacon transmitting an iBeacon frame hosts any connectable GATT services. While some manufacturers do offer a GATT service in their hardware beacons for configuring its identifiers as well as other purposes, the GATT Service UUID is typically not the same as the ProximityUUID.
If you want to do what you describe you need to:
Find out of your beacon manufacturer even hosts a GATT service at all.
It yes, find out what the GATT Service UUID is. Again, it will typically not be the same as the iBeacon ProximityUUID.
If you cannot get the info from the manufacturer, you might be able to find it out by scanning in the foreground (without specifying the GATT Service UUID), then printing out the discovered GATT Service UUIDs for the device that you get by calling discoverServices on the CBPeripheral from the scan results. You may find there are no services, which would give you a no answer to the first question above.
Once you have the above info, you can scan for the beacon in the background by specifying the GATT Service UUID when starting the scan. In the background, you will not get results if you do not specify a GATT Service UUID, and even if you do results will come much more slowly.

Is it possible to write data on iBeacon

I am going to use iBeacon in my app. Is it possible to write values on it, when the app is opened. If yes how do I achieve this. By using coreBluetooth I can do this.
NSData *bytes = [#"0xDE" dataUsingEncoding:NSUTF8StringEncoding];
[peripheral writeValue:bytes forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
An iBeacon just advertises 3 values; a UUID, a "major" value and a "minor" value.
Beacons typically have some BLE service and characteristics that are used for configuring these and other parameters (such as advertising rate and transmit power) but this is outside of the iBeacon specification; each vendor will have their own service and characteristics.
First you need to know the different between iBeacon(bluetooth beacons) and ordinary Bluetooth device. (You can google it)
The CoreBluetooth function you are calling is for altering values on connected bluetooth peripheral, the keywords are connected bluetooth peripheral which iBeacon is not.
Bluetooth peripherals include GATT server, which allows bluetooth centrals to connect and access its services and characteristics.
While iBeacon just advertises, UUID, major, minor, RSSI. No GATT server, no services or characteristics.
To conclude, there is NO SIMPLE WAY (using bluetooth only) to alter the value ('UUID', 'major', 'minor') on a ORDINARY BEACON.
But some beacon manufacturers do provide some similar solutions, they add extra hardware to beacons (network hard). And provide web portal for beacon owner the control the beacon remotely.
I have developed an app which can modify the iBeacon data of Bluetooth device recently.
There is no standard method in Bluetooth Specification for you to write iBeacon data.
It means that you must use the custom command as you and Bluetooth firmware developer both agree to do this,whatever kind of data communication,different vendor has different methods,both of app developer and Bluetooth firmware developer agree, this is enough!

Identify iOS peripheral advertising in background

I work on iOS application with acts as Bluetooth peripheral. I need to implement a searching for my iOS peripheral from non iOS centrals. I’m faced with a problem while my iOS application advertising in background mode. When it is advertising in foreground, my central can read primary service UUID from advertising data, but when it is advertising in background, I can’t see the name or the UUID of peripheral – there is only Apple manufacturer data in advertising packet.
The essence of the problem lies in the fact that my non iOS central can’t determinate – is it advertising my peripheral in background or any other peripheral in background. I have to connect every iOS device with advertising in background, enumerate its services to look for my service UUID.
The documentation says that during background advertising all service UUIDs go to special “overflow” area and only iOS devices can read it specifying service in CBCentralManager’s scanForPeripherialWithServices method. It looks like Apple have an ability to check background advertising packet data for service UUID.
After searching on SO I found some interesting information about service hashed UUID. Background mode advertising packet always contains Apple manufacturer data (14 FF 4c 00 01) and undocumented 128 bit value, where one of these 128 bits equals 1. I tried to change my service UUID several times and found out than this 128 bit value after Apple manufacturer data changes too.
I’d like to use this value to filter peripherals around and reduce
connections to wrong (not mine) peripherals. Can anyone give any
information how this value depends on service UUID? Is there any
hash function that is used on specified service UUID in
scanForPeripherialWithServices method?
Can I be sure that the background advertising packet will always be the same for the immutable service UUID which will never change?
Is there any other way to send my custom information while
advertising in background mode? Maybe I can add my data into BLE
SCAN RESPONSE packet?
Best Regards,
Dezmond

Using generic BLE beacons with iOS?

I'm looking to create a BLE Beacon which does not follow Apples iBeacon specification. The reason being that the "beacon" will be an arduino device which the app should also be able to communicate to to instruct it to do things. Is this supported on iOS? I've heard rumours of iOS 8 locking down on generic device advertising via Bluetooth.
Thanks in advance.
Yes, you can do this using the CoreBluetooth APIs, but there are a few restrictions depending on what type of Bluetooth LE advertisement you use.
1. Manufacturer Advertisement
You can read all the bytes of the manufacturer advertisement (up to 24 bytes) using CoreBluetooth, but only when an app is in the foreground. In the background, you will get no callbacks. This is often paired with a second iBeacon advertisement that wakes the app up in the background on iOS. For an example of this type of advertisement, see the AltBeacon specification.
2. GATT Service Advertisement
A GATT service advertisement detection will be sent to an app by CoreBluetooth even when the app is in the background, provided that the app is specifically looking for the GATT service UUID of the beacon. The disadvantage of this approach is that the data payload is generally limited to only 18 bytes after the 2-byte service UUID.
Other Details
In the case of both advertisement types, you can connect to the device using GATT, and read and write data. Note, however, that once you connect the device will generally stop advertising as a beacon.
Both of the above work as described with iOS 8. It's hard to predict the future, but it seems unlikely that Apple will lock down on the above two use cases as they are widely used for Bluetooth LE applications aside from Beacons.
You can see the basic steps to read these advertisements in this blog post. While the post is specifically about how Apple filters out iBeacon advertisements, if you make your own custom manufacturer advertisement, it will allow you to read the bytes as described in the post.
For the sake of completeness, both of the advertisement types above can be picked up by Android devices both in the foreground and the background.

Resources