fingy

Untitled

Mar 8th, 2021
774
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Arduino.h>
  2. //#include <header.h>
  3.  
  4. #include <WiFi.h>
  5.  
  6.  
  7. const char* ssid = "SSID";
  8. const char* password = "PASSWORD";
  9.  
  10. void ScanWiFi() {
  11.   int n = WiFi.scanNetworks();
  12.   Serial.println("scan done");
  13.   if (n == 0) {
  14.       Serial.println("no networks found");
  15.   } else {
  16.     Serial.print(n);
  17.     Serial.println(" networks found");
  18.     for (int i = 0; i < n; ++i) {
  19.       // Print SSID and RSSI for each network found
  20.       Serial.print(i + 1);
  21.       Serial.print(": ");
  22.       Serial.print(WiFi.SSID(i));
  23.       Serial.print(" (");
  24.       Serial.print(WiFi.RSSI(i));
  25.       Serial.print(")");
  26.       Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
  27.       delay(10);
  28.     }
  29.  
  30. }
  31. }
  32.  
  33. void initWiFi() {
  34.   WiFi.mode(WIFI_STA);
  35.   WiFi.setSleep(false);
  36.   WiFi.begin(ssid, password);
  37.   Serial.print("Connecting to WiFi ..");
  38.   while (WiFi.status() != WL_CONNECTED) {
  39.     Serial.println("Tentative de connexion.....");
  40.     delay(1000);
  41.   }
  42.   Serial.println(WiFi.localIP());
  43. }
  44.  
  45. void setup() {
  46.   Serial.begin(9600);
  47.   ScanWiFi();
  48.   delay(2000);
  49.   initWiFi();
  50.   Serial.print("RRSI: ");
  51.   Serial.println(WiFi.RSSI());
  52. }
  53.  
  54. void loop() {
  55.   // put your main code here, to run repeatedly:
  56. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×