Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * WeMos D1r2 WiFi Network Scanner
- *
- * learnelectronics
- * 19 MAY 2017
- *
- * www.youtube.com/c/learnelectronics
- *
- * NOTE: To use the Adafruit SSD1306 OLED Driver with the D1 you MUST set
- * the OLED-Reset to LED_BUILTIN
- */
- #include <Wire.h> //I2C Library for the OLED
- #include <Adafruit_SSD1306.h> //OLED Driver
- #include "ESP8266WiFi.h" //ESP8266 WiFi Library
- Adafruit_SSD1306 display(LED_BUILTIN); //create OLED object called display
- void setup() {
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //start the OLED @ Hex addy 0x3C
- display.display(); //show the Adafruit Logo
- delay(2000); //for 2 seconds
- display.clearDisplay(); //clear display & buffer
- WiFi.mode(WIFI_STA); //set WiFi mode
- WiFi.disconnect(); //WiFi disconnect
- delay(100); //short wait
- }
- void loop() {
- display.clearDisplay(); //clear display @ beginning of each loop
- display.setTextSize(1); //set smallest text size
- display.setTextColor(WHITE); //set text color to WHITE
- display.setCursor(0,0); //cursor to upper left
- //display.println("scan start");
- int n = WiFi.scanNetworks(); //get # of networks
- display.println("WiFi Scanner"); //print title to buffer
- display.println("---- -------"); //underline title to buffer
- if (n == 0) //if no networks found
- display.println("no networks found"); //print msg to buffer
- else //otherwise..
- {
- display.print(n); //print n to buffer
- display.println(" networks found"); //print msg to buffer
- for (int i = 0; i < n; ++i) //for loop for # of networks
- {
- //print SSID and RSSI for each network found
- display.print(i + 1);
- display.print(": ");
- display.print(WiFi.SSID(i));
- display.print(" (");
- display.print(WiFi.RSSI(i));
- display.print(")");
- display.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
- delay(10);
- }
- }
- Serial.println("");
- display.display(); //show buffer
- delay(5000); //wait 5 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement