Pages: [1] 2   Go Down
Author Topic: WiFi.RSSI(); Not updating?  (Read 2095 times)
0 Members and 1 Guest are viewing this topic.
Derbyshire
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Derbyshire
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply PaulS

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

Is this what you mean?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Derbyshire
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Derbyshire
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 04, 2013, 06:59:47 pm by Wi11turner » Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8967
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Derbyshire
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I still cannot get the RSSI read to update within the program.
Besides wishing, what are you doing?
Logged

Derbyshire
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: January 05, 2013, 10:29:52 am by Wi11turner » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8967
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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=
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 26, 2013, 07:47:18 pm by huckleberry » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6944
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In WiFi.cpp

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

In WiFiDrv.cpp

Code:
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.
Logged


Pages: [1] 2   Go Up
Jump to: