我正在尝试使用simplewifi
连接到wifi。目前,我试过:
Wifi wifi = new Wifi();
// get list of access points
IEnumerable<AccessPoint> accessPoints = wifi.GetAccessPoints();
// for each access point from the list
foreach (AccessPoint ap in accessPoints)
{
Console.WriteLine("ap: {0}\r\n", ap.Name);
//check if SSID is desired
if (ap.Name.StartsWith("z"))
{
//verify connection to desired SSID
Console.WriteLine("connected: {0}, password needed: {1}, has profile: {2}\r\n", ap.Name, ap.IsConnected, ap.HasProfile);
if (!ap.IsConnected)
{
//connect if not connected
Console.WriteLine("\r\n{0}\r\n", ap.ToString());
Console.WriteLine("Trying to connect..\r\n");
AuthRequest authRequest = new AuthRequest(ap);
authRequest.Password = "123456789";
var x=ap.Connect(authRequest);
}
}
}
如果我的密码硬编码,我无法传递密码
var password="abc123"
如何传递密码并连接?
此外,即使我必须连接到没有密码的wifi,connect方法总是返回false
。
你需要设置authRequest.Password = "yourpassword";
在你的ap.connect(authRequest);
之前
添加以下来自console.write()
的https://github.com/DigiExam/simplewifi
放在文件的顶部
using SimpleWifi;
然后在你的功能
// Wifi object
Wifi wifi = new Wifi();
// get list of access points
IEnumerable<AccessPoint> accessPoints = wifi.GetAccessPoints();
// for each access point from list
foreach (AccessPoint ap in accessPoints){
Console.WriteLine("ap: {0}\r\n", ap.Name);
//check if SSID is desired
if (ap.Name.StartsWith("ardrone_")){
//verify connection to desired SSID
Console.WriteLine("connected: {0}, password needed: {1}, has profile: {2}\r\n", ap.Name, ap.IsConnected, ap.HasProfile);
if (!ap.IsConnected){
//connect if not connected
Console.WriteLine("\r\n{0}\r\n", ap.ToString());
Console.WriteLine("Trying to connect..\r\n");
AuthRequest authRequest = new AuthRequest(ap);
ap.Connect(authRequest);
}
}
}