This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Wrong read authorization reply

Hi

I'm having some trouble with the read authorization giving me weird reply values.

In my application, I'm using a custom service called "Light Control" consisting of two characteristics; one write-only called "Light Command" (UUID: xxxx0002-xx...) and one read-only called "Light Status" (UUID: xxxx0003-xx...). For testing purposes I've set it up so that if I write either 0x05 or 0x07 to "Light Command", then I should get the same value in return by reading "Light Status". This doesn't happen though, as illustrated by the pictures below.

image description

image description

As you can see, the "Light Status" value stays the same regardless of which value "Light Command" was written to.

Can someone please enlighten me (some pun intended) as to what I'm doing wrong?

I'm pretty sure the fault lies somewhere in this code: (i.e in the sd_ble_gatts_rw_authorize_reply parameter setup)

static void on_read(ble_lc_t * p_lc, ble_evt_t * p_ble_evt)
{
		uint8_t	update_data;
		ble_gatts_rw_authorize_reply_params_t	 reply_params;
		
		update_data = p_lc->data_handler_status(); 
	
		memset(&reply_params, 0, sizeof(reply_params));
	
		reply_params.type			       = BLE_GATTS_AUTHORIZE_TYPE_READ;
		reply_params.params.read.p_data    = &update_data;
		reply_params.params.read.len         = sizeof(update_data);
		reply_params.params.read.offset     = 0;
	
		sd_ble_gatts_rw_authorize_reply(p_lc->conn_handle, &reply_params);
}

void ble_lc_on_ble_event(ble_lc_t * p_lc, ble_evt_t * p_ble_evt)
{
	if ((p_lc == NULL) || (p_ble_evt == NULL))
  {
     return;
  }
	
	switch (p_ble_evt->header.evt_id)
	{
		case BLE_GAP_EVT_CONNECTED:
			on_connect(p_lc, p_ble_evt);
			break;
		
		case BLE_GAP_EVT_DISCONNECTED:
			on_disconnect(p_lc, p_ble_evt);
			break;
		
		case BLE_GATTS_EVT_WRITE:
			on_write(p_lc, p_ble_evt);
			break;
		
		case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
			on_read(p_lc, p_ble_evt);
			break;
		
		default:
			// Nothing needed
			break;		
	}
}

I'm saying this because I've run the code in the debugger, and in all instances the variable update_data is set correctly. That is, if 0x05 was written to "Light Command" then update_data is set to 0x05 and if 0x07 was written to "Light Command" then update_data is set to 0x07.

Parents Reply Children
Related