Go Down

Topic: Increase rate/frequency of obtaining RSSI values using WiFiShield (Read 48 times) previous topic - next topic

EnAk

Hi people,

my goal is to get RSSI values from an AP using an Arduino Leonardo + WiFiShield. The desired frequency would be ideally something around 100 fresh RSSI values per second of one particular AP.

The problem so far is that I only get new, fresh RSSI values every 2-3 seconds.
I have already used several examples and methods to obtain RSSI values in the hope to get higher frequencies, but non helped so far.

Here a short history of my work so far:
1) Used Examples -> WiFiShield -> ScanNetworks: Scans all APs in range and prints out several infos about each in a nice way.
It got me thinking that maybe scanning for all APs and printing all infos might be slowing down the whole process (As in C where a lot of printing to console can significantly slow down processing speed).

2) Modified 1) by reducing the output to one AP only. I connected to the desired AP with SSID+PASS.
NO improvement!
Basically the code is this:

Code: [Select]
#include <SPI.h>
#include <WiFi.h>

//SSID of your network
char ssid[] = "test-wifi";
//password of your WPA Network
char pass[] = "test-pass";

void setup()
{
 WiFi.begin(ssid, pass);

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
   // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("RSSI:");
  Serial.println(rssi);
  }
}

void loop ()
{
 WiFi.begin(ssid, pass);
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
   // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("RSSI:");
  Serial.println(rssi);
  }
}


3) Modified the above code further by deleting reconnection within the loop (i.e. WiFi.begin(ssid,pass);). I realised that WiFi.RSSI() is only saved once on connection and is NOT updated afterwards. So I found this hint on the internet modifying the function getCurrentRSSI() in wifi_drv.cpp:

Code: [Select]
int32_t WiFiDrv::getCurrentRSSI()
{
startScanNetworks(); //MOD: <-This is all I added! : Source: http://forum.arduino.cc/index.php?topic=140764.15 by n8sbug TODO: DOES NOT CHANGE scanNetwork() delay!!!! :/
WAIT_FOR_SLAVE_SELECT();

    // Send Command
    SpiDrv::sendCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1);

    uint8_t _dummy = DUMMY_DATA;
    SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);

    //Wait the reply elaboration
    SpiDrv::waitForSlaveReady();

    // Wait for reply
    uint8_t _dataLen = 0;
    int32_t rssi = 0;
    SpiDrv::waitResponseCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&rssi, &_dataLen);

    SpiDrv::spiSlaveDeselect();

    return rssi;
}


Still NO improvement at all!

4) By narrowing down the sub-function which causes the 2-3Seconds delay I figured out that the function scanNetworks() is the "troublemaker". So I modified this function:

Code: [Select]
int8_t WiFiClass::scanNetworks()
{
uint8_t attempts = 100; //MOD: reduced the #attempts to 1 (orig. 10)
uint8_t numOfNetworks = 0;

if (WiFiDrv::startScanNetworks() == WL_FAILURE)
return WL_FAILURE;
  do
  {
  delay(50); //MOD: reduced/deleted for faster RSSI scanning (orig. 2000 [ms])
Serial.print("getScanNetworks() starting now. #");//MOD: Debug Information (To Be deleted later)
Serial.println(101-attempts);
  numOfNetworks = WiFiDrv::getScanNetworks();
  }
while (( numOfNetworks == 0)&&(--attempts>0));
return numOfNetworks;
}


NOTE: The Serial.print() functions simply print out the number of iterations within the loop before the function getScanNetworks() is complete. I did this to determine the processing time. It takes around 25 iterations before a fresh set of RSSI values is returned.
Bottom line: Still NO improvement!

5) So i took it one lever deeper, checking out the function WiFi.getScanNetworks() in wifi_drv.cpp.
This calls only sub function on a lower level, all SPI related and which can be found in spi_drv.cpp.
I even checked these sub-sub-function in spi_drv.cpp. But I can only find any possible improvements, i.e. methods to reduce the delay / improve the RSSI scanning frequency.


My current status: I dove in several levels deep into the library to try to improve the RSSI scanning frequency without any improvement so far. It seems to me, that I have to dig deeper (SPI lever, driver level) to *maybe* be able to improve the performance.

So my questions are: Is it even possible to increase the frequency of obtaining RSSI values? Do I have to modify the SPI drivers to achieve this (an area I have absolutely no knowledge about yet so far)?
Or is it impossible due to hardware restrictions, e.g. the communication between the Arduino board and the WifFShield basically takes this time for some hardware reasons?

Anyone has any ideas/knowledge about this?
Any help is highly appreciated :)


Cheers,
EnAk


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy