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
  • Hi JoanaBabo!

    If you want to send the temperature value as a string instead,
    you could try writing your code something like this:

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)  
    {     
      if(p_data[0]=='?')
      {   
    
      int32_t temp;
      uint8_t data[20]; 
      uint32_t err_code;
    
      err_code = sd_temp_get(&temp);
      APP_ERROR_CHECK(err_code);
    
      temp = (temp / 4);
      sprintf((char *)data, "Temperature: %d", temp); 
      printf("Temperature: %d \n", temp);
    
      ble_nus_string_send(&m_nus, data, sizeof(data));
      }                                                   
    }
    

    Let me know if that doesn't work out for you.

    Best regards,
    Joakim.

Reply
  • Hi JoanaBabo!

    If you want to send the temperature value as a string instead,
    you could try writing your code something like this:

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)  
    {     
      if(p_data[0]=='?')
      {   
    
      int32_t temp;
      uint8_t data[20]; 
      uint32_t err_code;
    
      err_code = sd_temp_get(&temp);
      APP_ERROR_CHECK(err_code);
    
      temp = (temp / 4);
      sprintf((char *)data, "Temperature: %d", temp); 
      printf("Temperature: %d \n", temp);
    
      ble_nus_string_send(&m_nus, data, sizeof(data));
      }                                                   
    }
    

    Let me know if that doesn't work out for you.

    Best regards,
    Joakim.

Children
Related