Last active
November 28, 2016 20:28
-
-
Save fredowsley/de578000bf1dc8f4085dfb1c790c6ba5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* WiFi Scanner for WiMos D1 | |
* Fred Owsley - @fredowsley | |
* Use Adafruit_SSD1306 libs from https://github.com/tekk/MeteoESP/tree/master/lib/Adafruit_SSD1306-esp8266-64x48 | |
* or this one: https://github.com/mcauser/Adafruit_SSD1306/blob/esp8266-64x48 | |
*/ | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Time.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#include <ESP8266WiFi.h> | |
// SCL GPIO5 | |
// SDA GPIO4 | |
#define OLED_RESET 0 // GPIO0 | |
Adafruit_SSD1306 display(OLED_RESET); | |
#if (SSD1306_LCDHEIGHT != 48) | |
#error("Height incorrect, please fix Adafruit_SSD1306.h!"); | |
#endif | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
// Get the screen ready | |
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!) | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48) | |
// init done | |
// Show image buffer on the display hardware. | |
// Since the buffer is intialized with an Adafruit splashscreen | |
// internally, this will display the splashscreen. | |
display.display(); | |
delay(500); | |
// Clear the buffer and set the font size and color | |
display.clearDisplay(); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.println("Screen OK\n"); | |
// Screen is ready. | |
// Setup the wifi | |
WiFi.mode(WIFI_STA); | |
WiFi.disconnect(); | |
delay(100); | |
display.println("Wifi OK"); | |
display.display(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
// WiFi.scanNetworks will return the number of networks found | |
int n = WiFi.scanNetworks(); | |
if (n == 0) { | |
display.clearDisplay(); | |
display.setCursor(0,0); | |
display.println("no networks found"); | |
display.display(); | |
} | |
else | |
{ | |
display.clearDisplay(); | |
display.setCursor(0,0); | |
display.println("networks found"); | |
display.display(); | |
delay(500); | |
display.clearDisplay(); | |
for (int i = 0; i < n; ++i) | |
{ | |
// Print SSID and RSSI for each network found | |
display.setCursor(0,0); | |
display.print(i + 1); | |
display.print(": \n"); | |
display.print(WiFi.SSID(i)); | |
display.print("\n"); | |
display.print(" ("); | |
display.print(WiFi.RSSI(i)); | |
display.print(")"); | |
display.print("\n"); | |
display.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"); | |
display.display(); | |
delay(500); | |
display.clearDisplay(); | |
} | |
} | |
// Wait a bit before scanning again | |
//delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment