RSSI Signal Level Tutorial

From openPicus Wiki
Jump to: navigation, search

Contents

What you are going to learn

You'll learn how to use the new Flyport IDE 2.4 libraries to gather information, specifically signal level, about the station you are connected to.

Disclaimer

The Signal Level information made available by the Microchip Transceiver is not metrically accurate, meaning it does not provide any real scientifically valid measure. You could expect dB/m or something like that, unfortunately this is not the case. The measure is absolute but relative to the Flyport transceiver, so there is a range from 0 to 128 which means no reception to maximum possible reception.

Code

Explanation

The code proposed is really simple: first the measure is triggered, then some kind of wait is required during the measuring period, and finally the result is fetched.

To avoid blocking during measuring, the library provides 3 functions:

  1. void RSSIUpdate()
  2. BYTE RSSIStatus()
  3. int RSSIValue()

Function 1 starts the measuring.
Function 2 returns a value corresponding to the status of the measuring

  • RSSI_VALID: Value is correct and ready to be read
  • RSSI_IN_PROGRESS: RSSI scan is in progress
  • RSSI_ERROR: Error occurred in RSSI scanning
  • RSSI_NOT_VALID: Value read is not valid, try again
  • RSSI_NO_CONN: Wi-fi is not connected, RSSI scan can not performed

Function 3 fetches the actual measured value.

The whole cose is nothing hugely different from just calling the three above mentioned functions in sequence: to get a better usability there is a delay between results, and a check on the errors to print meaningful messages. Nothing more.

Source

Here is the entire taskFlyport.c

#include "taskFlyport.h"
#include "grovelib.h"
 
void FlyportTask()
{	
	char msg[50];
	long counter=0;
 
	// Connection to Network
	WFConnect(WF_DEFAULT);
	while (WFStatus != CONNECTED);
 
	UARTWrite(1,"Flyport connected... hello world!\r\n");
	vTaskDelay(200);
 
	while(1)
	{
		UARTWrite(1,"\nInitiating RSSI scan");
		// Actually start the measure
		RSSIUpdate();
 
		//wait while the measure is incomplete
		while( RSSIStatus()==RSSI_IN_PROGRESS )
		{
			vTaskDelay(20);			
			UARTWrite(1,".");
		}
		UARTWrite(1,"\n");
 
		// when the measure is complete, do something with the result
		switch(RSSIStatus())
		{
			// if the result is valid then print it
			case RSSI_VALID:
				sprintf(msg,"Signal level: %d\n",RSSIValue());
				UARTWrite(1,msg);
				break;
 
			// generic error
			case RSSI_ERROR:
				UARTWrite(1,"Error during scan\n");
				break;
 
			// something happened and the measure is invalid
			case RSSI_NOT_VALID:
				UARTWrite(1,"Invalid measure, please try again\n");
				break;
 
			// the WF module is not connected
			case RSSI_NO_CONN:
				UARTWrite(1,"WF not connected\n");
				break;
 
		}
		vTaskDelay(1000);
	}
}
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox