Scanning the network

Is there any working solution for scanning specific SSID? I mean, you san whole networks, select one, and get the RSSI only for that one while moving around? Yes, there is WiFiScan in ESP8266 examples, but that cans whole network. I made something, but not quite good.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#define SCREEN_WIDTH  128
#define SCREEN_HEIGHT 32
#define OLED_RESET    -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int btnPinL = 16;
const int btnPinR = 13;
String wifiScan;
int btnStateL, btnStateR;
int modeSwitch = 1;
int i;
void setup() {
  Serial.begin(9600);
  pinMode(btnPinL, INPUT);
  pinMode(btnPinR, INPUT);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
}

void loop() {
  btnStateL = digitalRead(btnPinL);
  btnStateR = digitalRead(btnPinR);
  if(btnStateL == HIGH){
    modeSwitch = 1;
    }
  if(btnStateR == HIGH){
    modeSwitch = 2;
    }
  if(modeSwitch == 1){
    scanFunc();
    }
  if(modeSwitch == 2){
//this will be in another func
  display.clearDisplay();
  display.fillRect(64,0,128,1,WHITE);
  display.setCursor(2,4);
  display.setTextSize(1);
  Serial.println(WiFi.SSID(i));
  display.print(WiFi.SSID(i));
  display.display();
    }
  
}
void scanFunc(){
  Serial.println("scan start");
  display.clearDisplay();
  display.fillRect(0,0,64,1,WHITE);
  display.setCursor(2,10);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print("Scan Start");
  display.display();
  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
  display.clearDisplay();
  display.fillRect(0,0,64,1,WHITE);
  display.setCursor(2,4);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.print("No SSIDs");
  display.display();
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      display.clearDisplay();
      display.fillRect(0,0,64,1,WHITE);
      display.setCursor(2,4);
      display.setTextSize(1);
      display.setTextColor(WHITE);
      wifiScan = WiFi.SSID(i);
      display.print(wifiScan);
      display.setCursor(2,24);
      display.print((String)WiFi.RSSI(i)+" dBi");
      display.display();
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
      delay(1000);
    }
  }
  Serial.println("");
}

Here I used a NodeMcu, two buttons, and an OLED. You can see it in the sketch. On boot, it scans the networks. When pressing the second button while reading the results, it should go to another mode and pass that WiFi.RSSI(i). On the second mode, the second function should take that result and scan only that SSID.

Of course, this above doesn’t work. :slight_smile:

Can this be possible? How to pass that specific SSID to another function? Or some ready solution?

class ESP8266WiFiClass : public ESP8266WiFiGenericClass, public ESP8266WiFiSTAClass, public ESP8266WiFiScanClass, public ESP8266WiFiAPClass {
public:

// workaround same function name with different signature
using ESP8266WiFiGenericClass::channel;

using ESP8266WiFiSTAClass::SSID;
using ESP8266WiFiSTAClass::RSSI;
using ESP8266WiFiSTAClass::BSSID;
using ESP8266WiFiSTAClass::BSSIDstr;

using ESP8266WiFiScanClass::SSID;
using ESP8266WiFiScanClass::encryptionType;
using ESP8266WiFiScanClass::RSSI;
using ESP8266WiFiScanClass::BSSID;
using ESP8266WiFiScanClass::BSSIDstr;
using ESP8266WiFiScanClass::channel;
using ESP8266WiFiScanClass::isHidden;

Sorry, I am not following you.

I searched the internet. I am surprised that no one made it before.

I searched the internet. I am surprised that no one made it before.

Maybe you did not phrase you question correctly. Anyway you can not just 'scan' a single ssid. You can either connect to it, or you can scan all 'ssid's, compare the 'ssid's with the 'ssid' that you want the details for, and solely print those details. Either way you should store the name of the specific ID in a string (or String let's not fuss about it) Every time you run the scan, the 'ssid' you are looking for may be in a different place in the list.

The other words, don't mess up with that.

Could get the RSSI value of the connected SSID? That should be the other way around.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.