How to connect back IOS Bluetooth low energy - ios

There are 2 IOS devices: device C and device S. They both host a service with a characteristic and both advertise themselves. Device C have found device S and connects to it. After characteristic is found, connection C -> S is established. But after it device S wants to connect back and write to characteristic on device C instead of writing to local characteristic and notifying device C. That way both devices are central and peripheral at the same time. Is there a way to do this?

Related

swift how to develop an app performing an actual bluetooth pair

The actual bluetooth pair I am talking about is: let the app shows up in the searching list of Bluetooth of System Settings and other devices can pair to it (like we pair our device to Apple Air Pods).
But all articles I find online are talking about BLE/CoreBluetooth, I don't think these methods could make a device name shows up in the Bluetooth of System Settings.So how to develop an app performing an actual bluetooth pair? Any ideas?
The Bluetooth preferences screen only shows legacy Bluetooth peripherals. Devices advertising BLE services do not appear.
Apps on iOS do not have the ability to create and advertise legacy Bluetooth services.
If you create an app that acts as a BLE peripheral, using Core Bluetooth, and specify that encryption is required for a characteristic then you will trigger a pairing process when an app acting as a Bluetooth central on the other device connects and attempts to read/write that characteristic. Note that this requires cooperating apps on both devices.

How to get unique ID of Bluetooth Device using Core Bluetooth in iOS

