本站改版新增arduino频道

Micropython
Arduino

arduino 扫描周围wifi


arduino 扫描周围wifi

#include <Arduino.h>
#include "WiFi.h"
 
String ssid;
String password;
void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_MODE_STA);
  WiFi.disconnect(); //断开可能的连接
  delay(100);
  Serial.println("开始扫描WIFI:");
  int n = WiFi.scanNetworks();
  if (n)
  {
    Serial.print("扫描到");
    Serial.print(n);
    Serial.println("个WIFI");
    for (size_t i = 0; i < n; i++)
    {
      Serial.print("WiFi的名称(SSID):");
      Serial.println(WiFi.SSID(i));
      Serial.print("WiFi的信号强度(RSSI):");
      Serial.println(WiFi.RSSI(i));
      Serial.print("WiFi加密与否:");
      Serial.println(WiFi.encryptionType(i) == WIFI_AUTH_OPEN ? "未加密" : "加密");
 
      if (WiFi.SSID(i) == "NBWIFI")
      {
        ssid = WiFi.SSID(i);
        password = "z7758521";

  WiFi.begin(ssid.c_str(), password.c_str());
  while (!WiFi.isConnected())
  {
    Serial.print(".\n");
    
  }
  Serial.println("连接成功");

      }
    }
  }
  else
  {
    Serial.println("没扫描到WIFI");
  }
  
}
void loop()
{
}



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号

执行时间: 0.016934871673584 seconds