Tracking a moving device using BTLE - ios

I'm looking for a way to be able to track another BTLE-enabled iOS device using mine, while within range. Basically, one device would have to log it's geolocation info, and then send it periodically to the other device, using BTLE.
How would I be able to do this? In general, I haven't been able to find much info on how to send and receive messages via BTLE, so any help in that category would be great. I've seen this answer already, but it didn't help me much, and I'm wondering if anything has changed since then.
If not possible through Apple's built-in framework, do you know of any external ones that would allow for this?

Long, long, long, longgg story short, but here ya go:
On one iOS device, adopt both the CBCentralManager and CBPeripheralManager. The CBCentralManager is responsible for connecting to external peripherals and maintaining that connection. The CBPeripheralManager will be what you'll use to read/write from the iOS device that your using a peripheral.
On the other iOS device, adopt just the CBPeripheralManager. You'll need add all the services and characteristics into the CBPeripheralManager that are stated in the GATT profile. Check out developer.bluetooth.org. These services and characteristics are necessary in order to connect from one device to the other.
In addition to just the gatt characteristics and services, you'll need to add in a custom service with a characteristic that you store your location data.
Check out the docs but for CBPeripheralManager in particularly you'll need to utilize
-(void) peripheralManager:(BLEPeripheralManager*)mgr requiresResponseToWriteRequests:(NSArray*)requests;
and
-(void) peripheralManager:(BLEPeripheralManager*)mgr requiresResponseToReadRequest:(CBATTRequest*)request;
in order to pass the location data between devices..Sorry for the brief overview, but there's just way too much to write up quickly.

Related

Can I implement an iOS App to act as a BLE service?

Can I implement an iOS App to act as a Bluetooth low energy service?
I need to be able to programmatically define:
a service UUID
characteristics for the service
a way to update the values of these
a way to define the user permission of the characteristics: read / write / notify
a way to define the transmission (TX) power of the service
Would appreciate if you could point me out to a good demo / example to get started or even share some code snippet so this can become part of the Documentation of iOS.
Read the Core Bluetooth guide as throughly as possible, especially setting up a Peripheral Service:
https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/AboutCoreBluetooth/Introduction.html#//apple_ref/doc/uid/TP40013257-CH1-SW1
Keep in mind that if you are looking to adjust these parameters you need to pay attention to how iOS changes the BLE data structure being emitted when in background mode / inactive state.

iOS Bluetooth Low Energy connection with external device

I made a simple device made by a friend with some sensors and a bluetooth module. Right now the module is 3.0 so I know it's next to impossible to connect with my iPhone to it.
My questions is what specs and settings are required for a Bluetooth Low Energy module to connect with an iPhone so that I can receive data from it ?
First of all, you need to connect to the device
Next, once connected, you need to start looking for the device services
After that, when you discover your main service, or the service you want, you have to look for its Characteristics
Finally, once you discover the wanted characteristic, you need to subscribe to it by using the
[myPeripheral setNotifyValue:YES forCharacteristic:aChar];
Actually, It too long to explain all the detail, take a look at the official documentation, and its really something.
https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothOverview/CoreBluetoothOverview.html#//apple_ref/doc/uid/TP40013257-CH2-SW1
good luck ;)

iOS - corebluetooth retrieveConnectedPeripheralsWithServices: - how to get Advertisement Data?

I'm writing a suite of Bluetooth Low-Energy app for iOS 7.
When the app launches, there's a fair chance the peripheral I'm interested in is still connected to the iOS device, and to avoid scanning for the peripheral it would be great to connect immediately. retrieveConnectedPeripheralsWithServices: looks perfect for this, and indeed seems to work as advertised: I get a list of CBPeripherals which are connected to the device via some backgrounded app.
So far so good, but here's the issue:
There's information in the AdvertisementData which I want, but I don't know how to get the AdvertisementData when going this route.
As far as I can see, advertisementData is only available as a result of scanning.
So my question is this:
* Given a CBPeripheral returned by retrieveConnectedPeripheralsWithServices:, how can I get the associated advertisementData for that peripheral ?
One workaround would take advantage of the fact that the device was likely connected to another of the apps in my own suite, so I could persist the advertisement data myself in storage shared between the apps, but this is neither clean nor ideal, because there's a chance the device was connected to someone else's app, and so I'd have no insight into the advertisement data in that scenario, and would need to resort to a scan.
Unfortunately, the advertisement data is available only if you scan. It is not possible to retrieve it from Core Bluetooth or any other framework in any other way. You should revise your design if the advertisement is so important and rather go along the scanning route.

