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

Recognise/Read new characteristic value

So I've got my device running, set up two services with some read and write characteristics and it all works like charm now.

But now I want to react to values written into some characteristics (change of parameters for sensors) and can't quite figure out how to recognise my server send sth. to my device.

I think I need to listen to an event coming up in the on_ble_evt()-Function? How do I now a value has changed and how can I react to it? Do I have to implement the Device Manager for this?

  • Found an answer in the deep web :) Call a function inside the ble_evt_dispatch and let it interpret the messages for you:

    void get_config(ble_evt_t * p_ble_evt)
    {	uint8_t *debug;
    	ble_uuid_t uuid;
    	char str[100];
    	if(p_ble_evt->header.evt_id == BLE_GATTS_EVT_WRITE)
    	{	
    		uuid = p_ble_evt->evt.gatts_evt.params.write.uuid;
    		debug = p_ble_evt->evt.gatts_evt.params.write.data;
    		
    		if (uuid.uuid == YOUR_CUSTOM_UUID)    // without BASE!
    			// do sth.
                       /* Some DEBUG */
    		sprintf(str,"Value of Input = %d Value of UUID = %d\n",*debug,uuid.uuid);
    		SEGGER_RTT_WriteString(0, str);
    	}	
    }
    
Related