Derbyshire
Offline
Newbie
Karma: 0
Posts: 33
|
 |
« on: January 04, 2013, 03:45:27 pm » |
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. #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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #1 on: January 04, 2013, 05:08:40 pm » |
You can add Serial.print() statements to the WiFi source, to see what is happening.
|
|
|
|
|
Logged
|
|
|
|
|
Derbyshire
Offline
Newbie
Karma: 0
Posts: 33
|
 |
« Reply #2 on: January 04, 2013, 05:27:07 pm » |
Thanks for the reply PaulS I have this in my original 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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #3 on: January 04, 2013, 05:33:32 pm » |
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
Newbie
Karma: 0
Posts: 33
|
 |
« Reply #4 on: January 04, 2013, 05:43:54 pm » |
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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #5 on: January 04, 2013, 06:32:30 pm » |
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
Newbie
Karma: 0
Posts: 33
|
 |
« Reply #6 on: January 04, 2013, 06:55:18 pm » |
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
Tesla Member
Karma: 50
Posts: 6540
Arduino rocks
|
 |
« Reply #7 on: January 04, 2013, 08:00:09 pm » |
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
|
|
|
|
|
Derbyshire
Offline
Newbie
Karma: 0
Posts: 33
|
 |
« Reply #8 on: January 05, 2013, 10:07:04 am » |
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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #9 on: January 05, 2013, 10:10:38 am » |
I still cannot get the RSSI read to update within the program. Besides wishing, what are you doing?
|
|
|
|
|
Logged
|
|
|
|
|
Derbyshire
Offline
Newbie
Karma: 0
Posts: 33
|
 |
« Reply #10 on: January 05, 2013, 10:24:18 am » |
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). 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: 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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #11 on: January 05, 2013, 10:58:40 am » |
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
Tesla Member
Karma: 50
Posts: 6540
Arduino rocks
|
 |
« Reply #12 on: January 05, 2013, 02:13:16 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #13 on: April 26, 2013, 07:44:49 pm » |
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
Faraday Member
Karma: 35
Posts: 5918
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #14 on: April 27, 2013, 04:40:02 pm » |
In WiFi.cpp int32_t WiFiClass::RSSI() { return WiFiDrv::getCurrentRSSI(); }
In WiFiDrv.cpp 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
|
|
|
|
|
|