2 Replies Latest reply on Feb 26, 2013 2:13 PM by jasonrc

    Issue with an app that calls sntp_get_time() periodically using a worker thread

      [WICED-SDK-2.2.1]

       

       

      I want to create a simple program that calls  sntp_get_time() periodically.

       

      I attempted to register a timed event, similarly to the UDP timed event which works fine.

       

       

      
      /* Register a function to process received UDP packets */
      
      wiced_rtos_register_timed_event( &process_udp_rx_event, WICED_NETWORKING_WORKER_THREAD, &process_received_udp_packet, UDP_CHECK_PERIOD, 0 );
      
      
      /* Register a function to update the time */
      
      wiced_rtos_register_timed_event( &process_ntp_event, WICED_NETWORKING_WORKER_THREAD, &process_ntp_time, TIME_UPDATE_PERIOD, 0 );
      
      

       

       

      The above timed event called the function below around 8 times and

       

      then stopped. If I commented out the UDP timed event it would run OK.

       

       

      Why doesnt this work?

        • 1. Re: Issue with an app that calls sntp_get_time() periodically using a worker thread
          For convenience purposes, WICED provides two worker threads dedicated to doing asynchronous work.

           

          One for networking activity (WICED_NETWORKING_WORKER_THREAD) and the other for non-networking activity (WICED_HARDWARE_IO_WORKER_THREAD).

           

           

          The network worker thread pulls function pointers out of a message queue and executes them in order of insertion.

           

          Functions that may take a long time to complete eg. sntp_get_time(), which has a five second receive timeout, can cause situations where the message queue fills with other jobs such as process_received_udp_packet().

           

           

          As a general rule you should NOT register a timed event at a rate faster than the longest time the function will take to execute/timeout.

           

          If you want to ensure responsiveness to multiple timed events, you can either setup shorter timeout periods for each event and call them regularly, or create additional worker threads.

           

           

          Is there a particular reason you need to poll the NTP server once a second?

           

          Once or twice a day should be sufficient assuming the microprocessor clock isnt too far out.
          • 2. Re: Issue with an app that calls sntp_get_time() periodically using a worker thread
            You are correct, I only need to execute the sntp_get_time() function one or twice a day.

             

            I was executing it more frequently just for test purposes.

             

            So it looks like I do in fact need to use the second worker thread.