Skip to content

Instantly share code, notes, and snippets.

@yagop
Created January 29, 2023 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yagop/f295179075033e94d5723bce36db786c to your computer and use it in GitHub Desktop.
Save yagop/f295179075033e94d5723bce36db786c to your computer and use it in GitHub Desktop.
/**
* Scan networks and print in screen
*/
#include "WiFi.h"
#include "HT_SSD1306Wire.h"
#define BAUDRATE 115200
// addr , freq , i2c group , resolution , rst
SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED);
void VextON(void) {
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
}
void setup() {
Serial.begin(BAUDRATE);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
VextON();
}
void loop() {
Serial.println("Loooooop");
display.init();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 0, "Scanning networks...");
// WiFi.scanNetworks will return the number of networks found
int networksFound = WiFi.scanNetworks();
if (networksFound == 0) {
display.drawString(0, 0, "No networks found");
display.display();
delay(500);
return;
}
display.drawString(0, 0, String(networksFound) + " networks found:");
display.display();
// Reset screen as we will write in 0
display.init();
int textPosition = 0;
for (int network = 0; network < networksFound; ++network) {
// Solo podemos mostrar 5
if (network % 5 == 0) {
delay(1000);
// Limpiamos
display.init();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
textPosition = 0;
}
bool isEncrypted = WiFi.encryptionType(network) == WIFI_AUTH_OPEN;
String encryptionInfo = isEncrypted ? "" : "*";
String wifiInfo = WiFi.SSID(network) + ": (" + WiFi.RSSI(network) + ") " + encryptionInfo;
display.drawString(0, textPosition, wifiInfo);
textPosition = textPosition + 10;
display.display();
delay(1000);
}
// Wait a bit before scanning again
delay(3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment