This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPPLE demo, reading RSSI when low energy connection is established

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

  • Hi,

    When it comes to the command execution, it is the same.

  • HI,

    Thanks for response. So VS_Read_RSSI should just work for LE connections?

    SPP+LE>connectle 00183342A282
    Connection Request successful.
    
    SPP+LE>
    etLE_Connection_Complete with size 18.
       Status:       0x00.
       Role:         Master.
       Address Type: Public.
       BD_ADDR:      0x00183342A282.
    
    SPP+LE>
    etGATT_Connection_Device_Connection with size 12:
       Connection ID:   1.
       Connection Type: LE.
       Remote Device:   0x00183342A282.
       Connection MTU:  23.
    
    SPP+LE>
    Exchange MTU Response.
    Connection ID:   1.
    Transaction ID:  1.
    Connection Type: LE.
    BD_ADDR:         0x00183342A282.
    MTU:             50.
    

    For lines above I would expect status = 0. Unfortunately I get error -2 which means "no connection":

    RSSI: 0 (ConnId = 1, HCI retval = 0, status = 2)
    RSSI: 0 (ConnId = 1, HCI retval = -502)
    

    I should have added that I use CC256x based module (patch version 2.1) and latest Bluetopia stack. Any idea would be helpful.

  • Hi,

    That is strange.

    Can you try the stranded Send_HCI_Read_RSSI (0x1405) command from the spec

    OCF --> 0x0005
    OGF --> 0x05

    and see it it works

  • Hi,

    Send_HCI_Read_RSSI did not help. But I have found that GAP_LE_Query_Connection_Handle returns ID = 1025. I used this value as a parameter for both VS_Read_RSSI and HCI_Read_RSSI but I am still getting error no. 2.

  • Hi,

    Could you check the return you are getting for GAP_LE_Query_Connection_Handle? It looks the 1025 is the return for the Connection Handle Result and not the actual Connection Handle itself that needs to be used for HCI_Read_RSSI.

     

    Thanks,

    Stonestreet One.

  • Hi,

    after long break I have returned to this problem and, well, solved it. Not sure what I have messed up in SSPLEDemo but in my project HCI_Read_RSSI combined with GAP_LE_Query_Connection_Handle works very well. I do not want to leave this thread unanswered so here is some portion of code:

    int16_t GetRSSI (int8_t *rssi)
    {
    	Word_t ConnectionHandle, RetConnectionHandle;
    	Byte_t StatusResult;
    
    	int Result;
    
    	Result = GAP_LE_Query_Connection_Handle(BluetoothStackID, RemoteBD_ADDR, &ConnectionHandle);
    	if(Result < 0) {
    		return ERROR;
    	}
    
    	Result = HCI_Read_RSSI(BluetoothStackID, ConnectionHandle, &StatusResult, &RetConnectionHandle, (SByte_t*) rssi);
    	if(Result < 0) {
    		return ERROR;
    	}
    
    	if(StatusResult != HCI_ERROR_CODE_NO_ERROR) {
    		return ERROR;
    	}
    
    	return OK;
    }

    Best regards,
    Matthew