/* SD card read/write This example shows how to read and write data to and from an SD card file The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. */ #include #include #include "ESP8266WiFi.h" //Sd2Card card; File myFile; void setup() { // Open serial communications and wait for port to open: //SPI.begin(); Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("Initializing SD card..."); if (!SD.begin(4)) { //if (!card.init(SPI_HALF_SPEED, 4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); } void loop() { // nothing happens after setup // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("scan.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { // Serial.print("Writing to scan.txt..."); // myFile.println("testing 1, 2, 3."); // close the file: // myFile.close(); // Serial.println("done."); Serial.println("scan start"); myFile.println("scan start"); // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(); char ssid[64]; Serial.println("scan done"); myFile.println("scan done"); if (n == 0) { Serial.println("no networks found"); myFile.println("no networks found"); } else { Serial.print(n); myFile.print(n); Serial.println(" networks found"); myFile.println(" networks found"); for (int i = 0; i < n; ++i) { delay(10); // Print SSID and RSSI for each network found Serial.print(i + 1); myFile.print(i + 1); Serial.print(": "); myFile.print(": "); Serial.print(WiFi.SSID(i)); myFile.print(WiFi.SSID(i)); Serial.print(" ("); myFile.print(" ("); Serial.print(WiFi.RSSI(i)); myFile.print(WiFi.RSSI(i)); Serial.print(")"); myFile.print(")"); Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"); myFile.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"); if (WiFi.encryptionType(i)==2) { Serial.println("TKIP(WPA)"); myFile.println("TKIP(WPA)"); } else if (WiFi.encryptionType(i)==5) { Serial.println("WEP"); myFile.println("WEP"); } else if (WiFi.encryptionType(i)==4) { Serial.println("CCMP(WPA)"); myFile.println("CCMP(WPA)"); } else if (WiFi.encryptionType(i)==7) { Serial.println("NONE"); myFile.println("NONE"); delay(10); } if (WiFi.encryptionType(i)==8) Serial.println("AUTO"); myFile.println("AUTO"); delay(10); } } Serial.println(""); myFile.println(""); // Wait a bit before scanning again delay(2000); } else { // if the file didn't open, print an error: Serial.println("error opening scan.txt"); } myFile.close(); delay(5000); }