<< Chapter < Page | Chapter >> Page > |
The experimental setup goes as follows. You will use to boards, a sender and a receiver. The sender continuously sends bursts of 100 messages, each containing a counter which increases from 1 to 100. Out of those 100 sent messages, the receiver may only receive 40. It will count the number of received messages until the counter reaches 100, or until the counter loops back to a smaller value. When this happens, the receiver outputs the number of received messages, i.e. the probability of the link.
At the same time as the receiver counts the number of the received messages, it calculates the average RSSI over those 100 messages, which it outputs togetherwith the link probability. Finally, to allow for the receiver to output these statistics (which takes some time), after each burst of 100 messages, the sender sends 20messages with counter set to 101.
To implement this:
source_code/iar_v4.11/lab_ezwsn.eww
with IAR. The project corresponding to this section is called
txrx_probability
. .P1IFG&= ~0x04;
by
P1IFG |= 0x04;
. This causes a continuous stream of messages. Power the newly programmed node on the battery pack and press the button; the red LED flashes.cat /dev/comx>probability.txt
. This logs the output in a file.XLaunch
. In Cygwin, type
export DISPLAY=127.0.0.1:0.0
.gnuplot
, then
plot "probability.txt" using 1:2
. This plots the probability as a function of the RSSI, make sure to obtain a graph similar to the one in the figure below.#include "mrfi.h"
uint8_t counter, num_received, bool_counting;int16_t cumulative_rssi;
mrfiPacket_t packet;void print_probability(int16_t cumulative_rssi, uint8_t number)
{char output[] = {" 000 0.00\n"};if (cumulative_rssi<0) {
output[0]='-';
cumulative_rssi=-cumulative_rssi;}
output[1]= '0'+((cumulative_rssi/100)%10);
output[2]= '0'+((cumulative_rssi/10)%10);
output[3]= '0'+ (cumulative_rssi%10);
output[5]= '0'+((number/100)%10);
output[7]= '0'+((number/10)%10);
output[8]= '0'+ (number%10);
TXString(output, (sizeof output)-1);}
int main(void){
BSP_Init();P1REN |= 0x04;
P1IE |= 0x04;MRFI_Init();
P3SEL |= 0x30;UCA0CTL1 = UCSSEL_2;
UCA0BR0 = 0x41;UCA0BR1 = 0x3;
UCA0MCTL = UCBRS_2;UCA0CTL1&= ~UCSWRST;
MRFI_WakeUp();MRFI_RxOn();
__bis_SR_register(GIE+LPM4_bits);}
void MRFI_RxCompleteISR(){
P1OUT ^= 0x02;MRFI_Receive(&packet);
counter = packet.frame[9];
if (counter==101) {if (bool_counting == 1) {
print_probability(cumulative_rssi/num_received,num_received);}
bool_counting=0;num_received=0;
cumulative_rssi=0;} else {
bool_counting=1;num_received++;
cumulative_rssi+=Mrfi_CalculateRssi(packet.rxMetrics[0]);
}}
#pragma vector=PORT1_VECTOR__interrupt void interrupt_button (void)
{P1IFG&= ~0x04;
P1OUT ^= 0x01;mrfiPacket_t packet;
packet.frame[0]=8+3;
for (counter=1;counter<101;counter++){
packet.frame[9]=counter;
MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);
}for (counter=0;counter<20;counter++){
packet.frame[9]=101;
MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);
}}
Some keys to understand the code:
packet.frame[0]
is the length field, which sets the payload length at 3 bytes (minimum accepted value).packet.frame[9]
is the first byte of the payload.bool_counting
indicates whether the statistics have already been printed out (without this semaphore, as there are 20 guard messages, the statistics would be printed out 20 times)As shown in hte figure below, link probability is closely correlated to RSSI. The theory tells us that, at very low RSSI, link probability is very close to 0; at very high RSSI it isclose to 1. Between those extremes, there is a linear slope, shown as an overlay in the figure below.
Notification Switch
Would you like to follow the 'Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500' conversation and receive update notifications?