6

Ok I've been searching googling and learning all morning. I've installed gatttool, learned about hciconfig, hcitool, sdptool, and a bunch of other stuff and I still cannot find the answer.

I would like to be able to have a bluetooth process on my raspberry pi that I can connect to from my iPhone's "bluetooth" menu. Seems like it should be really really simple.

I've seen guides and tutorials about connecting to a bluetooth device from a raspberry pi, but nothing that will allow me to make the raspberry pi the bluetooth device.

I've also tried running: sudo hciconfig hci0 piscan, but this didn't really do anything for me.

Is it possible to have my raspberry pi participate in the Service Discovery Protocol and be found by my phone?

Update:

I've also seen this answer Automatically accepting Bluetooth connections on a Pi 3 using this command: hciconfig hci0 sspmode 1, and while that seemed promising it didn't resolve the issue

OneChillDude
  • 183
  • 1
  • 1
  • 7
  • Please post your answer, when you will find it! – moonvader Nov 13 '16 at 07:41
  • Please try using a different device to find the Pi. For example a laptop with BT on Windows seem to find everything. You can also get nice tools on windows to try and test connection and debug them. It is possible iPhone is being difficult as usual. – Piotr Kula Dec 01 '16 at 10:10
  • Did anyone ever find an answer here? – Jonathan Dec 21 '19 at 21:36

2 Answers2

2

Three things that need to be in place for the iPhone to connect with BLE to a Raspberry Pi:

  1. There needs to be a BLE service running on the Raspberry Pi
  2. That service needs to be advertising itself on the Raspberry Pi
  3. There needs to be an application on the iPhone that understands what to do with the advertised BLE service.

To test this there are some general tools available.

On the Raspberry Pi the Bluetooth stack is BlueZ. In the source tree of BlueZ they have an example Python scripts for a GATT server (BLE service) and an example advertisement for that example GATT server. They are available here:

Then on your iPhone, install a generic BLE tool. I always recommend the nRF Connect

As a side note, any tutorial that mentions the 8 tools (hciattach hciconfig hcitool hcidump rfcomm sdptool ciptool gatttool) that have been deprecated by BlueZ is a warning sign that the tutorial might be out of date.

If you want an even quicker test. Then you can create an Eddystone URL beacon that you will not be able to connect to, but will show up as an entry in nRF Connect:

This will create the beacon displaying a URL of https://www.bluetooth.com/

On the Raspberry Pi:

sudo btmgmt add-adv -u feaa -d 1016aafe100001626c7565746f6f746800 -g 1

Which will show something like this on the Phone:

nRF Connect entry for beacon

ukBaz
  • 1,457
  • 1
  • 6
  • 22
  • The suggested btmgmt command fails on RasPi4 under Bullseye with Add Advertising failed with status 0x0d (Invalid Parameters) – Mark Setchell Feb 08 '22 at 10:49
  • Probably worth creating a new question with this. Use sudo btmon in a different terminal to see more detailed log information when you run the command. Also worth doing a sudo service bluetooth restart before running creating the advertisement so starting from the same setup. – ukBaz Feb 08 '22 at 11:30
2

This task (To be able to discover raspberry pi from iphone's bluetooth menu) seems require quite an effort. iPhone seems to ignore all discovered bluetooth device which doesn't meet its standard. See: https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf I don't think a simple script or a single command line would do the trick, you have to write a bunch of codes defining iPhone known bluetooth services, profiles and characteristics.

I am also aiming this, and learned that I have to teach myself the concept of bluetooth communication protocol on all its layers.

  • 1
    Bluetooth is supposed to be so simple for user to use but I have always found writing code for it was a nightmare. Especially for iOS with their crazy extra layers of standards as you mention. – Piotr Kula Dec 01 '16 at 10:09
  • Just for the record, as described at https://didier.io/post/raspberrypi-stream-sound-over-bluetooth it works without much effort now. – Stepan Vavra May 16 '18 at 17:58
  • Stepan Vavra, We are talking about BLE here, not Bluetooth. – Nandha Handharu Nov 14 '18 at 09:10