0

I want to settle a timer and check it if it's expired in the next invocation of the function coap_send_transaction(). How can I do that?


    PROCESS_THREAD(example_process, ev, data){

       static struct etimer et;

       PROCESS_BEGIN();

       while (1) {
         etimer_set(&et, CLOCK_SECOND); /* Set the timer to 1 second. */
         PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
         printf("the timer is expired!\n");
       }

       PROCESS_END();
    }

    void coap_send_transaction(coap_transaction_t *t) { 
      
       process_start(&example_process, NULL);
       if etimer_expired(&et) { 
         // do something 
         // how can I do this?
       }
    }
bijoy26
  • 133
  • 9
  • What exactly do you want to do? There is much wrong with this code: where is `coap_send_transaction` function called from? you cannot access a function variable (even static from another function like this). Please provide [a minmal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your problem. – Simon Doppler Jun 14 '21 at 12:31
  • Yes It's called from another file that's not the probleme the probleme is when I call this function I need to lanch a timer and check if it's expired – amine baiche Jun 14 '21 at 13:36
  • Does this code compile? It doesn't seem to be able to do so, since the `et` variable is not defined in `coap_send_transaction`. – Simon Doppler Jun 14 '21 at 14:03
  • yes ! That's where I'm stuck because I need to call it in the coap_send_transaction function .. do you have any Idea on how I could have do so ? – amine baiche Jun 14 '21 at 14:16
  • You can declare the timer outside the function, as a global variable (I strongly recommend using a file-scoped with `static`) like in [this example](http://contiki.sourceforge.net/docs/2.6/a00002.html). – Simon Doppler Jun 15 '21 at 08:08

0 Answers0