bluetooth low energy advertising packet and topology

I want to advertise a single id lets say "stackoverflow1" on a ble device. So people close to the sensor can get this message (welcome to wwdc2012) as popups on the iPhone. That's it! meaning that there is no update on the value or anything else in other words I just want to know which room I came in. In another room there's another sensor adversing "stackoverflow2".
Now the question is, should I put the rooms' sensor (advertiser) as Peripherals and visitors' iPhones as Centrals?
If your answer is yes, can I send this Id in advertising packet? i.e. can I skip connection to the room's peripheral? Please guide me a little but on this
Thanks
Yes, the iPhones should be centrals and the in-room device should be a peripheral. It's perfectly fine to put enough data in the advertisement that the iOS app can do something useful after simply seeing the peripheral advertised without actually connecting to it. That way, multiple centrals/phones can detect proximity at once without a single phone tying up an exclusive connection to the device. Instead of specifying the room in the service name, you should be able to put it in the advertisement data for the device, giving them all the same service name. That way the iOS app doesn't need to know the completely list of rooms (i.e. services) in advance and they can be added to without changing the app.
In short, the gist of what you described should work fine, and seems like a sound approach to me.
You can include information in the advertisement from the peripheral as "Manufacturer Specific" data. Then the iOS application can get it from the advertisement data dictionary using the CBAdvertisementDataManufacturerDataKey.

Transmitting data with CoreBluetooth

I'm developing an iOS app with an accompanying Bluetooth LE peripheral. The one step I don't seem to be able to solve is how to actually transmit the data from my app to the peripheral or vice versa.
What I've built so far is a test app that can connect to my sample Bluetooth peripheral, and read all of its services/characteristics/descriptors. It can toggle notifications for a given characteristic, and write to given characteristics. It is just this last step of "transmit n bytes to the peripheral, and receive m bytes from the peripheral" that I can't seem to figure out.
Looking at the External Accessory Framework (what I would use if Apple would actually give me MFi approval for this project), they give you input and output streams on a given session to communicate with the accessory, but no such object exists for CoreBluetooth.
Is this simply an oversight on Apple's part on the functionality of CoreBluetooth? Or do I simply need to develop my own Bluetooth service profile to handle the inflow/outflow of data to and from the peripheral?
LE is fundamentally designed to work with these GATT based profiles, which are suited for monitoring sensors, not for data streams. While LE does allow for additional L2CAP streams to be opened for custom protocols, Apple's CoreBluetooth doesn't provide access to do so.
You can build a custom profile with private services and characteristics and have it work kind of like SSP; that's the way I'm using my BLE module to get data from some sensors to my app. The module I bought (Microchip's RN-4020) already has a custom profile made specifically for this known as MLDP (Microchip Low-energy Data Profile).
The way I get the data in my iOS app is by subscribing to the private characteristic, thus being notified when the values are updated. So far it has been working great, and the data rate can go up to 20 kbps according to Microchip (I haven't tested its limits, since I don't need much speed). Here's a link to Microchip's product page: http://www.microchip.com/wwwproducts/Devices.aspx?product=RN4020
Good luck!
You can use the bluetooth.org 'Immediate Alert Service' uuid=1802 with characteristic uuid=2A06 with property=write_no_response to send one byte values to your peripheral device from your iPhone. The peripheral device must be programmed to act on the data that is sent. For example, you might use a button on an iPhone app to send a hex address that causes one or more port pins to turn on or off on the peripheral. While this is not using the Alert Service as it was intended, it does provide an easy way to test out data transfer to a peripheral device. The same process could be used to send sequential data bytes similar to a serial data stream. I have not yet tried sending more complex data streams. The write_no_response does not provide any feedback to the app as to whether the data was received by the peripheral.
The IOS TemperatureSensor.xproj is an example of code for reading temperature data from a peripheral. The OSX HealthThermometerClient.xproj has the code needed to decode the somewhat complex thermometer data structure. The IOS TI-BLE-Demo.xproj TIBLECBKeyfob.m has code for reading and writing characteristic values, such as, reading temperature or battery levels from a peripheral device.

Resources