Skip to content

Question: Is there a way to get the Wifi signal strength ? #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thereforeiam opened this issue Apr 27, 2015 · 29 comments
Closed

Question: Is there a way to get the Wifi signal strength ? #132

thereforeiam opened this issue Apr 27, 2015 · 29 comments

Comments

@thereforeiam
Copy link

In order to be able to diagnose connection problem I was wondering if it was possible to get the signal strength via the WiFi API.
I realise this is not available as part of the standard arduino lib, but GSM has something equivalent

@linagee
Copy link
Contributor

linagee commented Apr 29, 2015

Yes you can. You can do almost anything with this chip if you dive into their closed source libs. :-) (Its doing almost everything entirely in software.) I don't think you'd even need to go that far though. There appears to be some way that passive mode and the wifi scan are able to grab the RSSI. (You could probably even just use passive mode and only look at AP packets.)

@duncan-a
Copy link

Does anyone know the method for this?

I'm intending to have a 'connected' LED and it would be very useful to have
an indication of signal strength to accompany that...

On 29 April 2015 at 16:15, linagee [email protected] wrote:

Yes you can. You can do almost anything with this chip if you dive into
their closed source libs. :-) (Its doing almost everything entirely in
software.) I don't think you'd even need to go that far though. There
appears to be some way that passive mode and the wifi scan are able to grab
the RSSI. (You could probably even just use passive mode and only look at
AP packets.)


Reply to this email directly or view it on GitHub
#132 (comment).

@marvinroger
Copy link
Contributor

As far as I know, there is currently no way in the Espressif SDK to retrieve the RSSI to the current connected AP. But as @linagee pointed out, it is possible looking at the sources to get the RSSI after a wifi scan, here is a working example:

#include <Arduino.h>
#include <ESP8266WiFi.h>

const char* SSID = "YOUR_SSID";

// Return RSSI or 0 if target SSID not found
int32_t getRSSI(const char* target_ssid) {
  byte available_networks = WiFi.scanNetworks();

  for (int network = 0; network < available_networks; network++) {
    if (strcmp(WiFi.SSID(network), target_ssid) == 0) {
      return WiFi.RSSI(network);
    }
  }
  return 0;
}

void setup() {
  Serial.begin(115200);
}

void loop() {
  unsigned long before = millis();
  int32_t rssi = getRSSI(SSID);
  unsigned long after = millis();
  Serial.print("Signal strength: ");
  Serial.print(rssi);
  Serial.println("dBm");

  Serial.print("Took ");
  Serial.print(after - before);
  Serial.println("ms");
  delay(1000);
}

Outputting

Signal strength: -60dBm
Took 2133ms
Signal strength: -57dBm
Took 2133ms
Signal strength: -57dBm
Took 2128ms
Signal strength: -58dBm
Took 2132ms
Signal strength: -62dBm
Took 2132ms
Signal strength: -57dBm
Took 2132ms

This is far from clean and ideal, as:

  • It is not very bulletproof as it filters the networks by SSID, impossible to do now by mac address
  • It is blocking for around 2 sec, the time to do a wifi scan, which is a huge caveat for a single threaded system

But hey, it works!

@duncan-a
Copy link

duncan-a commented May 1, 2015

Marvin:
Thanks for that.
A two second blocking certainly less than ideal but a starting point is
always good to have at my level of comprehension.

On 1 May 2015 at 00:59, Marvin Roger [email protected] wrote:

As far as I know, there is currently no way in the Espressif SDK to
retrieve the RSSI to the current connected AP. But as @linagee
https://github.com/linagee pointed out, it is possible looking at the
sources to get the RSSI after a wifi scan, here is a working example:

#include <Arduino.h>
#include <ESP8266WiFi.h>
const char* SSID = "YOUR_SSID";
// Return RSSI or 0 if target SSID not foundint32_t getRSSI(const char* target_ssid) {
byte available_networks = WiFi.scanNetworks();

for (int network = 0; network < available_networks; network++) {
if (strcmp(WiFi.SSID(network), target_ssid) == 0) {
return WiFi.RSSI(network);
}
}
return 0;
}
void setup() {
Serial.begin(115200);
}
void loop() {
unsigned long before = millis();
int32_t rssi = getRSSI(SSID);
unsigned long after = millis();
Serial.print("Signal strength: ");
Serial.print(rssi);
Serial.println("dB");

Serial.print("Took ");
Serial.print(after - before);
Serial.println("ms");
delay(1000);
}

Outputting

Signal strength: -60dB
Took 2133ms
Signal strength: -57dB
Took 2133ms
Signal strength: -57dB
Took 2128ms
Signal strength: -58dB
Took 2132ms
Signal strength: -62dB
Took 2132ms
Signal strength: -57dB
Took 2132ms

This is far from clean and ideal, as:

  • It is not very bulletproof as it filters the networks by SSID,
    impossible to do now by mac address
  • It is blocking for around 2 sec, which is a huge caveat for a single
    threaded system

But hey, it works!


Reply to this email directly or view it on GitHub
#132 (comment).

@Links2004
Copy link
Collaborator

thx to latests SDK ist possible now.
see pull #325

@duncan-a
Copy link

Can somebody explain to those of us who are less 'techie' how to update the
ESP modules to the latest SDK so that we can use the new functionality???

Simple 'step by step' approach appreciated!!!

On 25 May 2015 at 12:33, Markus [email protected] wrote:

