{"id":13112,"date":"2017-02-03T15:06:55","date_gmt":"2017-02-03T20:06:55","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=13112"},"modified":"2023-04-11T22:17:49","modified_gmt":"2023-04-12T02:17:49","slug":"tutorial-4-working-esp8266-wifi-scan-class","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/tutorial-4-working-esp8266-wifi-scan-class\/","title":{"rendered":"Tutorial 4: Working with ESP8266 WiFi Scan Class"},"content":{"rendered":"<p>Working with ESP8266 WiFi functionality using Arduino IDE has been made surprisingly simple by the availability of the versatile <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/doc\/esp8266wifi\/readme.md\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266WiFi library<\/a>\u00a0<\/strong>that allows user to configure\u00a0the ESP8266 as a WiFi network scanner, a WiFi station (connected to a WiFi network), a soft access point (creating it&#8217;s own WiFi network), etc.\u00a0In this tutorial, we will explore the features of the\u00a0<a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/doc\/esp8266wifi\/scan-class.md\" target=\"_blank\" rel=\"noopener noreferrer\">Scan Class<\/a> of the\u00a0<strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/doc\/esp8266wifi\/readme.md\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266WiFi library<\/a><\/strong>. The Scan Class allows you to scan and list the available WiFi networks in the range. In order to try this feature, open an example code from <strong><em>File-&gt;Examples-&gt;ESP8266WiFi-&gt;WiFiScan<\/em><\/strong>.<\/p>\n<p>In the example code,<\/p>\n<pre>int n = WiFi.scanNetworks();<\/pre>\n<p>returns the number of WiFi networks found within the range. You can also print out the names and Received Signal Strength Indication (RSSI) values in dBm using <em>WiFi.SSID()<\/em> and <em>WiFi.RSSI()<\/em> functions.<\/p>\n<div id=\"attachment_13140\" style=\"width: 784px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/Scanner.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13140\" class=\"wp-image-13140 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/Scanner.jpg\" alt=\"WiFi Scanner example\" width=\"774\" height=\"1152\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/Scanner.jpg 774w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/Scanner-437x650.jpg 437w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/Scanner-688x1024.jpg 688w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/a><p id=\"caption-attachment-13140\" class=\"wp-caption-text\">WiFi Scanner example<\/p><\/div>\n<p>The complete WiFi Scan example code is posted below.<\/p>\n<pre>\/*\n * This sketch demonstrates how to scan WiFi networks. \n * The API is almost the same as with the WiFi Shield library, \n * the most obvious difference being the different file you need to include:\n *\/\n#include \"ESP8266WiFi.h\"\n\nvoid setup() {\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 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 {\n Serial.print(n);\n Serial.println(\" networks found\");\n for (int i = 0; i &lt; n; ++i)\n {\n \/\/ Print SSID and RSSI for each network found\n Serial.print(i + 1);\n Serial.print(\": \");\n Serial.print(WiFi.SSID(i));\n Serial.print(\" (\");\n Serial.print(WiFi.RSSI(i));\n Serial.print(\")\");\n Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?\" \":\"*\");\n delay(10);\n }\n }\n Serial.println(\"\");\n\n \/\/ Wait a bit before scanning again\n delay(10000);\n}<\/pre>\n<p>Upload the example code to your EasyESP-1 board and open the\u00a0<strong>Serial Monitor<\/strong> window. You will see the ESP8266 prints out the list of available WiFi networks on the screen, as shown below.<\/p>\n<div id=\"attachment_13129\" style=\"width: 1156px\" class=\"wp-caption alignnone\"><a style=\"font-weight: bold; text-align: center; font-size: 0.95em;\" href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/WiFiscan.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13129\" class=\"wp-image-13129 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/WiFiscan.png\" alt=\"WiFi scanner output\" width=\"1146\" height=\"836\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/WiFiscan.png 1146w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/WiFiscan-580x423.png 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/WiFiscan-1024x747.png 1024w\" sizes=\"auto, (max-width: 1146px) 100vw, 1146px\" \/><\/a><p id=\"caption-attachment-13129\" class=\"wp-caption-text\">WiFi scanner output<\/p><\/div>\n<h3><a href=\"https:\/\/www.elecrow.com\/cde82664e.html\" target=\"_blank\" rel=\"noopener noreferrer\">Buy EasyESP-1 board<\/a><\/h3>\n<h4>More tutorials<\/h4>\n<h5 class=\"post-title\"><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/easyesp-1-rapid-prototyping-development-board-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-1-setting-arduino-ide-easyesp-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-2-easyesp-1-hello-world-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 2: EASYESP-1 \u201cHELLO WORLD\u201d EXAMPLE<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-3-connecting-oled-display-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266<\/a><\/h5>\n","protected":false},"excerpt":{"rendered":"<p>Working with ESP8266 WiFi functionality using Arduino IDE has been made surprisingly simple by the availability of the versatile ESP8266WiFi library\u00a0that allows user to configure\u00a0the ESP8266 as a WiFi network scanner, a WiFi station (connected to a WiFi network), a soft access point (creating it&#8217;s own WiFi network), etc.\u00a0In this tutorial, we will explore the features of the\u00a0Scan Class of the\u00a0ESP8266WiFi library. The Scan Class allows you to scan and list the available WiFi networks in the range. In order to try this feature, open an example code from File-&gt;Examples-&gt;ESP8266WiFi-&gt;WiFiScan. In the example code, int n = WiFi.scanNetworks(); returns the<\/p>\n","protected":false},"author":1,"featured_media":13129,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1603,1044,1464,1466],"tags":[1621,1622],"class_list":["post-13112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-tutorials","category-esp8266","category-featured","category-tutorials","tag-easyesp-1-tutorial","tag-esp8266-wifi-scanner"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=13112"}],"version-history":[{"count":15,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13112\/revisions"}],"predecessor-version":[{"id":15141,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13112\/revisions\/15141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/13129"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=13112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=13112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=13112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}