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

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

     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) */
    
      err = setSystemMode();
      if (err) {
        LOG_ERR("System mode set:%d \n", err);
        return err;
      }
    
      err = enablePsm(false);
    
      if (err) {
        LOG_ERR("PSM not enabled \n");
        return err;
      }
    
      err = eDRXsetting(false);
    
      if (err) {
        LOG_ERR("eDRX not enabled \n");
        return err;
      }
    
      err = lte_lc_init_and_connect();
    
      if (err) {
        LOG_ERR("LTE link could not be established.\n");
        return err;
      } else {
    
        u8_radio_lte_conn_flag = true;
        LOG_INF("Connected to LTE network.\n");
      }
    #endif /* defined(CONFIG_LWM2M_CARRIER) */
    
    connected:
    
      if (RADIO_PSM_MODE == u8_Psm_eDrx_Status_flag) {
        err = lte_lc_psm_get(&reqTAU, &reqActiveTime);
        if (err < 0) {
          LOG_INF("Error reading PSM parameter: %d Errno: %d\n", err, errno);
        }
      }
    
      if (RADIO_EDRX_MODE == u8_Psm_eDrx_Status_flag) {
    
        err = readEdrxParameter(&NetWrkEdrx, &Pagingtw, &ReqEdrxVal);
        if (err < 0) {
          LOG_INF("Error reading eDrx parameter: %d,Errno: %d\n", err, errno);
        }
      }
    
    #endif /* defined(CONFIG_BSD_LIBRARY) */
      return 0;
    }

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

    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
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_NATIVE=n
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    CONFIG_LTE_PSM_REQ_RPTAU="00000011"
    CONFIG_LTE_PSM_REQ_RAT="00100001"
    CONFIG_LTE_PDP_CMD=y
    CONFIG_LTE_LOCK_BANDS=n
    CONFIG_LTE_LOCK_BAND_MASK="10000001000000001100"
    CONFIG_LTE_PDP_CONTEXT="0,\"IP\",\"default\""
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    
    # AT host library
    CONFIG_AT_HOST_LIBRARY=y
    #CONFIG_UART_INTERRUPT_DRIVEN=y
    
    # Stacks and heaps
    CONFIG_MAIN_STACK_SIZE=2048
    CONFIG_HEAP_MEM_POOL_SIZE=1024
    
    # Disable native network stack to save some memory
    CONFIG_NET_IPV4=y
    CONFIG_NET_IPV6=n
    CONFIG_NET_UDP=y
    CONFIG_NET_TCP=y
    
    ###gpio related###
    #CONFIG_GPIO=y
    
    ###UART CONFIGURATION###
    #Enables serial driver
    #CONFIG_SERIAL=y
    
    #Needed for enabling ISRs
    #CONFIG_UART_INTERRUPT_DRIVEN=y
    
    #UART RAM buffer allocation, see TXD.MAXCNT on nRF9160
    CONFIG_UART_0_NRF_TX_BUFFER_SIZE=1024
    CONFIG_UART_2_NRF_TX_BUFFER_SIZE=1024
    
    ###power management###
    CONFIG_DEVICE_POWER_MANAGEMENT=y
    
    ###RTOS###
    #enables polling
    CONFIG_POLL=y
    
    #PP---???
    #CONFIG_DYNAMIC_OBJECTS=y
    
    #enables ring buffer
    CONFIG_RING_BUFFER=y
    
    #this macro enabled for u8_t to work
    CONFIG_DEPRECATED_ZEPHYR_INT_TYPES=y
    
    
    #CONFIG_NRFX_UARTE=y
    #CONFIG_NRFX_UARTE0=y
    #CONFIG_NRFX_UARTE2=y
    
    
    CONFIG_ADC=y
    #CONFIG_ADC_0=y
    #CONFIG_ADC_NRFX_SAADC=y
    
    #SPI
    CONFIG_SPI=y
    CONFIG_SPI_3=y
    CONFIG_SPI_NRFX=y
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SPI_NOR=y
    
    
    #I2C
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_I2C_1=y
    
    
    
    #DebugLogs
    CONFIG_BOOT_BANNER=n
    ###################################
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    
    CONFIG_PRINTK=y
    CONFIG_CONSOLE=y
    
    CONFIG_LOG=y
    
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_IMMEDIATE=y
    
    CONFIG_SERIAL=y
    CONFIG_STDOUT_CONSOLE=y
    
    CONFIG_UART_CONSOLE=n
    CONFIG_RTT_CONSOLE=y
    
    

    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

  • Hi,

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

    How can i know that?

    I tried sending at%xtime=1, its just sending ok, nothing more than that, so how can i make sure that my SDR supports this?

    Best Regards

    Rajender

Related