How to use core bluetooth framework get data? - ios

I am working on an iOS core Bluetooth application, i can connect the bluetooth device use iphone4S , but i dont know how to communication with the device. i want to read information form the device.
i also see this sources code https://github.com/sergiomtzlosa/CoreBluetooth-Demo/
and this article How to read information from core bluetooth device
but i dont understand how to transfer data.
can some one help me? thank you

To use CoreBluetooth, first your device must support Bluetooth Low Energy in Bluetooth 4.0. You can't connect to the device through iOS's UI for LE, you will have to develop your own UI for it because your application need to connect to only the devices with the services that you are interested in.
After that, you can subscribe to notification of the device when a characteristic value is updated, and then read the value using CoreBluetooth API. If the device has a characteristic that can be written to, then your application can write to the characteristic using CoreBluetooth API.
That's the general idea, hope that answers your question.
Edit: check out these samples:
Heart Rate Monitor
Temperature Sensor

A very similiar question has been asked and answered.
Read through the framework and find methods and callbacks with very descriptive names like:
- (void) centralManagerDidUpdateState:central
- (void) centralManager:central didDiscoverPeripheral
- (void) peripheral:peripheral didDiscoverServices:error

Related

How to retrive the information of BLEs which are connected to a BLE

I'm new to Core Bluetooth. Using custom GATT my BLE device will exchange the information with other BLE devices, What I have to do is collect the information that my BLE device got and need to send it to cloud and after that need to clear that data.
I mostly saw Central Manager(Phone) and Peripheral(BLE device) examples but not sure how to get the connected BLE devices information. Do I need to use CBPeripheralManager? Please suggest the approach to handle it. Thanks.

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.

Tracking a moving device using BTLE

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.

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