新手求助!-Arduino中文社区 - Powered by Discuz! Archiver

xiongjiaxiao 发表于 2022-1-7 18:53

新手求助!

最近有个项目需要用到连接wifi,主控用esp8266,就是想做到手机设置里会自动扫描周边的wifiIP地址,这样就不用自己去烧写程序来改wifi账号和密码了。我用AT指令可以获取到周边的WIFI,但是用arduino来编程该如何实现?急求!:funk:

XlinliY.Zhang 发表于 2022-1-7 22:19

/*
    This sketch demonstrates how to scan WiFi networks.
    The API is almost the same as with the WiFi Shield library,
    the most obvious difference being the different file you need to include:
*/

#include <ESP8266WiFi.h>

void setup() {
Serial.begin(115200);
Serial.println(F("\nESP8266 WiFi scan example"));

// Set WiFi to station mode
WiFi.mode(WIFI_STA);

// Disconnect from an AP if it was previously connected
WiFi.disconnect();
delay(100);
}

void loop() {
String ssid;
int32_t rssi;
uint8_t encryptionType;
uint8_t* bssid;
int32_t channel;
bool hidden;
int scanResult;

Serial.println(F("Starting WiFi scan..."));

scanResult = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true);

if (scanResult == 0) {
    Serial.println(F("No networks found"));
} else if (scanResult > 0) {
    Serial.printf(PSTR("%d networks found:\n"), scanResult);

    // Print unsorted scan results
    for (int8_t i = 0; i < scanResult; i++) {
      WiFi.getNetworkInfo(i, ssid, encryptionType, rssi, bssid, channel, hidden);

      Serial.printf(PSTR("%02d: [%02X:%02X:%02X:%02X:%02X:%02X] %ddBm %c %c %s\n"),
                  i,
                  channel,
                  bssid, bssid, bssid,
                  bssid, bssid, bssid,
                  rssi,
                  (encryptionType == ENC_TYPE_NONE) ? ' ' : '*',
                  hidden ? 'H' : 'V',
                  ssid.c_str());
      delay(0);
    }
} else {
    Serial.printf(PSTR("WiFi scan error %d"), scanResult);
}

// Wait a bit before scanning again
delay(5000);
}

xiongjiaxiao 发表于 2022-1-7 22:21

XlinliY.Zhang 发表于 2022-1-7 22:19


呜啊!感谢大神!等了好久都没人回复
页: [1]
查看完整版本: 新手求助!