Difference between revisions of "RSS measurement"
(→Understanding the Code) |
|||
(35 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
== Introduction == | == Introduction == | ||
− | + | Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna. | |
+ | In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received. | ||
− | == RSS Measurement | + | A step-by-step description of the simulation process and the C source code can be found in the subsequent sections. |
+ | |||
+ | == RSS Measurement using Cooja Simulator == | ||
=== Step 1 === | === Step 1 === | ||
− | Create New Simulation | + | Run 'ant' to start Cooja. Create New Simulation and let us say we name our simulation as "RSS". |
+ | |||
+ | |||
[[File:RSS_1.png|center|800px]] | [[File:RSS_1.png|center|800px]] | ||
Line 17: | Line 22: | ||
=== Step 2 === | === Step 2 === | ||
− | + | Add motes to the simulation. Go to Motes-> Add motes-> Create a new mote type-> and select Sky Mote to be added to the network. | |
− | + | ||
+ | [[File:RSS_2.png|center|800px]] | ||
=== Step 3 === | === Step 3 === | ||
− | Browse the firmware. | + | Browse and select the firmware. |
− | + | ||
+ | '''Note''': You have to create a .c file for RSS measurement and the source code can be found in the next section. | ||
+ | |||
+ | [[File:RSS_3.png|center|800px]] | ||
=== Step 4 === | === Step 4 === | ||
Compile the firmware. | Compile the firmware. | ||
+ | |||
[[File:RSS_4.png|center|800px]] | [[File:RSS_4.png|center|800px]] | ||
− | |||
− | |||
=== Step 5 === | === Step 5 === | ||
− | Select number of | + | Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes. |
− | + | ||
− | + | ||
+ | '''Note''': We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver. | ||
+ | |||
+ | [[File:RSS_5.png|center|800px]] | ||
=== Step 6 === | === Step 6 === | ||
Start the simulation. | Start the simulation. | ||
+ | |||
[[File:RSS_6.png|center|800px]] | [[File:RSS_6.png|center|800px]] | ||
+ | === Step 7 === | ||
+ | The 'Mote Output' window gives real time information of the events occurring in the simulation process. | ||
+ | |||
+ | You can see the RSSI values for every packet received in the mote output window. These values are in '''dBm'''. | ||
− | |||
− | |||
[[File:RSS_7.png|center|800px]] | [[File:RSS_7.png|center|800px]] | ||
− | == Code == | + | == Source Code == |
<code><nowiki> | <code><nowiki> | ||
+ | <HEADER FILES> | ||
static struct collect_conn tc; | static struct collect_conn tc; | ||
− | |||
PROCESS(example_collect_process, "RSS Measurement"); | PROCESS(example_collect_process, "RSS Measurement"); | ||
AUTOSTART_PROCESSES(&example_collect_process); | AUTOSTART_PROCESSES(&example_collect_process); | ||
− | + | ||
− | static void | + | static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops) |
− | recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops) | + | |
{ | { | ||
static signed char rss; | static signed char rss; | ||
static signed char rss_val; | static signed char rss_val; | ||
static signed char rss_offset; | static signed char rss_offset; | ||
− | printf("Sink got message from %d.%d, seqno %d, hops %d: len %d '%s'\n", | + | 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_offset=-45; | |
− | + | rss=rss_val + rss_offset; | |
− | + | printf("RSSI of Last Packet Received is %d\n",rss); | |
− | + | ||
− | + | ||
− | printf("RSSI of Last Packet Received is %d\n",rss); | + | |
− | + | ||
} | } | ||
− | + | ||
static const struct collect_callbacks callbacks = { recv }; | static const struct collect_callbacks callbacks = { recv }; | ||
− | + | ||
PROCESS_THREAD(example_collect_process, ev, data) | PROCESS_THREAD(example_collect_process, ev, data) | ||
{ | { | ||
Line 90: | Line 95: | ||
collect_open(&tc, 130, COLLECT_ROUTER, &callbacks); | collect_open(&tc, 130, COLLECT_ROUTER, &callbacks); | ||
− | if(rimeaddr_node_addr.u8[0] == 1 && | + | if(rimeaddr_node_addr.u8[0] == 1 && rimeaddr_node_addr.u8[1] == 0) |
− | + | { | |
printf("I am sink\n"); | printf("I am sink\n"); | ||
collect_set_sink(&tc, 1); | collect_set_sink(&tc, 1); | ||
Line 100: | Line 105: | ||
PROCESS_WAIT_UNTIL(etimer_expired(&et)); | PROCESS_WAIT_UNTIL(etimer_expired(&et)); | ||
− | while(1) { | + | while(1) |
+ | { | ||
/* Send a packet every 1 seconds. */ | /* Send a packet every 1 seconds. */ | ||
− | if(etimer_expired(&periodic)) { | + | if(etimer_expired(&periodic)) |
+ | { | ||
etimer_set(&periodic, CLOCK_SECOND * 1 ); | etimer_set(&periodic, CLOCK_SECOND * 1 ); | ||
etimer_set(&et, random_rand() % (CLOCK_SECOND * 1)); | etimer_set(&et, random_rand() % (CLOCK_SECOND * 1)); | ||
Line 111: | Line 118: | ||
− | if(etimer_expired(&et)) { | + | if(etimer_expired(&et)) |
+ | { | ||
static rimeaddr_t oldparent; | static rimeaddr_t oldparent; | ||
const rimeaddr_t *parent; | const rimeaddr_t *parent; | ||
− | + | if(rimeaddr_node_addr.u8[0] != 1 ) | |
− | + | { | |
− | + | printf("Sending\n"); | |
− | + | packetbuf_clear(); | |
− | + | 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)) { | + | { |
− | + | 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); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
} | } | ||
Line 141: | Line 154: | ||
== Understanding the Code == | == Understanding the Code == | ||
− | + | The functions of some code snippets are mentioned below, | |
− | + | ||
+ | * <code> static const struct collect_callbacks callbacks = { recv };</code> | ||
− | + | callbacks = { recv } calls the recv() function when a packet is received. | |
− | + | ||
− | + | ||
− | + | * <code> collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);</code> | |
− | + | ||
+ | Opens a connection. | ||
− | |||
− | |||
+ | * <code> collect_set_sink(&tc, 1);</code> | ||
− | + | Sets the node as sink. Note that we are setting node 1.0 as the sink here. | |
− | + | ||
− | + | ||
+ | * <code> collect_send(&tc, 15);</code> | ||
− | + | Sends data through the link. | |
+ | |||
+ | * <code> etimer_set(&et, CLOCK_SECOND * 1);</code> | ||
+ | |||
+ | This will set the timer to repeat the iterations every 1 seconds. | ||
+ | |||
+ | |||
+ | * <code>if(rimeaddr_node_addr.u8[0] != 1 )</code> | ||
+ | |||
+ | This if condition will work only for the source nodes i.e. node id != 1. | ||
+ | |||
+ | |||
+ | To understand the calculations performed in '''recv()''' function, see page 49 at http://web.stanford.edu/class/cs244e/papers/cc2420.pdf | ||
+ | |||
+ | |||
+ | [[Contiki_tutorials | Back to Contiki Tutorials]] | ||
− | Edited by : Nitin | + | Edited by : Nitin, Samarth Pai |
− | + |
Latest revision as of 12:04, 7 October 2016
Contents
Introduction
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.
RSS Measurement using Cooja Simulator
Step 1
Run 'ant' to start Cooja. Create New Simulation and let us say we name our simulation as "RSS".
Step 2
Add motes to the simulation. Go to Motes-> Add motes-> Create a new mote type-> and select Sky Mote to be added to the network.
Step 3
Browse and select the firmware.
Note: You have to create a .c file for RSS measurement and the source code can be found in the next section.
Step 4
Compile the firmware.
Step 5
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.
Note: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.
Step 6
Start the simulation.
Step 7
The 'Mote Output' window gives real time information of the events occurring in the simulation process.
You can see the RSSI values for every packet received in the mote output window. These values are in dBm.
Source Code
<HEADER FILES>
static struct collect_conn tc;
PROCESS(example_collect_process, "RSS Measurement");
AUTOSTART_PROCESSES(&example_collect_process);
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_offset=-45;
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;
PROCESS_BEGIN();
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);
PROCESS_WAIT_UNTIL(etimer_expired(&et));
while(1)
{
/* Send a packet every 1 seconds. */
if(etimer_expired(&periodic))
{
etimer_set(&periodic, CLOCK_SECOND * 1 );
etimer_set(&et, random_rand() % (CLOCK_SECOND * 1));
}
PROCESS_WAIT_EVENT();
if(etimer_expired(&et))
{
static rimeaddr_t oldparent;
const rimeaddr_t *parent;
if(rimeaddr_node_addr.u8[0] != 1 )
{
printf("Sending\n");
packetbuf_clear();
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
PROCESS_END();
} //end of process thread
Understanding the Code
The functions of some code snippets are mentioned below,
-
static const struct collect_callbacks callbacks = { recv };
callbacks = { recv } calls the recv() function when a packet is received.
-
collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);
Opens a connection.
-
collect_set_sink(&tc, 1);
Sets the node as sink. Note that we are setting node 1.0 as the sink here.
-
collect_send(&tc, 15);
Sends data through the link.
-
etimer_set(&et, CLOCK_SECOND * 1);
This will set the timer to repeat the iterations every 1 seconds.
-
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, see page 49 at http://web.stanford.edu/class/cs244e/papers/cc2420.pdf
Edited by : Nitin, Samarth Pai