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

Parents
  • 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

Reply Children
  • 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

  • 1)no if i call it there its starts running from 1970 not with the date and time which i have set so what should i do??

    2) on a seprate note i have other question 

    I want to set the BLE connection interval via BLE  command using an customised app. what i want to do is this 

    #define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS)

    #define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS)

    if i send 10 and 50 through bluetooth my program should run with 10 as min and 50 .

    I have tried sending  two numbers and setting that numbers to two variables and placed it there instead of 20 and 75 but that seems to be not working.

    1)is it possible to do this?

    2)possible means how can i do that

    Thanks & Regards 

    Manikandan V

  • Hi Manikandan

    1) That is odd. I just did my own test, and I have no issue setting the time in the nus data handler. 

    Maybe you can take a look at my example and see if you are doing it differently?

    2604.ble_app_uart_calendar.zip

    2) In a Bluetooth connection the connection parameters is normally dictated by the central device, but the peripheral can request a change to the parameters. 

    In the standard BLE examples this is facilitated by the ble_conn_params module, which allows you to request different connection parameters by calling the ble_conn_params_change_conn_params(..) function, as described here.

    If you want this to happen as a response to a packet sent from Be aware that it is up to the central to decide if it accepts these parameters or not. For instance most smart phones have some limits on which connection parameters they will accept. 

    Best regards
    Torbjørn

  • thanks it worked kindly check my new ticket i have another doubt.

Related