Automatic Router Selection for ESP8266

I wonder if anyone who has done this can help.  As most of you know, I program my ESP8266 devices in C.  I’ve been having some issues with weak signal recently and it would be really nice to have a list of acceptable access points and their passwords – and have the ESP, if it loses the signal, check the list (including identical SSIDs) and reconnect.

Has anyone done this already and if so would they care to share code?

5 thoughts on “Automatic Router Selection for ESP8266

  1. The ESP-13’s supposedly have 10db more, due to better RF design. That might solve your weak signals problem without needing to code…

    1. Hence my question – have you done any comparisons – and if not – do you have time to do any? I would not be the only one in here interested in your input…

  2. Hi Pete,

    I’ve implemented this but I use the Arduino ESP8266 framework and the supplied Wifi libraries make getting a list of all available access points with their corresponding signal strengths, encryption properties etc very easy.

    I setup a C array with each entry having an access point SSID and the corresponding password. It’s then a case of obtaining the available Wifi SSIDs and running down the C array looking for a match.

    Code looked like this (hope formatting works)

    // WiFi network parameters
    // One row per known WiFi network
    // For each network
    // column 1 == SSID
    // column 2 == Wifi password
    // column 3 == thingspeak API key to use when logging data

    const String wifiNetworks[networks][3] =
    {
    { “YOUR SSID”, “YOUR WIFI PASSWORD”, “YOUR THINGSPEAK API CODE”},
    };

    boolean findNetwork ()
    {
    boolean selected=false;

    // scan for nearby networks:
    Serial.println(“** Scanning Networks **”);
    int numSsid = WiFi.scanNetworks();
    if (numSsid == -1)
    {
    Serial.println(“No Wifi networks found”);
    return selected;
    }

    // print the list of networks seen:
    Serial.print(“Number of available networks: “);
    Serial.println(numSsid);

    Serial.println ( “Network list” );

    // print the network number and name for each network found:
    for (int thisNet = 0; thisNet<numSsid; thisNet++) {
    Serial.print(thisNet);
    Serial.print(") SSID: ");
    Serial.print(WiFi.SSID(thisNet));
    displayEncryptionType(WiFi.encryptionType(thisNet));
    Serial.print("\tSignal: ");
    Serial.print(WiFi.RSSI(thisNet));
    Serial.println(" dBm");
    for ( int i=0; i< networks && !selected ; i++ ) {
    if ( wifiNetworks[i][0]==WiFi.SSID(thisNet)) {
    wifiNetworks[i][0].toCharArray ( ssid,50);
    wifiNetworks[i][1].toCharArray ( password,20);
    wifiNetworks[i][2].toCharArray ( apiKey,20);
    selected=true;
    break;
    }
    }
    }
    if ( selected ) {
    Serial.println ( "\nRecognised Network SSID: " + String ( ssid ) );
    } else {
    Serial.println ( "\nNo recognised network found" );
    }
    return selected;
    }

    1. Missed out

      const int networks=1; // Number of WiFi networks known

      at the start

      And as you can see, my use case involved having the thingspeak API code in the array too.

Comments are closed.