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

Sending number over ble with ble_nus_string_send

Hi! Can anyone help me send values of temperature over ble? I tried and it appears like this,Capturar.PNG.

I'm using the code on the examples, ble_peripheral\ble_app_uart and ble_central\ble_app_uart, to comunicate over ble and changed this function on ble_peripheral to send values of temperature when i request in central:

static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length){		
  if(p_data[0]=='?'){	

	uint8_t temp;
	uint32_t err_code;

    err_code = sd_temp_get(&temp);
	APP_ERROR_CHECK(err_code);
														
    temp = (temp / 4);
	printf("Temperature: %d \n", temp);
																											
	ble_nus_string_send(&m_nus, &temp, 2);
	}													
}									

The temperature is correct when i print on the side of the peripheral but when i send it over ble to central it appears in hexadecimal i think, as you can see on the image above. I'm using two nrf52, pca10040, s132 and i have SDK 12.2.0.

Thanks.

Parents
  • This kind of question seems to get asked more often than I could believe possible.

    The number has been sent as a 16 bit number. It's little endian so the first byte is the lower 8 bits, the second the higher 8 bits, so the number received is ... 0x0017

    which is 23 (16 + 7 == 23)

    Whatever you have on the other side just needs to convert that. If you want to send it as a string instead, convert it to a string on the client and send that instead.

Reply
  • This kind of question seems to get asked more often than I could believe possible.

    The number has been sent as a 16 bit number. It's little endian so the first byte is the lower 8 bits, the second the higher 8 bits, so the number received is ... 0x0017

    which is 23 (16 + 7 == 23)

    Whatever you have on the other side just needs to convert that. If you want to send it as a string instead, convert it to a string on the client and send that instead.

Children
Related