How to get parameter from app_uart_ble?

Hi

I am using nrf52840 and I want to use nrf_calendar example with app_ble_uart, 

I am traying to send parameter from nrf toolbox uart app mobile 

but I have no idea how to do that

I tried to manipulate this part code for to set parameter clock ":nrf_cal_set_time(year, month, day, hour, minute, second); " as nrf_calendar example, but I cant

static void nus_data_handler(ble_nus_evt_t * p_evt) {
	if (p_evt->type == BLE_NUS_EVT_RX_DATA) {
	
		for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++) {
			err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
		}
	}

any advice how to get parameter app_ble_uart?

.

.

.

.

.

best regards

I was using google translate :p

Parents Reply Children
  • Hi Kazi

    thanks for you reply,

    I have a doubt

    Can I change  char timestring[]= "08,54,00,27,00,2022";  to char timestring[]= Varible char;?

    variable char  = NUS data :

    this part handling the data recived over NUS BLE

    I am traying to save data in a variable  get_time = p_evt->params.rx_data.p_data;

     declaration

    I can to print p_evt->params.rx_data.p_data and length also .

    printf("\r%s - %d\r\n",p_evt->params.rx_data.p_data,p_evt->params.rx_data.length);

    and using get_time I am traying to do this

      

    void reloj_init()
    {
    	nrf_cal_init();
    	uint32_t year, month, day, hour, minute, second;
    	
    	char timestring[]= get_time;	
        
        hour   =atoi(timestring);    // 1 - 24
        minute =atoi(timestring+3);  // 0 - 59
        second =atoi(timestring+6);  // 0 - 59
    		day    =atoi(timestring+9);	 // 1 - 31
    		month  =atoi(timestring+12); // 0 - 11
    		year   =atoi(timestring+15); // 1900 
    		
    		nrf_cal_set_time(year, month, day, hour, minute, second);
    }

    because I am thinking that the variable get_time = "09,15,00,27,00,2022" ,the data I sent over NUS.

    I guess.. xd

    what is wrong?

    I am beginner  sorry , I have a lot doubts

    best regards

  • Hi,

    You may try to create a char array and use the memcpy () function

    (For example // Copies "numBytes" bytes from address "from" to address "to"
    void * memcpy(void *to, const void *from, size_t numBytes);)

    to copy the NUS string to the array. 

    Best Regards,

    Kazi Afroza Sultana

  • HI

    yes, you right, I created a char array into nus_data_handler "arr[i]"

    static void nus_data_handler(ble_nus_evt_t * p_evt)// esta funcion recibe lo que se haya mandado por bluetooth
    {
        
    		
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
            
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
    							{   
                    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
    		---->   arr[i] = p_evt->params.rx_data.p_data[i];

    and I used atoi like your example 

    void data_update()
    {
    	uint32_t year, month, day, hour, minute, second;
    	
    		hour   =atoi(arr+2);    // 1 - 24
            minute =atoi(arr+5);  // 0 - 59
            second =atoi(arr+8);  // 0 - 59
    		day    =atoi(arr+11);	 // 1 - 31
    		month  =atoi(arr+14); // 0 - 11
    		year   =atoi(arr+17); // 1900 
    		
    	  nrf_cal_set_time(year, month, day, hour, minute, second);	
    		
    	  memset(arr,0,26);
    
    }

    now its works , i can to change the time over NUS

    thank you kazi

    best regards

Related