cancel
Showing results for 
Search instead for 
Did you mean: 

BlueNRG: Not notified when attribute is written

occam25
Associate II

I have modified the BlueNRG sensor demo adding a new characteristic to turn on/off a LED. I want to be notified when the client (the smartphone) sends data so I can check the written value to change the LED status accordinly.

I have tried many options but I am not being notified for writes, only for reads.

This is the characteristic added (just bellow de humidity characteristic):

COPY_LED_CHAR_UUID(uuid);
 ret =  aci_gatt_add_char(envSensServHandle, 
    	 UUID_TYPE_128, 
    	uuid, 
 	2,
 	CHAR_PROP_WRITE | CHAR_PROP_WRITE_WITHOUT_RESP,
	ATTR_PERMISSION_NONE, 
    	GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP | GATT_NOTIFY_ATTRIBUTE_WRITE,
 	16, 
    	0, 
   	&ledCharHandle);
    if (ret != BLE_STATUS_SUCCESS) goto fail;
 
    charFormat.format = FORMAT_UINT16;
    charFormat.exp = -1;
    charFormat.unit = UNIT_UNITLESS;
    charFormat.name_space = 0;
    charFormat.desc = 0;
 
    uuid16 = CHAR_FORMAT_DESC_UUID;
 
    ret = aci_gatt_add_char_desc(envSensServHandle,
    				 ledCharHandle,
                                 UUID_TYPE_16,
                                 (uint8_t *)&uuid16,
                                 7,
                                 7,
                                 (void *)&charFormat,
                                 ATTR_PERMISSION_NONE,
				 ATTR_PERMISSION_NONE, 
				 ATTR_ACCESS_WRITE_REQ_ONLY, 
                                 16,
                                 FALSE,
                                 &descHandle);
    if (ret != BLE_STATUS_SUCCESS) goto fail;

The return value is BLE_STATUS_SUCCESS

Then, in the user_notify callback, I add the EVT_BLUE_GATT_WRITE_PERMIT_REQ event but it is never called.

  case EVT_VENDOR:
	{
		evt_blue_aci *blue_evt = (void*)event_pckt->data;
		switch(blue_evt->ecode){
		case EVT_BLUE_GATT_READ_PERMIT_REQ:
		{
			evt_gatt_read_permit_req *pr = (void*)blue_evt->data;
			Read_Request_CB(pr->attr_handle);
			break;
		}
		// ADDED THE WRITE REQUEST NOTIFICATION
		case EVT_BLUE_GATT_WRITE_PERMIT_REQ:
		{
			evt_gatt_write_permit_req *pr = (void *)blue_evt->data;
			Write_Request_CB(pr);
			break;
		}
		}
	}

Am I missing something? do I need to do anything else in order to get the write notifications? (read notifications work perfectly)

I have been stuck with this for a long time, any help will be appreciated!

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
occam25
Associate II

Just in case it is useful to someone, It turned out that the code is ok and the problem was in the smartphone app. In app inventor. I was using the writeBytes call but it doesn't work properly. After changing to writeStrings the write notification worked like a charm

View solution in original post

2 REPLIES 2
occam25
Associate II

Just in case it is useful to someone, It turned out that the code is ok and the problem was in the smartphone app. In app inventor. I was using the writeBytes call but it doesn't work properly. After changing to writeStrings the write notification worked like a charm

Avan .12
Associate III

Excellent! Thank you!