Hi,
I have a problem with reading RSSI when LE connection is established. I use SPPLE demo example for a client and SPPLE demo lite for a server. I would like to measure RSSI on client side so I have written simple periodic task called every 1 second:
void ProcessRSSI() { int RSSI; int ret_val; Byte_t Status; Word_t ConnRes; if(RSSI_Context.TrackRSSI_Enabled) { ret_val = VS_Read_RSSI(BluetoothStackID, RSSI_Context.ConnectionID, &RSSI); Display(("RSSI: %d (ConnId = %d, HCI retval = %d)\r\n", RSSI, RSSI_Context.ConnectionID, ret_val)); ret_val = HCI_Read_RSSI(BluetoothStackID, RSSI_Context.ConnectionID, &Status, &ConnRes, &RSSI); Display(("RSSI: %d (ConnId = %d, HCI retval = %d, status = %d)\r\n", RSSI, ConnRes, ret_val, Status)); } }
ConnectionID is taken from command line:
if((LEConnectionIndex = FindLEIndexByAddress(BD_ADDR)) >= 0) { Display(("Tracking RSSI enabled.")); RSSI_Context.TrackRSSI_Enabled = TRUE; RSSI_Context.RSSI = -127; RSSI_Context.ConnectionID = LEContextInfo[LEConnectionIndex].ConnectionID; }
VS_Read_RSSI was added by me in BTVS.c. This is based on similar implementation I have found here in e2e:
int BTPSAPI VS_Read_RSSI(unsigned int BluetoothStackID, Byte_t ConnectionHandle, int* RSSI) { int ret_val; Byte_t Length; Byte_t Status; Byte_t ConnHandle[2]; Byte_t Buffer[32]; Byte_t OGF; Word_t OCF; ConnHandle[0] = ConnectionHandle & 0xFF; ConnHandle[1] = (ConnectionHandle >> 8) & 0xFF; Length = sizeof(Buffer); OGF = VS_COMMAND_OGF(VS_READ_RSSI_COMMAND_OPCODE); OCF = VS_COMMAND_OCF(VS_READ_RSSI_COMMAND_OPCODE); ret_val = HCI_Send_Raw_Command(BluetoothStackID, OGF, OCF, sizeof(ConnHandle), (Byte_t *)&ConnHandle, &Status, &Length, Buffer, TRUE); *RSSI = (int)((signed char)Buffer[3]); ret_val = MapSendRawResults(ret_val, Status, Length, Buffer); return ret_val; }
When I create LE connection (commands: client, connectle <bd_addr>, discoverspple <bd_addr>) i get ConnectionID equal to 1. Unfortunately reading RSSI gives error 0x02 (No connection?). After that I have created SPP connection (open <inquiry index> <port>) and tried to read RSSI again (ConnectionID was still equal to 1) and I got:
RSSI: -69 (ConnId = 1, HCI retval = 0) RSSI: -256 (ConnId = 1, HCI retval = 0, status = 0)
It seems to work now. So is the connection ID handled differently in BLE ? How to use this vendor specific command when only LE connection is active.
Regards,
Matthew