8
votes

I am trying to connect to a Raspberry Pi via iPhone using CoreBluetooth (bluetooth 4.0). I have discovered the device and send out a connection request using this code:

if (peripheral != self.foundPeripheral) {
    NSLog(@"Try to connect to %@", peripheral.name);
    self.foundPeripheral = peripheral;
    [self.centralManager stopScan];
    [self.centralManager connectPeripheral:peripheral options:nil];

}

Neither the didConnectPeripheral or didFailedToConnectPeripheral are called. I also made sure to set the RPi to advertise bluetooth low energy using

sudo hciconfig hci0 leadv

but when I check active connections with

hcitool con

there are no active connections. Am I missing some set up for the RPi? Also the name variable on the peripheral is blank, is that because I have not connected yet?

1
Do you have an sort of GATT server running to respond to requests? I think the hciconfig may just flip the switch to turn on advertising, but there's actually nothing responding to connection requests.Tim Tisdall
I don't have a GATT server running at the moment, but it makes sense that something has to be running to process everything. I will look into it and comment again later. Thank you!Jacobcr
I thought there was a test GATT server that's part of the Bluez source code, but I couldn't find it. There is a file called attrib_server.c that seems to contribute to that kind of role.Tim Tisdall
An alternative to the BlueZ stack is to use a BLED112 dongle from BlueGiga. It's flashable, has reasonably simple API and development kit to get basic tasks done. You would code the GATT server inside of the BLED112 dongle using simple script and XML files and communicate to Linux via the USB endpoint.barbazoo

1 Answers

3
votes

Try out bleno, it's a node.js library that can be used to create a BLE peripheral on both OS X and Linux. It works well on my Raspberry Pi running Raspbian.