Time from NTP server

Hi,

Im using nrf9160 based custom board, nrf sdk 1.5.1.

I want to get the time from NTP servers, for that i connected to CATM1 n/w, connected to NTP server using UDP Protocol, but im not understanding what is the request i should make for NTP server to get present EPOCH, 

Please share any example if available.

i have tried sntp_client example (zephyr/samples/net/sockets/sntp_client) but when i run my code its directly going into fault_s.S after spm_jump() function.

Best Regards

Rajender

Parents
  • Hi,

     

    You have two options for fetching NTP:

    * Use the DATE_TIME library: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.0/nrf/libraries/others/date_time.html?highlight=date_time

    You can find a reference implementation in asset_tracker (look at "date_time" references): https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/applications/asset_tracker/src/main.c

    * Use SNTP directly, by adjusting the configuration.

    Replace the sntp_client/prj.conf with these lines: 

    https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/samples/nrf9160/udp/prj.conf#L7-L29

    Then set the IP to the ntp server here: 

    https://github.com/nrfconnect/sdk-zephyr/blob/master/samples/net/sockets/sntp_client/src/config.h#L17-L19

    example: ntp.uio.no resolves to ipv4 address "129.240.2.6"

    i have tried sntp_client example (zephyr/samples/net/sockets/sntp_client) but when i run my code its directly going into fault_s.S after spm_jump() function.

    This is due to the default configuration of the zephyr samples, where they assume native network. You have to adjust the configuration as mentioned above.

     

    Kind regards,

    Håkon

  • Hi,

    I have tried again, but now its getting error as "Failed to send over UDP socket -1"

  • Hi,

     

    Rajender said:

    In this example i haven't seen any network connectivity code, so where i can find the same, and how i can check my IP address after network connection.

    Now my Control not even entering into src/main file, may be its waiting for the Connectivity, so how can i check that?

    When CONFIG_LTE_AUTO_INIT_AND_CONNECT=y is set, it will wait in the lte_lc driver on boot-up before main is entered. Once main is entered, the link shall be up and running.

     

    Rajender said:
    In this example i haven't seen any network connectivity code, so where i can find the same, and how i can check my IP address after network connection.

     You can use this library to obtain this information:

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.0/nrf/libraries/modem/modem_info.html

    but then I would also recommend that you look at date_time library as well, which I linked to in my former post.

     

    Kind regards,

    Håkon

  • Hi,

    Now i can get the time from ntp server (time1.google.com) using sntp, but i want to get the time from at%xtime=1 also,

    I am sending this %xtime command after network connected and got ip address, but still im getting nothing but "OK" as a response, what would be the reason for this?

    Best Regards

    Rajender

  • Hi,

     

    Rajender said:

    Now i can get the time from ntp server (time1.google.com) using sntp, but i want to get the time from at%xtime=1 also,

    I am sending this %xtime command after network connected and got ip address, but still im getting nothing but "OK" as a response, what would be the reason for this?

    I'm glad to hear that you got ntp running.

    The %XTIME enables a notification, so it is important that you enable this notification early in the process.

    This can require that you enable the notification prior to connecting to the modem, ie. by setting CONFIG_LTE_AUTO_INIT_AND_CONNECT=n in your prj.conf and connecting to the network in main, something similar to this:

    https://github.com/nrfconnect/sdk-nrf/blob/v1.7.0/samples/nrf9160/mqtt_simple/src/main.c#L506-L545

     

    Kind regards,

    Håkon

  • Hi,

    I was connecting the network through main only, and please take a look at my network connecting function.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    int nRF_Radio_configure(void) {
    int err = 0;
    int reqTAU, reqActiveTime;
    float NetWrkEdrx = 0.0, Pagingtw = 0.0, ReqEdrxVal = 0.0;
    #if defined(CONFIG_BSD_LIBRARY)
    if (IS_ENABLED(CONFIG_LTE_AUTO_INIT_AND_CONNECT)) {
    /* Do nothing, modem is already turned on */
    /* and connected */
    goto connected;
    }
    LOG_INF("Connecting to LTE network.");
    LOG_INF("This may take several minutes.");
    #if defined(CONFIG_LWM2M_CARRIER)
    /* Wait for the LWM2M carrier library to configure the */
    /* modem and set up the LTE connection. */
    k_sem_take(&lte_connected, K_FOREVER);
    #else /* defined(CONFIG_LWM2M_CARRIER) */
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    this is my prj file, here i already done this, CONFIG_LTE_AUTO_INIT_AND_CONNECT=n.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    CONFIG_GPIO=n
    CONFIG_GPIO_NRFX=y
    CONFIG_GPIO_NRF_P0=y
    CONFIG_NRFX_GPIOTE=y
    CONFIG_NRFX_RTC=y
    CONFIG_NRFX_RTC0=y
    CONFIG_NRFX_RTC1=y
    CONFIG_NRFX_RTC2=y
    CONFIG_UART_ASYNC_API=y
    CONFIG_NEWLIB_LIBC=y
    #######################################
    # SNTP
    CONFIG_SNTP=y
    # enable to use thread names
    CONFIG_THREAD_NAME=y
    # Network
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    note: Iam not on actual catm1 network, i am connecting through SDR(simulation based n/w station).

  • Hi,

     

    Rajender said:
    note: Iam not on actual catm1 network, i am connecting through SDR(simulation based n/w station).

    The network will provide the time using XTIME. Does your SDR support this?

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Rajender said:
    note: Iam not on actual catm1 network, i am connecting through SDR(simulation based n/w station).

    The network will provide the time using XTIME. Does your SDR support this?

     

    Kind regards,

    Håkon

Children