iPhone corebluetooth central Manager send data to peripheral
Asked Answered
P

3

15

I want to send data from iPhone to a bluetooth device which get discovered and connects. I am referring this tutorial to connect.

I am not able to send data to external bluetooth device which is connected as we do with External Accessory framework.

I am using iPhone5 as it has Bluetooth 4.0

Pyxis answered 26/9, 2013 at 6:21 Comment(0)
D
22

In Core Bluetooth you need to use the characteristics for communication. There is no standard stream based API like in the External Accessory Framework and I don't know of any open source libraries that implement something like that.

Basic operation

Peripheral -> Central:

  1. Central subscribes to characteristic (either with notifications or indications)
  2. Peripheral receives the subscribed callback so knows that the central is listening
  3. Peripheral updates characteristic
  4. Central receives characteristic updated notification

Central -> Peripheral:

  1. Central writes characteristic
  2. Peripheral receives write request update

The actual speed you can achieve depends on various factors. With indications the data is never lost (like TCP) but notifications don't have such guarantees (like UDP).

More info

I suggest you check out the official Core Bluetooth Programming Guide and concentrate on the

sections. But better would be studying the whole guide as is. For a working example, check out the BTLE Transfer example from Apple, as well.

Distinguishing answered 26/9, 2013 at 8:6 Comment(6)
I have checked BTLE Transfer but there is no sample to send data from central to peripheral.Pyxis
The central sends data by writing the characteristics on the peripheral.Distinguishing
@Pyxis Updated the answer to describe the basic scheme of operation in both directions.Distinguishing
I'm heaving hard trouble here. I can't get data reading on the peripheral side working. I can send data from P->C, but not vice-versa.Lynnell
@Julian You need to write characteristics you discovered. What is not working?Distinguishing
See my question here: #20034933Lynnell
B
5

If i understand you correctly you want the central to send data to your peripheral.

for that you use this method:

[peripheral writeValue:dataPacket forCharacteristic:writeChar type:CBCharacteristicWithResponse]
Ballista answered 26/10, 2015 at 10:39 Comment(3)
There is no such API in CBPeripheralManager classSelmner
Gilli is not calling writeValue on a CBPeripheralManager but on a CBPeripheral which does have that APIStandice
what is writeChar ?Godewyn
S
1

This is pretty compelling video to watch and know what exactly goes in iOS bluetooth framework. Its clearly explained what operations can be performed by central and peripheral systems.

https://developer.apple.com/videos/play/wwdc2012-705/

Selmner answered 29/10, 2015 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.