microcontrollercontikitexas-instruments

Contiki Rime stack how to get the broadcasting ID in Example_Broadcast


I am working on the broadcasting example of contiki's Rime stack :

https://github.com/contiki-os/contiki/blob/master/examples/rime/example-broadcast.c

When receiving a broadcast I can easily read out the senders id:

broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
{
  printf("Sender: %d.%d\n", from->u8[0], from->u8[1]);
}

But how can I get "my"/current node's ID?

Any help appreciated


Solution

  • The local address in Contiki is stored in linkaddr_node_addr:

    #include "net/linkaddr.h"
    ...
    printf("Local: %d.%d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
    

    There is also another variable: uint16_t node_id, at least on most platforms. It is by default equal to linkaddr_node_addr.u8[0] + (linkaddr_node_addr.u8[1] << 8). Add #include "sys/node-id.h" for that.