thx to latests SDK ist possible now.
see pull #325 #325


Reply to this email directly or view it on GitHub
#132 (comment).

@igrr
Copy link
Member

igrr commented May 25, 2015

@duncan-a
When the update is released, you will just need to open the Board Manager and click "Install" button for the ESP8266 core.

Clarification: updated package with the new SDK is not released yet. Still troubleshooting some bugs.

@duncan-a
Copy link

OK thanks - even I should be able to manage that!!!

Any idea when the update is likely to be released?

On 25 May 2015 at 12:51, Ivan Grokhotkov [email protected] wrote:

@duncan-a https://github.com/duncan-a
When the update is released, you will just need to open the Board Manager
and click "Install" button for the ESP8266 core.


Reply to this email directly or view it on GitHub
#132 (comment).

@Tugao
Copy link

Tugao commented Aug 11, 2015

Heyyyy
I am new with esp8266
I would like to get the name of ssid , the Signal strength and the mac address
is it possible ?
I can´t found how to get a mac address ( ap )

thanks

@Links2004
Copy link
Collaborator

you can use WiFi.getNetworkInfo() to get all at once or MAC only WiFi.BSSID()

bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);


@Tugao
Copy link

Tugao commented Aug 11, 2015

ooo my thanks
but, howe can I use this labarys in my project
I have others labrary liki this im my project, but
they dont work well

@Links2004
Copy link
Collaborator

its part of the ESP8266 project, you already have it.

#include <EPS8266WiFi.h>

and then use the functions

@Tugao
Copy link

Tugao commented Aug 11, 2015

Yes, needed to update my old library
so Now i go this information
one more time
thanks for open my eyes

I thought this command just uas possible whit at command

@Links2004
Copy link
Collaborator

at commands have noting to do with this project :)

@N0TB0T
Copy link

N0TB0T commented Oct 3, 2015

Maybe I get it wrong, but I'd have to pass about 8 arguments ot WiFi.getNetworkInfo(), so I'd have to scan the Network previously anyway?

@Links2004
Copy link
Collaborator

you can take a look here:

WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);

the arguments are pointer where the information will be stored.
the first is the index.

basic:
run WiFi.scanNetworks and then use WiFi.getNetworkInfo for all the entrys

@hb020
Copy link

hb020 commented Jan 30, 2016

For those looking for RSSI on the ESP8266's active WifI connection, This is one of the first topics that come up. But the explanations are about RSSI after a (rather time consuming) scan, after the remark "As far as I know, there is currently no way in the Espressif SDK to retrieve the RSSI to the current connected AP". Well, that is no longer true. One can get the RSSI of the active WiFi connection: WiFi.RSSI(). That's all that is needed.

@duncan-a
Copy link

Are you implying that this is available with a new version of the Expressif
SDK?

If so, for those of us who are not super techie, how does one update the
SDK?

On 30 January 2016 at 16:11, hb020 [email protected] wrote:

For those looking for RSSI on the ESP8266's active WifI connection, This
is one of the first topics that come up. But the explanations are about
RSSI after a (rather time consuming) scan, after the remark "As far as I
know, there is currently no way in the Espressif SDK to retrieve the RSSI
to the current connected AP". Well, that is no longer true. One can get the
RSSI of the active WiFi connection: WiFi.RSSI(). That's all that is needed.


Reply to this email directly or view it on GitHub
#132 (comment).

@marvinroger
Copy link
Contributor

The SDK is embedded, you don't have to download it yourself...

Just download the latest 2.1.0 (not sure it was implemented before), and when connected in STA do WiFi.RSSI() and you're good to go.

@hb020
Copy link

hb020 commented Jan 31, 2016

It is also in 2.0 (stable/master)

@gert3d
Copy link

gert3d commented Feb 4, 2016

@ marvinroger commented on 1 May 2015:

I used the code for a ESP-07(without any antenna) , (onboard antenna only), (external antenna only) and (both antenna's) but I do not see much difference in signal strength, all range between -76dBm and -87dBm, 2129ms.
However in a functional sketch retrieving NTP time I DO see a difference: no response without antenna's and a reliable response with whatever antenna configuration. So I wonder what is measured really.

@Messaoudi0
Copy link

Hello everybody
Already thank you for all that information, I would like to know if we can get the signal to noise ratio(SNR) and if possible, how?
Or just get the noise and then I will make the equation Signal / Noise.

Thank you

@bitnapper
Copy link

Like @Messaoudi0 I am also interested in getting the signal to noise ratio. I need it to get the geolocation with the mozilla location service api.

@tablatronix
Copy link
Contributor

Anyone even find if noise or SNR are available ?

@gicho
Copy link

gicho commented Dec 23, 2016 via email

@zavliju
Copy link

zavliju commented Jun 13, 2017

if (strcmp(WiFi.SSID(network), target_ssid) == 0) <-- cannot convert 'String' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'

Can I ask something? I've just try the code, but there is a problem with the datatype.
Thanks. :)

@marvinroger
Copy link
Contributor

Actually, you don't need that anymore. Just call WiFi.RSSI()

@byingtan
Copy link

I now going to carry out a project with esp8266 module 1 and arduino Uno to measure rssi received by the smartphone. I am confuse about the wiring between esp 8266 and arduino. Wish someone can give me some guidance.

@devyte
Copy link
Collaborator

devyte commented Aug 24, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests