0
votes

I am currently working on a project involving interaction with Bluetooth Low Energy tag and iPhone. I want to know how I could register a key pressed on the bluetooth tag on the iPhone. i.e When a user presses a key on the tag, the app on the iPhone should be able to recognize and perform a certain function (say emit a sound).

I am using a Texas Instruments 2540 tag and was referrring to their sample code. In their code,

A key press notification has to be enabled. When a key is pressed on the tag, the corresponding service and characteristics UUID value gets updated. In the app, the 'didUpdateValueForCharacteristic" delegate method gets called and appropriate functions can be called.

However, the company designing the bluetooth tag insists that a service be created on the iPhone app (iPhone acting as a Bluetooth server) and the bluetooth tag will alert the iPhone acting as a client.

My code excerpt is

define Key_Press_Notification_Service 0xFFE0
define Key_Press_Notification_Characterisitc 0xFFEA

-(void) enableButtons:(CBPeripheral *)p
{
[self notification: Key_Press_Notification_Service characteristicUUID:Key_Press_Notification_CharacterisitcUUID p:p on:YES];
}

// -(void) notification... Method

// - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic.. Method


Can you help me on whether this is possible ? And how I could register a key pressed from the BlueTooth tag to be identified on the iPhone ?

2

2 Answers

3
votes

Manjua,

Once you have your peripheral and forCharacteristic:characteristic you just need to enable the notifications:

// begin notification for the characteristic.
[peripheral setNotifyValue:YES forCharacteristic:characteristic];

You then use your CBPeripheralDelegate to receive the updates:

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
1
votes

This looks like a "FindMe profile" scenario, described in http://developer.bluetooth.org/gatt/profiles/Pages/ProfileViewer.aspx?u=org.bluetooth.profile.find_me.xml. The "Find me locator" (bluetooth tag) and "Find me target" (iPhone) each should have an "Immediate Alert" service. The Immediate Alert service behaviour is described in http://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.immediate_alert.xml.

When a key is pressed on your tag, it should perform a write on the Alert Level characteristic residing on the iPhone.

Alternatively you can make your own custom profile. I.e. some characteristic on the tag performs a notification when a key is pressed. Your iPhone app would then subscribe to this characteristic and be notified of any key presses. Custom profiles would of course mean that your tag won't be out-of-the-box compatible with Bluetooth Smart Ready devices.