I am developing an application that requires the ios device to provide Bluetooth UUID (to get the Bluetooth UUID from scanned/connected device), then send it to the server for further development. I can not find any answer on the internet.
I am using core bluetooth for scanning and connecting device and sent device info name and uuid but uuid changed every 15-20 minutes. How can i recognize previously connected device and how can i get unique BLE device UUID so that i can match identifier with previously added device list. Help please...
You can get the identifier property of the discovered CBPeripheral and connect to that. If you connect then the identifier should not change for that device for a significant amount of time (in practice I don't think it ever changes, but in theory it can).
Once you have a peripherals identifier you can save that value and subsequently get the peripheral via retrievePeripherals rather than scanning.
The issue you will face is that the identifier is specific to the iOS device that discovers the peripheral. Another iOS device will get a different identifier for the same peripheral.
If you need a unique identifier for your peripheral that is transportable across iOS devices then you will need to expose such a value via a characteristic on the peripheral itself and have your app read that characteristic value after it has connected.

iOS Core Bluetooth - Can't discover the real device from scan

I am trying to discover a bluetooth device and connect to it through the use of CBCentralManager. The device is a headset. It can be discovered through bluetooth scan on the phone. The device name is "A1-25". When I connect "A1-25" directly from phone bluetooth settings, I can play songs with it, it's working fine.
However, when I started scanning peripherals using CBCentralManager. I can't see a peripheral named "A1-25". But rather, I saw a peripheral named "EQ_Test_llyan". But before, when I scan nearby devices from the bluetooth settings, "EQ_Test_llyan" did not come out.
2017-12-13 16:35:07.233021+0800 Test[1405:500801] started scanning
2017-12-13 16:35:17.469375+0800 Test[1405:500801] discovered peripheral with name EQ_Test_llyan advertisementData:{
kCBAdvDataIsConnectable = 1;
kCBAdvDataLocalName = "EQ_Test_llyan";
kCBAdvDataManufacturerData = <b0024551 5f544553 54>;
}
2017-12-13 16:35:17.470672+0800 Test[1405:500801] connecting with device!!!!!!!
2017-12-13 16:35:17.654884+0800 Test[1405:500801] connected to peripheral name:EQ_Test_llyan id:7326E741-BF68-D9E8-D7A6-5F27227685A7
2017-12-13 16:35:17.656526+0800 Test[1405:500801] discovering services for peripheral name:EQ_Test_llyan
2017-12-13 16:35:18.193311+0800 Test[1405:500801] discovered services:(
) for peripheral name:EQ_Test_llyan
The peripheral "EQ_Test_llyan" has no services (see above log), so I can't communicate with it. Now, when I went back to the bluetooth devices in the phone settings I am now connected to "EQ_Test_llyan", but not to "A1-25". Now, I try to play the music, the sound does not come out from the headset.
When I turned off the headset, I will be disconnected from "EQ_Test_llyan" and "A1-25" will be gone. Therefore I conclude that "EQ_Test_llyan" and "A1-25" comes from the same device.
Take note that I can connect to both at the same time. I will just connect to "EQ_Test_llyan" programmatically, then it will appear on the settings. Then I manually connect to "A1-25" from the phone settings. It will be like what it shows on the picture below. When I play the music, I can still hear sound coming out from headset. So, it's working fine as long as I am connected to "A1-25", but not to "EQ_Test_llyan" alone.
So my questions are:
Is CBPeripheral referring to the actual device? Because if it is,
why can't I scan "A1-25" but I can scan "EQ_Test_llyan"?
Take note that when the phone is connected to "A1-25", it has an "i"
beside it, this means that the connection can be terminated. But
when the phone is connected to "EQ_Test_llyan", there's no "i"
beside it. So, it can't be disconnected unless you turned off the
device. So, what's the difference between the two? Is "AI-25" the
real device, while "EQ_Test_llyan" is just a connection? I don't
understand.
You can not discover "A1-25" from the CBCentralManager because it is a headset as you've mentioned. Headset uses Headset Profile (HSP), which is known as "Bluetooth Classic" profile, while Core Bluetooth is suitable only for Bluetooth Low Energy (BLE, Bluetooth 4.0) General Attribute Profile (GATT). If you examine the CoreBluetooth API, you'll discover it's all about services and characteristics. It has no abstractions for sound-related profiles.
On the other hand, GATT is very general and abstract profile, and can be used by a device of any kind, each time for some very specific data — speed, temperature, heart rate, some device configuration, and virtually any other values. So you can pair to GATT devices only from an app that aware of that exact device. You just have nothing to do with such generic service from your phone settings screen.

Reconnect to a bonded Peripheral after toggling iOS Bluetooth off/on

I am not new to iOS, but am relatively new to CoreBluetooth and BTLE in general. Using devices running iOS 10 or later ( currently 11.2 ), I have found that if bluetooth is toggled off and on, the bonded peripheral can no longer be accessed.
After doing a bit of debugging, it seems that once bonded, the security information saved on both ends includes the address of each peer. The iOS side remembers the peripheral just fine, but after turning Bluetooth off and on again, the address of the iOS device changes itself, so to the peripheral its currently registered bonded peer (address) no longer exists. For this reason, connection between the two is no longer possible until the bonding information on the peripheral side is cleared ( Peripheral device performs direct advertisement once bonded so that only its bonded peer can see it ).
I would like to know
A) is there anyway to retain the same address on the iOS side after toggling Bluetooth off/on
B) If the address cannot be retained/recalled, what is the usual method for dealing with this sort of situation?
I have searched through the Core Bluetooth Programming reference and have googled this problem to the best of my ability, but to no avail.
Peripheral output via serial connection while bonded with the iOS central:
BTA=001EC0461948 Name=The_Lock1948 Connected=7DD350CC912D,1
Bonded=7DD350CC912D,1 Server Service=00000001 Features=20000000
TxPower=4
iOS Bluetooth off/on, then reconnect with the exact same iOS device:
BTA=001EC0461948 Name=The_Lock1948 Connected=5DDC08C0B0A3,1
Bonded=7DD350CC912D,1 Server Service=00000001 Features=24000000
TxPower=4
As you can see, the "Connected" address has changed while the peripheral remains bonded to the previous address. The only difference between the two is a toggle of the BT setting. When I say BT power off/on, I mean really turn the power off and on, not the "Allow New Connections" setting in iOS 11+.
By the way, just to add to this, I have seen 2 other BTLE peripheral devices ( keyboards ) that cannot reconnect after a iOS BT power toggle until they are reset in some fashion.

Bluetooth Autoreconnect HM10 Bluetooth Serial

I am using HM10-BluetoothSerial-iOS as base for my own application where I remotly control an AtMega.
I wish to automatically reconnect to the HM10 Bluetooth device. As far as I know you cannot store CBPeripherals for a later connection. So how can I reconnect at a later time?

Resources