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 Reply Children
  • My apologies. I forgot to add:

    CONFIG_LTE_AUTO_INIT_AND_CONNECT=y

     

    Kind regards,

    Håkon

  • Hi,

    after adding "CONFIG_LTE_AUTO_INIT_AND_CONNECT=y" my prj.conf file looks like this.

    # General config
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    CONFIG_SERIAL=n
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=1024
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # SNTP
    CONFIG_SNTP=y
    
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=y

    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?

  • 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

Related