I'm looking for a convenient way to detect whenever an iPhone is close to, almost touching, a Raspberry Pi. The detection is ought to be made from the Raspberry. I don't necessarily need to exchange any data, all I need to know is when the devices are very close or touching.
I've been brainstorming some ideas but would need your hand on this one, here are my thoughts:
That were my thoughts, I'm sure you have better ideas and I would be delighted to hear them! Any input is valuable :)
You could definitely benefit from using BLE via CoreBluetooth and setting up the Raspberry Pi as a Bluetooth peripheral that you connect to from your app. You can set up the Raspberry Pi to broadcast a unique GATT Service so you can automatically connect to it by finding this service in CoreBluetooth.
Once you're connected to the peripheral, you can use the readRSSI()
method to retrieve the Bluetooth signal strength, and the framework will call the peripheral(_:didReadRSSI:error:)
delegate method with the information you requested. You can then use this to detect (approximately) the distance of the iPhone from the Raspberry Pi.
As far as actual distance goes, the 'RSSI -> distance' relationship will vary between iOS devices, chipsets, and Bluetooth dongles that you use (more information here), so you're probably going to have to play around with the data once you've got the app up and running to find what suits your needs.
Sorry for the high number of links. This question was kind of broad, and I'm just offering my perspective since I've done a lot of work with CoreBluetooth and BLE. As far as I know, WiFi wouldn't be a very great reusable solution, and I haven't done any work with NFC in my apps. Let me know if you have other questions!
Edit: I missed where you said you wanted to do the detection on the Raspberry Pi itself, not the phone. My apologies. I'll keep my answer above as a reference, but you still have options via Bluetooth LE and potentially via NFC, as well (and I'm still ruling out Wi-Fi due to too many variations in network strength and detection).
For BLE, you could follow an very similar approach to the one I highlighted above, except create your iPhone app where your iOS device is a peripheral, and it broadcasts it's services to the Raspberry Pi. For NFC, if you check this thread, both answers seem to have some good starting information on how you could potentially get a tokenized account number from Apple Pay if you hook up an NFC reader to the Pi. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With