Go Down

Topic: WiFi.RSSI(); Not updating? (Read 3078 times) previous topic - next topic

Wi11turner

Hi all,

I am trying to read my wifi signal strength and display it as it updates.

I find that i can read the strength on start up of my board, but it will not update as i move away from my router or get closer.


Code: [Select]

#include <SPI.h>
#include <WiFi.h>

char ssid[] = ""; //  your network SSID (name)
char pass[] = "";    // your network password (use for WPA, or use as key for WEP)

WiFiServer server(12000);  //a higher port number given, not clashing with https

int status = WL_IDLE_STATUS;


void setup()
{
  Serial.begin(9600);                       //Begins serial communication with the board

    if (WiFi.status() == WL_NO_SHIELD)       // check for the presence of the shield:
    { 
    Serial.println("WiFi shield not present");
    while(true);
    }


  while ( status != WL_CONNECTED)       // attempt to connect to Wifi network:
    {   
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);     // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 
    delay(5000);                         // wait 5 seconds for connection:
    }
  }

void loop() {
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}






Can anyone spot what im doing wrong?

(Apologies for my hacked up code, it's from a larger program)


Many thanks

PaulS

You can add Serial.print() statements to the WiFi source, to see what is happening.

Wi11turner

Thanks for the reply PaulS

I have this in my original code: 
Code: [Select]
void loop() {
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


Is this what you mean?

PaulS

Quote
Is this what you mean?

No. I mean that you put similar statements in WiFi.cpp and wifi_drv.cpp, to learn what RSSI() is doing, and the functions it calls.

Wi11turner

Thanks for the prompt reply again.

I still do not understand why this doesn't work, or where to go with it.

Could you suggest somewhere to learn about this? Searching WiFi.cpp hasn't brought up any 'nice' examples.

Sorry for my incompetence, I am not experienced with this.

PaulS

Quote
Sorry for my incompetence, I am not experienced with this.

If you can't edit a library, and add
Serial.print("I got here...");
statements, or perhaps something just a bit more useful, then I don't see how you are going to use the RSSI information that you get, should you start getting correct information (assuming that you are not now getting correct information - a point I'm not willing to concede).

What makes you think that there is a problem? RSSI is not a measure of distance, so moving the receiver towards or away from the WiFi router is not necessarily going to cause a change in RSSI values.

Wi11turner

#6
Jan 05, 2013, 12:55 am Last Edit: Jan 05, 2013, 12:59 am by Wi11turner Reason: 1
Sorry I should have explained the reasoning beforehand.

I will transmit the signal strength to Processing, here I will produce a simple signal strength bar chart, similar to the ones you see on cell phones. Eventually this will go onto an android application.

I know my RSSI value is chancing since I am using an application on a android devise to show that the RSSI value is changing as I move physical locations.

zoomkat

You might want to put a second or so delay in the rssi reading loop, otherwise you may not be able to see what is being sent.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Wi11turner

Quote
You might want to put a second or so delay in the rssi reading loop,


I have tried this and I still see no update.

If i reposition the wifi sheild further away from the router it does show a signal change if i manually restart the board.

I still cannot get the RSSI read to update within the program.

PaulS

Quote
I still cannot get the RSSI read to update within the program.

Besides wishing, what are you doing?

Wi11turner

#10
Jan 05, 2013, 04:24 pm Last Edit: Jan 05, 2013, 04:29 pm by Wi11turner Reason: 1
The RSSI read does not update as i change physical locations from my router.

For example, the signal displayed in the serial monitor, from this code, does not change/update as i move a large distance away from the router (eg. 3 bricked rooms).

Code: [Select]

void loop() {
 long rssi = WiFi.RSSI();
 Serial.print("signal strength (RSSI):");
 Serial.print(rssi);
 Serial.println(" dBm");
 delay(500);
}


But when i manually reset my board and wait for a reconnection the RSSI updates to a new value, to a more realistic value.

I'm assuming the program I have written does not tell the wifi board to make a new reading?


In response too:
Quote
Besides wishing, what are you doing?

I am wishing that the kind arduino community might be able to point out my error :-).

Thanks for your time PaulS.

PaulS

Quote
I am wishing that the kind arduino community might be able to point out my error :-).

If there IS an error in your code, the only way to debug it is to modify the library to show what it is doing.

You seem unwilling to do that. I do not understand why.

zoomkat

you might want to search thru the below postings for similar issues and resolutions.

https://www.google.com/search?hl=en&as_q=rssi&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Farduino.cc%2Fforum%2F&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

huckleberry

#13
Apr 27, 2013, 02:44 am Last Edit: Apr 27, 2013, 02:47 am by huckleberry Reason: 1
I had the same problem, and while PaulS seems to think that updating the library is a piece of cake, I for one do not find it trivial. It calls 50 other files, and you're soon in a sticky and unwieldy situation. I mean, if it were so simple (like a hello world), wouldn't less people rely on libraries to get things done?

So sorry you had to endure his jabbings. Anyways, I found a workaround: add a "WiFi.begin(ssid, pass);" after (or before) assigning the rssi value in your loop.

void loop() {
long rssi = WiFi.RSSI();
 Serial.print("signal strength (RSSI):");
 Serial.println(rssi);

WiFi.begin(ssid, pass);
delay(1);
}


And for others with this problem, I am using a Leonardo board, with the WIFI shield model R3, a macbook running Arduino 1.0.4, and my blood type is A+.

Cheers.

liudr

In WiFi.cpp

Code: [Select]
int32_t WiFiClass::RSSI()
{
    return WiFiDrv::getCurrentRSSI();
}


In WiFiDrv.cpp

Code: [Select]
int32_t WiFiDrv::_networkRssi[WL_NETWORKS_LIST_MAXNUM] = { 0 };
int32_t WiFiDrv::getCurrentRSSI()
{
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;
}


I guess there is no way to know if RSSI is kept up to date inside the WiFi chip/firmware so Paul's "find that line in library" is not working here. This is my frustration too. I can only trace things down to this layer right above the WiFi chip firmware. I have no way of knowing what happens in there. Don't ask me to learn a whole new environment just to understand the firmware.

Go Up