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

ble data transfer

Hi,

I am using the following statements for send a string data over BLE.

static uint8_t Name3[BLE_NUS_MAX_DATA_LEN]= "xxxxxxxx";
	err_code = ble_nus_string_send(&m_nus, Name3, 20);	
	if (err_code != NRF_ERROR_INVALID_STATE)
	{
		APP_ERROR_CHECK(err_code);
	}	

But I am unable to send integers and floating values. Is there a function where I can send non-string data variables via BLE.

Regards Siva

Parents
  • So assume you want to send a uint16_t value of say 10000. This is of course two bytes and you must assign each byte of value to each element of the array Name3. One fairly easy way to do this is bit masking and shifting. So do this:

    Name3[0] = (value & 0xFF00) >> 8;
    Name3[1] = (value & 0x00FF);
    

    Now say value was a unit32_t, which is 4 bytes long, then do this

    Name3[0] = (value & 0xFF000000) >> 24;
    Name3[1] = (value & 0x00FF0000) >> 16;
    Name3[2] = (value & 0x0000FF00) >> 8;
    Name3[3] = (value & 0x000000FF);
    
  • Actually, you might be right. I've just noticed my values never been larger than one byte so while it compiles fine and appears to work, what is happening is the value is being assigned to that array element and when putting in a value greater than one byte it is being lost.

Reply Children
No Data
Related