0

I want to do a CoAP request to an Erbium REST mote in which I first ask information from another mote to use in the response.

For this I command the REST mote to send a UDP message to the other mote. This mote will return a response with the information. However this information is asynchronously received and I am unable to block the CoAP handler until this information has been received.

static void res_info_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
RESOURCE(res_info,
         "title=\"Getting info: ?len=0..\";rt=\"Text\"",
         res_info_handler,
         NULL,
         NULL,
         NULL);

static void
res_info_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
  send_to_mote("getInfo");

  //wait for the response: yield to other processes

  //if response has been received: continue
  response = info;

  REST.set_header_etag(response, (uint8_t *)&length, 1);
  REST.set_response_payload(response, buffer, length);
}

Data from the udp request is received in the tcpip_handler (which is repeatedly executed from the udp process)

static void
tcpip_handler(void)
{
  char *str;

  if(uip_newdata()) {
    str = uip_appdata;
    str[uip_datalen()] = '\0';
    printf("ER: DATA recv '%s'\n", str);
    info = str;
  }
}

Would anyone have an idea how I can achieve this?

Martin
  • 11
  • 2

1 Answers1

0

As Erbium is based on Contiki, the task mechanisms of Contiki apply; they are described in the Contiki wiki.

The gist is that where you want to yield to other processes, you can literally PROCESS_YIELD(); that will pause processing of that thread until you wake it up from your receive-handler by posting an event to it.

chrysn
  • 810
  • 6
  • 19