I'm working on an application for iOS (Objective-C).
I'm looking for a way to connect to a BLE device so that you can specify the MAC or UUID of this device.
Currently I have two BLE devices with the same name so the app is not able to differentiate between the two , which gives many problems (these devices do not have the same functions).
Is there any way to specify the MAC or UUID when connected to BLE device?
RSSI signal strength discover the differentiate two or more device.
If once time UUID get from peripheral then also differentiate peripheral.
Note: iOS doesn't give permission to read MAC address of peripheral.
The MAC of the device is not available, nor is any other particularly useful identifier. However, since "these devices do not have the same functions," they should have different services that they advertise. When calling scanForPeripherals(withServices:options:) you should be passing the specific service or services you're interested in. This is much better for performance, and also will automatically filter out devices you are not interested in. Passing nil for serviceUUIDs should only be done for a generic BLE scanner.
If you control the device firmware, you can add services to identify the type of device, or add information in the manufacturer's advertising data to distinguish the devices during scanning.
If these devices advertise the same services and are otherwise identical, then you will need to connect to both and query them to determine which device you wanted. You still will not receive a MAC, however, unless the device provides it via some characteristic.
Typically, a given device will continue to have the same CBPeripheral UUID, and this can be used to reconnect to previously known devices. However, if the device never pairs securely, this UUID is not always stable, either.
Related
I'm a new developer developing a BLE service on iOS and Android. Currently there is a problem that I am facing, that the device address on iOS is the UUID mapped from the mac address, and on Android it is the mac address of the device. So now is there a way on iOS, from the mac address I received can get the corresponding UUID? Thanks everyone!
I am not sure how to do it.
the device address on iOS is the UUID mapped from the mac address
This is incorrect. The peripheral ID is not "from" the MAC address. It's just a random UUID. It's not even stable (it can, and does, change over time, though not quickly). There is no way on iOS to get the MAC address of a BLE device, or even to absolutely uniquely identify a BLE device unless you control the firmware. If you do control the firmware, then you can provide some mechanism to uniquely identify the device over a protocol of your own design.
As a broad rule, you can use the peripheral ID to identify or connect to a device you've connected to before. This isn't 100%, because the ID does change sometimes. But for the most part it does work (and it's intended to work, so Apple won't just break this arbitrarily). But you cannot otherwise identify the device.
As a corollary, the peripheral ID on one iPhone is completely unrelated to the peripheral ID on another phone for the same device. This is intentional.
You will have to adjust your design to deal with these facts.
I'm trying to use the ESP32 to check if my iPhone is in the house using the bluetooth.
The problem is that when I scan near devices with the ESP32's bluetooth, the iPhone only sends two things:
Mac address
Service UUID
The Mac address changes every 15 minutes more or less, so it's useless.
And the UUID is not unique.
I find other devices with the same UUID (strange)
Someone knows how can I workaround these limitations and recognise if my iPhone is near or not?
Thank you all!
This is all by design of Bluetooth. Bluetooth intentionally makes tracking unpaired devices difficult. See Bluetooth Technology
Protecting Your Privacy for a very high-level overview of how this works.
If you pair with the phone, you can get the IRK (Identity Resolution Key), and with that you get resolve the "real" MAC address and identify the phone. That said, if you're using esp-idf, the code indicates that it doesn't support RPA (Resolvable Private Address). See also BLE generating and resolving random mac addresses does not work correctly where they also suggest this is a limitation of the ESP32.
That said, iPhones do advertise a LocalName, and if this is just for use in your house, and you control your phone's device name, you can just look for that in the advertising packet. Note that the local name may be truncated or eliminated if it is long or there are other things the phone needs to advertise. If it's not advertising it, you can connect and read it from GAP. See How do you get the actual name of a bluetooth low energy device?
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.
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.
Can you pair a bluetooth LE device in an iOS app, i.e. not via Settings. Trying to make it easier on the user to pair with a specific device.
If so how?
You don't pair Bluetooth LE devices through system settings. Generally you don't pair with Bluetooth Low Energy devices at all. The only time that pairing is required is when the device has an attribute that is marked as encryption required - attempting to read this attribute will trigger a pairing process, but before you can read you need to discover and connect to the device.
Discovery and connection is handled by the Core-Bluetooth framework.
The Core Bluetooth Programming Guide goes through the steps required to use a CBCentralManager to discover and connect to a BLE peripheral.
According to the BT SIG Security Manager documentation you can pair/Bond ble devices if they respond to the message that is.
You can also wait and do it as previously explained from the peripheral side. Some devices like HipKey does this automatically when connecting first time.
Look at BTSIG Security Manager specifications.
On Android this also works from BT settings menu IF the peripheral supports it.
Bonding and Authenticating are usually confused but om most platforms it means the same.
A good way to try this out is by buying the TI ble development kit. Its cheap. It comes with a USB dongle and SW which can be used to initiate pairing like from the settings menu.
To do it from iOS just connect and read a known encrypted characteristic.
Cases where you want to "pair" (remember a Bond) includes Pulse meters, hearing aid, keyboard and other private units.