Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Mikejstb
#19155 I seem to be having a bad time getting things posted these days.
Anyway, here's my modified Scan_Wifi_networks function.

I modified it to:
-display the # of APs found
-display 8 at a time AP SSID + RSSI value with a little pause between them
-if > 8 APs then clear the display and then display the next 8, etc.

I think it would be really neat if it could sort the APs by RSSI - show the strongest first on through the weakest.

Hopefully this post makes it through and I haven't messed it up some how again.

Code: Select allvoid Scan_Wifi_Networks()

{
   int c = 0;
   char myStr[13];
   char mySSIDstr[20];

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  // Need to be in dicsonected mode to Run network Scan!
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
   // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  sprintf(myStr,"%d APs found\0",n);
  clear_display();
  sendStrXY(myStr,3,0); // display the number of APs found
    delay(2000);
 
  if (n == 0)
  {
    clear_display();
    sendStrXY("No networks found",3,0);
    delay(1000);
   } 
  else
  {

   clear_display(); // Clear OLED
 
    for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
        sprintf(myStr,"%s",WiFi.SSID(i)); // copy in the SSID
        strncpy(mySSIDstr,myStr,12);      // then truncate it
        myStr[12] = 0; 
        sprintf(myStr,"%s %2d\0",myStr,WiFi.RSSI(i)); // append the RSSI
        sendStrXY(myStr,c,0);
        c++;
        if (c > 7){
         delay(2000);
         clear_display(); // Clear OLED
         c = 0 ;
        }
        delay(2000);       
    } // end of for loop
  }  // end of else
} // end of ScanWifiNetworks function
User avatar
By Mikejstb
#19266 it's funny, I was googling for "Ardiuino string truncation" and such and just not finding that I needed. Then I guess it dawned on me that the Arduino sketches are pretty much "C", so I tried the good old sprint() and was surprised that it worked!
User avatar
By danbicks
#19268 C programmer background lol, I can tell :)

Really nice work, have it running perfect. I am in the process of trying to get a stable MQTT app running with OLED etc.
So far have it subscribed to 2 topics with callbacks and command processing in place. Just going to create some nice MQTT OLED graphic icons etc and then test for stability.

Have added some routines to check for loss of connection or router and then re establish, also tinkering with Qos levels :)

All good fun Lol.

Dans