{"id":8405,"date":"2023-04-07T09:30:54","date_gmt":"2023-04-07T07:30:54","guid":{"rendered":"https:\/\/deepbluembedded.com\/?p=8405"},"modified":"2023-08-17T23:50:32","modified_gmt":"2023-08-17T20:50:32","slug":"esp32-wifi-signal-strength-arduino-rssi","status":"publish","type":"post","link":"https:\/\/deepbluembedded.com\/esp32-wifi-signal-strength-arduino-rssi\/","title":{"rendered":"Get ESP32 WiFi Signal Strength (Arduino) & RSSI Value"},"content":{"rendered":"\n
In this tutorial, you’ll learn how to find the ESP32 WiFi signal strength of a specific network. And we’ll discuss how to get the RSSI (Received Signal Strength Indicator) value and use it to judge the WiFi signal strength.<\/p>\n\n\n\n
Before proceeding with this tutorial, you should have installed the ESP32 Arduino Core in your Arduino IDE to be able to compile and build projects for ESP32 in Arduino IDE. Follow the tutorial below to get started if you haven’t done that already.<\/p>\n\n\n\n
If you’re just starting with ESP32, it’s highly recommended to begin with the following tutorial to kickstart your journey with ESP32 microcontrollers. Then, go to the second link which directs you to the main page for ESP32 Tutorials Series, where you’ll find all ESP32 tutorials ordered and categorized in a logical way that guarantees you systematic progress in learning ESP32 programming and IoT.<\/p>\n\n\n\n
For checking the WiFi signal strength of a specific network with ESP32, we’ll be using the WiFi.h library which is built-in already in Arduino core. We just need to include the library.<\/p>\n\n\n\n
There is a provided example for ESP32 WiFi network scanning that can also be used to get the WiFi signal strength for each of the nearby WiFi networks. Open File<\/strong> > Examples<\/strong> > WiFi <\/strong>> WiFiScan<\/strong> sketch.<\/p>\n\n\n\n Here is the full code listing of this example:<\/p>\n\n\n\n <\/p>\n\n\n\n This example is particularly useful when you try to connect to a nearby network but keeps failing. This WiFi scanner example will show you the signal strength of each WiFi network within the ESP32 range. The RSSI<\/strong> (Received Signal Strength Indicator) is what you’re looking for if you’d like to know the signal strength of each nearby network.<\/p>\n\n\n\n The function <\/p>\n\n\n\n At this point, you’ll have the number of found networks nearby and you can access any of the following parameters of each network.<\/p>\n\n\n\n To get & print the SSID of any found network in the list, call the following function <\/p>\n\n\n\n To get and print the RSSI (Received Signal Strength Indicator), use the <\/p>\n\n\n\n Which gives you an estimated signal strength value for any surrounding network you’ve found while scanning.<\/p>\n\n\n\n And this is the result of running the ESP32 WiFi Scanner sketch on my board.<\/p>\n\n\n\n <\/p>\n\n\n\n And I can definitely confirm that my home router WiFi has the strongest signal as it’s in the next room, followed by my other router on another floor which has a bit weaker signal as we can expect. So we can conclude this topic and move to the next which is trying to connect to an existing WiFi network with ESP32.<\/p>\n\n\n The RSSI<\/strong> (Received Signal Strength Indicator) can be checked by the ESP32 to determine the WiFi connection strength between the ESP32 and the specific WiFi network you’re trying to connect to (e.g. home router or any access point). This can be useful in case you’re having some issues with the WiFi connection or keeps disconnecting sporadically. <\/p>\n\n\n\n You can then check the RSSI for the network you’re working with and judge if the WiFi signal power needs adjusting or if you simply need to place the ESP32 board a little closer to the access point.<\/p>\n\n\n\n Generally speaking, the lower the RSSI value, the weaker the signal is, and vice versa. The range for RSSI value is from 0 down to -120 dBm. Having a 0 dBm is hard to achieve and it means you’ve got an amazingly strong connection. And low values from -90 down to -120 dBm are unusable at all.<\/p>\n\n\n\n RSSI is an estimated measure of the WiFi signal strength for a specific network (router or access point). The return value has the following form and unit (-x dBm<\/strong>). Which means a lower absolute value indicates a more powerful connection. Here’s how to judge the RSSI value and decide on the signal strength rating:<\/p>\n\n\n\n Parts List<\/strong><\/p>\n\n\n\n Here is the full components list for all parts that you’d need in order to perform the practical LABs mentioned here in this article and for the whole ESP32 series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.<\/p>\n\n\n\/*\n * ESP32 WiFi Scanner Example. Examples > WiFi > WiFiScan\n * Full Tutorial @ https:\/\/deepbluembedded.com\/esp32-wifi-library-examples-tutorial-arduino\/\n *\/\n\n#include \"WiFi.h\"\n\nvoid setup()\n{\n Serial.begin(115200);\n\n \/\/ Set WiFi to station mode and disconnect from an AP if it was previously connected.\n WiFi.mode(WIFI_STA);\n WiFi.disconnect();\n delay(100);\n\n Serial.println(\"Setup done\");\n}\n\nvoid loop()\n{\n Serial.println(\"Scan start\");\n\n \/\/ WiFi.scanNetworks will return the number of networks found.\n int n = WiFi.scanNetworks();\n Serial.println(\"Scan done\");\n if (n == 0) {\n Serial.println(\"no networks found\");\n } else {\n Serial.print(n);\n Serial.println(\" networks found\");\n Serial.println(\"Nr | SSID | RSSI | CH | Encryption\");\n for (int i = 0; i < n; ++i) {\n \/\/ Print SSID and RSSI for each network found\n Serial.printf(\"%2d\",i + 1);\n Serial.print(\" | \");\n Serial.printf(\"%-32.32s\", WiFi.SSID(i).c_str());\n Serial.print(\" | \");\n Serial.printf(\"%4d\", WiFi.RSSI(i));\n Serial.print(\" | \");\n Serial.printf(\"%2d\", WiFi.channel(i));\n Serial.print(\" | \");\n switch (WiFi.encryptionType(i))\n {\n case WIFI_AUTH_OPEN:\n Serial.print(\"open\");\n break;\n case WIFI_AUTH_WEP:\n Serial.print(\"WEP\");\n break;\n case WIFI_AUTH_WPA_PSK:\n Serial.print(\"WPA\");\n break;\n case WIFI_AUTH_WPA2_PSK:\n Serial.print(\"WPA2\");\n break;\n case WIFI_AUTH_WPA_WPA2_PSK:\n Serial.print(\"WPA+WPA2\");\n break;\n case WIFI_AUTH_WPA2_ENTERPRISE:\n Serial.print(\"WPA2-EAP\");\n break;\n case WIFI_AUTH_WPA3_PSK:\n Serial.print(\"WPA3\");\n break;\n case WIFI_AUTH_WPA2_WPA3_PSK:\n Serial.print(\"WPA2+WPA3\");\n break;\n case WIFI_AUTH_WAPI_PSK:\n Serial.print(\"WAPI\");\n break;\n default:\n Serial.print(\"unknown\");\n }\n Serial.println();\n delay(10);\n }\n }\n Serial.println(\"\");\n\n \/\/ Delete the scan result to free memory for code below.\n WiFi.scanDelete();\n\n \/\/ Wait a bit before scanning again.\n delay(5000);\n}<\/pre>\n\n\n\n
WiFi.scanNetworks()<\/code> is used to handle the core logic of WiFi scanning and it returns the total number of networks found.<\/p>\n\n\n\n
int n = WiFi.scanNetworks();<\/pre>\n\n\n\n
\n
WiFi.SSID(i)<\/code> and pass to it the index of the found network.<\/p>\n\n\n\n
Serial.print(WiFi.SSID(i));<\/pre>\n\n\n\n
WiFi.RSSI(i)<\/code> function as shown below.<\/p>\n\n\n\n
Serial.print(WiFi.RSSI(i));<\/pre>\n\n\n\n
ESP32 RSSI WiFi (Signal Strength Indicator)<\/strong><\/h3>\n\n\n
\n\n\nESP32 WiFi Signal Strength RSSI Rating<\/strong><\/h2>\n\n\n
RSSI Value Range<\/strong><\/td> WiFi Signal Strength<\/strong><\/td><\/tr> \u00a0RSSI > -30 dBm<\/td> \u00a0Amazing<\/td><\/tr> \u00a0RSSI < – 55 dBm<\/td> \u00a0Very good signal<\/td><\/tr> \u00a0\u00a0RSSI < – 67 dBm<\/td> \u00a0Fairly Good<\/td><\/tr> \u00a0\u00a0RSSI < – 70 dBm<\/td> \u00a0Okay<\/td><\/tr> \u00a0\u00a0RSSI < – 80 dBm<\/td> \u00a0Not good<\/td><\/tr> \u00a0\u00a0RSSI < – 90 dBm<\/td> \u00a0Extremely weak signal (unusable)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n
\n\n\n