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

Time sync up

hello ,i am using sdk16 with nrf52852 DK  i can be able to get time using that nrf calendar example. Now i want to sync up the mobile time with Dk every time i connect with bluetooth we are developing our own customised app. My question is

1)if i get time from app how can i get that time and put that in nrf_cal_set_time function to make my clock run continuously?

2)i am using ble_app_uart example if anyone tells where would my timestamp from app comes in this example that would be helpful??

3)otherwise should i add new things to this example to get time??

thanks and regards

Manikandan V

  • Hi Manikandan

    I believe I already answered these questions in one of your other cases. 

    Can you confirm whether or not you got some progress?

    If you have more questions about this I suggest we continue the discussion here, to avoid the other case getting too long an confusing. 

    Best regards
    Torbjørn

  • hello  i am using android and developed an customised app and doing something like this is

    for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    {
    str[i]=p_evt->params.rx_data.p_data[i];

    strcpy(buf,str);

    uint8_t j=0;
    char *pch = strtok (buf,"- :");
    while (pch != NULL)
    {

    array[j]=pch;
    j=j+1;
    pch = strtok (NULL, "- :");
    }
    year=atoi(array[0]);
    month=atoi(array[1]);
    day=atoi(array[2]);
    hour=atoi(array[3]);
    minute=atoi(array[4]);
    second=atoi(array[5]);
    ....

    }

    note: i am sending the current time from app everytime i connect with bluetooth and getting the exact values in year,hour,...,seconds variable.

    but if  i call nrf_cal_set_time(..) in main to starts from 1970  but not with the time i sent

    my main looks like this

    int main();

    {

    //all init

    nrf_cal_set_time(year, month, day, hour, minute, second); 

    while(1)
    {

    length=sprintf(cal_string,"%s", nrf_cal_get_time_string(true)); 

    ble_nus_data_send(&m_nus,cal_string,&length,m_conn_handle);
    }

    }

    where should i call nrf_cal_set_time(..) in my program to make it run one time and start sending date and time from the time i sent.

    Thanks and regards

    Manikandan V

  • Hi

    My initial thought is that you seem to be over complicating things a little.

    Can't you just code year/month/day/hour/minute/second each into a separate byte without converting to and from ascii representation?

    Then you only need 6 bytes in total to represent a date and time update, and you can easily copy each byte from the rx_data.p_data buffer into the 6 variables (just remember to subtract 1970 from the year before sending it, and add it back here, since a single byte can't store numbers > 255).

    Best regards
    Torbjørn

  • okie i have done that now i have 6 variables from year to second how can i set time using these variables where should i call nrf_cal_set_time(year, month, day, hour, minute, second); this function to set the time and start my program with that particular time

    thanks and regards

    manikandan v

  • Hi Manikandan

    Can't you just run the nrf_cal_set_time(..) function in the nus_data_handler() function, when the data is received?

    Best regards
    Torbjørn

Related