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

Send a float

I want to send a float as a value of a characteristic.

As I know is this all what I have to change to send a float...

float temperature;

uint16_t len = 20;

attr_char_value.init_len  = 4;
attr_char_value.init_offs = 0;
attr_char_value.max_len   = 4;
attr_char_value.p_value   = (uint8_t*)&temperature;

hvx_params.offset = 0;
hvx_params.p_len = &len;
hvx_params.p_data = (uint8_t*)&temperature;

But it doesnt work. I wont recieve any data.

Parents
  • Regarding the size, in your case "len" is the number of bytes you are sending, so set to 4. Regarding notification, there are two way of exchanging data between nRF51 and the host(for example android device). One is to change temperature inside nRF51 but the host won't know about it. In this case host has to read data periodically but you don't use sd_ble_gatts_hvx() in nRF51. Instead you update value by sd_ble_gatts_value_set(). Another way is to use sd_ble_gatts_hvx() in nRF51 and data will be sent automatically to the host so host doesn't need to read it. But host has to enable notification or indication of that characteristics before nRF51 send data.

Reply
  • Regarding the size, in your case "len" is the number of bytes you are sending, so set to 4. Regarding notification, there are two way of exchanging data between nRF51 and the host(for example android device). One is to change temperature inside nRF51 but the host won't know about it. In this case host has to read data periodically but you don't use sd_ble_gatts_hvx() in nRF51. Instead you update value by sd_ble_gatts_value_set(). Another way is to use sd_ble_gatts_hvx() in nRF51 and data will be sent automatically to the host so host doesn't need to read it. But host has to enable notification or indication of that characteristics before nRF51 send data.

Children
No Data
Related