RSS measurement

From Contiki
Revision as of 18:53, 22 November 2014 by Nitin (Talk | contribs) (Understanding the Code)

Jump to: navigation, search

Back to Contiki Tutorials


This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.

You can find the step by step simulation in the next section "RSS Measurement Program on Cooja" and you can find the C code in the subsequent section.

RSS Measurement Program on Cooja

Step 1

Create New Simulation on Cooja. Let's say we call our simulation as "RSS".

RSS 1.png

Step 2

Create Motes.

RSS 2.png

Step 3

Browse the firmware. Note: You can find the code later in this tutorial.

RSS 3.png

Step 4

Compile the firmware.

RSS 4.png

Step 5

Select number of new motes=2. Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.

RSS 5.png

Step 6

Start the simulation.

RSS 6.png

Step 7

You can see the RSSI value in the mote output window. These RSSI values are in dBm.

RSS 7.png



static struct collect_conn tc;

PROCESS(example_collect_process, "RSS Measurement");

static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)
  static signed char rss;
  static signed char rss_val;
  static signed char rss_offset;
  printf("Sink got message from %d.%d, seqno %d, hops %d: len %d '%s'\n",originator->u8[0], originator->u8[1],seqno, hops,packetbuf_datalen(),
         (char *)packetbuf_dataptr());
  rss_val = cc2420_last_rssi;
  rss=rss_val + rss_offset;
  printf("RSSI of Last Packet Received is %d\n",rss);

static const struct collect_callbacks callbacks = { recv };

PROCESS_THREAD(example_collect_process, ev, data)
  static struct etimer periodic;
  static struct etimer et;

  collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);

  if(rimeaddr_node_addr.u8[0] == 1 && rimeaddr_node_addr.u8[1] == 0) 
    printf("I am sink\n");
    collect_set_sink(&tc, 1);

  /* Allow some time for the network to settle. */
  etimer_set(&et, 120 * CLOCK_SECOND);


    /* Send a packet every 1 seconds. */
      etimer_set(&periodic, CLOCK_SECOND * 1 );
      etimer_set(&et, random_rand() % (CLOCK_SECOND * 1));


      static rimeaddr_t oldparent;
      const rimeaddr_t *parent;
      if(rimeaddr_node_addr.u8[0] != 1 )
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),"%s", "Fight On") + 1);
        collect_send(&tc, 15);

        parent = collect_parent(&tc);
        if(!rimeaddr_cmp(parent, &oldparent)) 
           if(!rimeaddr_cmp(&oldparent, &rimeaddr_null))
              printf("#L %d 0\n", oldparent.u8[0]);
           if(!rimeaddr_cmp(parent, &rimeaddr_null)) 
              printf("#L %d 1\n", parent->u8[0]);
           rimeaddr_copy(&oldparent, parent);

  } //end of while

} //end of process thread

Understanding the Code

1-static const struct collect_callbacks callbacks = { recv };

callbacks = { recv } calls the recv() function when a packet is received.

2-collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);

Opens a connection.

3-collect_set_sink(&tc, 1);

Sets the node as sink. Note that we are setting node 1.0 as the sink here.

4-collect_send(&tc, 15);

Sends data through the link.

5-etimer_set(&et, CLOCK_SECOND * 1);

This will set the timer to repeat the iterations every 1 seconds.

6-if(rimeaddr_node_addr.u8[0] != 1 )

This if condition will work only for the source nodes i.e. node id != 1.

To understand the calculations performed in recv() function, follow [1]

Back to Contiki Tutorials

Edited by : Nitin