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
  • First of all you are adding characteristic with exact size 4. It means that you have to set len = 4 while sending data. But your original problem most likely in the fact that the host didn't enable notification for that characteristic after connection and before you send data by sd_ble_gatts_hvx()

  • Oh very interesting! I didnt know that!! So there are two ways to send information from nRF51 to host. One way is to recieve a READ from the host. In this case the host reads the value of the Characterstic. The value of the characteristic will only be changed if I set a new value with sd_ble_gatts_value_set().

    But there is another way if I want that the value of the characteristic is automatically updated. The nRF51 will send the value of the Characteristic all the time. But the host will only recieve the value of the characteristic when the nRF51 recieves a notification or indication from the host.

    Do I understand something wrong?

Reply
  • Oh very interesting! I didnt know that!! So there are two ways to send information from nRF51 to host. One way is to recieve a READ from the host. In this case the host reads the value of the Characterstic. The value of the characteristic will only be changed if I set a new value with sd_ble_gatts_value_set().

    But there is another way if I want that the value of the characteristic is automatically updated. The nRF51 will send the value of the Characteristic all the time. But the host will only recieve the value of the characteristic when the nRF51 recieves a notification or indication from the host.

    Do I understand something wrong?

Children
No Data
Related