Sending data from computer to iOS using Core Bluetooth - ios

Is it possible to send data from any computer the supports BLE (Windows or Mac) to an iOS app's CBCentralManager?
The data I want to send is purely text based. I'm searching for it but I am not being able to find if it is possible or a tutorial of how to do it.
Any help would be greatly appreciated.

Yes, normally you can do that. What you have to do is:
From the peripheral device (transmitter), advertise an CBService
(iOS) with a CBCharacteristic that support write value.
From the receiver, you create a CBCentralManager to search for the service created by the transmitter, then discover the right CBCharacteristic. Once the CBCharacteristic discovered, you can try to write value to that characteristic.
The processus look simple, but you have to do step by step on the receiver's side:
first, look for device
if device found, try to connect
then once connected to that device, try to discover the service
then once the service discovered, try to discover the characteristic
then once the characteristic is discovered, try to send
then you will receive the result of sending (ok or failed)
Take a look at my project in github, it's not complete but it show you how to exchange data between 2 BLE devices. The application is for iOS, but I'm pretty sure that you have the same code in Mac OS. I don't know how it works on PC.

Related

How to clone BLE device (configurations,charcterstics etc)and share it with other

I am working on an app that gets data from the BLE device, I am able to code to get the app to connect with the BLE device. But further characteristics read is an issue as I don't physically have the device
i came across an app named nRF Connect for Mobile . It has the functionality to clone BLE if paired. the video for a BLE clone is shown here but export and import is not avaible
Is there any way I can get the BLE cloned say some configuration file, which then imported in certain app create then same BLE device .i can use to read all the characteristics and other properties
Why don't you just connect to the device in for example nRF Connect, write down the services, characteristics and descriptors you see (usually isn't that many). Then just set up a local GATT server with the same content.
If I understood your question and your video correctly, you would like to copy the advertisement data of a BLE peripheral and use it to advertise on an iOS device yourself.
Maybe CBPeripheralManager can help you do that.
You can call startAdvertising([String:Any]?) and advertise a BLE peripheral.
But iOS limits on a system level which keys you can advertise.
From a short look in the documentation, it seems only the keys
CBAdvertisementDataLocalNameKey
CBAdvertisementDataServiceUUIDsKey
are supported.
But if you'd want to include more information about your peripheral, you could still create an own CBMutableService "deviceInfo" and send information within a characteristic after having established a connection.

How to send data through central mode to peripheral?

I'm developing an application where Client App starts BLE scanning in "Central" mode and there is a scanner App which Acts as "Peripheral",client will keep scanning for Scanners (Beacons) with specific id (where the Scanners are advertising the same id) when that both id match data is sent over BLE to the scanner app I have an example code which works perfectly from peripheral to central but i don't have idea about my case how it work.
The Demo which you are following is the correct one for a beginner. In this Demo, app is sending text data from TextView. The text data is passed in octet form, in iOS it is considered as Data (.utf8).
Now, question is, which type of data you want to send from Central to Peripheral.
The General flow is:
1. Central will proximate peripheral so that other Bluetooth manager can scan it.
2. Once anyone try to connect with that peripheral, then on successful connection, it will return available Services and Characteristics inside of those each services.
3. Based on characteristic, you can write your own logic to send text, images, audio, video or anyother data from Central to Peripheral.
Just follow the Demo link which you are following. Thanks.

How to match EAAccessory and CBPeripheral with MFi device?

I have MFi device which uses BLE for control and Classic Bluetooth for audio streaming.
In the App, i use coreBluetooth framework to scan BLE and EAAccessory framework to scan Classic Bluetooth.
I don't want the BLE of target device to be connected if its Classic Bluetooth is not yet connected. So i need to know which EAAccessory is corresponding to target CBPeripheral.
I am familiar with coreBluetooth, there is UUID string to identify the CBPeripheral. But it looks not exist in EAAccessory.
I have an idea but not sure: maybe firmware side can config EAAccessory's serial number and CBPeripheral's manufacture data in advertisement data with the same
serial number, so that App side can check if they are the same.
Dose anyone knows the general way to implement this in App side and firmware side?
I really do not think there is s relationship between the 2. BT and BTLE are managed by different chip at peripheral side and phone side.
Usually in BT you use the MAC address to identify the peripheral on BTLE side the MAC address is not used anymore since iOS at the first connection give its own identifier to the peripheral.
What you can do is probably at firmware side, by exposing a service with a characteristic that somehow relate the 2.
UPDATE AFTER COMMENT
I see, as far as I know there a best practice doesn't exist.The worst part is that you have to handle connections differently, mostly due to how connection are made on iOS side. While on the BLE you can choose a not encrypted connection that would not require paring or bonding, on BT side I guess that bonding is required.
Probably the most simple flow would be, user bond the BT device. Once you are in the app and detect the connected BT device, use a scan method for detect BLE companion device by filtering for a specific service id that your device exposes, once you do that you can also filter discoveries using BLE name without still making a connection.
Adv packet are restricted in size (29 usable byte) but you can also use the scan response (31 byte), that exposes some additional properties such as manufacturer data that will be exposed in a dictionary (kCBAdvDataManufacturerData).
Once you know that is the correct device you can start a connection, that does not require pair or bond but is NOT encrypted (Pair and Bond will require the user to accept the connection inside your app).

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 ;)

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