Custom ubus loop - handle commands/events

Hi all!

For a project I am writing my own ubus daemon with a custom ubus loop.
The idea is that my ubus main loop polls a chip via spi to check whether a message is received and acks back.
While polling I want to handle other ubus calls / commands. After handling commands I need to reset my chip into receiving mode.

I added a simple get_info command which just prints a (version) string.

My main looks like this:

int main(int argc, char **argv) {
  const char *ubus_socket = NULL;

  /* Configure SPI rate, DW3000 supports up to 38 MHz */

  ctx = ubus_connect(ubus_socket);
  if (!ctx) {
    fprintf(stderr, "Failed to connect to ubus\n");
    return -1;



  // uloop_run();
  printf("Starting ranging listen and respond loop..\n");


  return 0;

In my own loop I need to check whether there is a command "queried", because I otherwise would constantely reset my chip.

The function ubus_handle_event does work on the command queue.

My idea was something like this:

void ranging_responder_loop()
    while (1)

        printf("Waiting for Frame..\n");
        /* Poll for reception of a frame or error/timeout. */

        while (!((status_reg = dwt_read32bitreg(...)))
            // Check if there is a command pending!
            if ((list_empty(&(ctx->requests)) == false) || (list_empty(&(ctx->pending)) == false))
                printf("got command!\n");

My problem is now that in the ubus context requests and pending are always empty, so my event handling is never called. (I wasn't sure which one to use, both are not working)
I used the libubus header to search for the event queue.

What am I doing wrong ?
How do I check if there are events pending correctly ?

Thanks! :slight_smile: