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

Send own data using Multilink Peripheral Example ( more than uint8 e.g. uint32 )

Got it working.. forgot (didn't know) I had to change the attribute length as well

I am currently trying to figure out where/how to attach my measurements so they can later be requested by a central when in a connection (and for the time being with the nRF Master Control Panel on Android. Is the Android Master Control Panel able to do this (enable services)?)

I would like to send 2x byte, 1x int32, 1x uint32.

I am currently playing around with gatts_value but I am struggling with sending values other than uint8_t

	uint8_t temp_temp = 5;
	ble_gatts_value_t test_value;
	test_value.offset = 0;
	test_value.p_value = &temp_temp;
	test_value.len = sizeof(temp_temp);
	sd_ble_gatts_value_set	(m_conn_handle,m_char_handles.value_handle, &test_value);	

If I got e.g. a variable: int32_t cool_name and want to use that, how to do that? I found this Post and tried this:

	uint32_t temp_temp = hole_druck();
	ble_gatts_value_t test_value;
	test_value.len = 4;
	test_value.offset = 0;
	test_value.p_value = (uint8_t*)&temp_temp;	

But it did not work.

(To minimize current consumption the central shall later on be able to request these measurements every 4 seconds. And both shall turn their radios off in between. And the peripheral should based on the last request start a timer to get fresh measurements from the sensor. Is this the right way to go for this?)

  • Got it. Forgot to/Didn't know I had to change attributes length as well.

    ...
        attr.max_len   = 3;
    ...
        		uint8_t temp_temp[] = {0xAB, 0xCD, 0xEF};
        		ble_gatts_value_t test_value;
        		test_value.len = sizeof(uint8_t)*3;
        		test_value.offset = 0;
        		test_value.p_value = (uint8_t*)&temp_temp;		
        		sd_ble_gatts_value_set(m_conn_handle,m_char_handles.value_handle, &test_value);
    
Related