Open ghost opened 7 years ago
hi hope this helps.
Public Class Wifi
Public Shared Event ConnectionStatusChanged(isConnected As Boolean)
Public Shared ReadOnly Property IsConnected() As Boolean
Get
Return _wifi.ConnectionStatus = SimpleWifi.WifiStatus.Connected
End Get
End Property
Public Shared Function GetAccessPoints() As List(Of SimpleWifi.AccessPoint)
Return _wifi.GetAccessPoints().
OrderByDescending(Function(ap) ap.SignalStrength).
ToList()
End Function
Public Shared Function Connect()
If IsConnected Then Return True
For Each ap In GetAccessPoints().Where(Function(x) x.HasProfile)
If Connect(ap, New SimpleWifi.AuthRequest(ap)) Then Return True
Next
Return False
End Function
Public Shared Function Connect(ap As SimpleWifi.AccessPoint, ar As SimpleWifi.AuthRequest)
Disconnect()
AddHandler _wifi.ConnectionStatusChanged, AddressOf Wifi_ConnectionStatusChanged
Return ap.Connect(ar)
End Function
Public Shared Sub Disconnect()
_wifi.Disconnect()
RemoveHandler _wifi.ConnectionStatusChanged, AddressOf Wifi_ConnectionStatusChanged
End Sub
Private Shared _wifi As SimpleWifi.Wifi =
New SimpleWifi.Wifi()
Private Shared Sub Wifi_ConnectionStatusChanged(sender As Object, e As SimpleWifi.WifiStatusEventArgs)
RaiseEvent ConnectionStatusChanged(e.NewStatus = SimpleWifi.WifiStatus.Connected)
End Sub
End Class
thanks a lot. but... how to use it? why 2 connect funcions? thanks and regards
no problem you can catch some ideas from here
Sub Main()
'try to connect to a known network
Wifi.Connect()
'get all avaliable networks to choose witch one you will connect
Dim access_points = Wifi.GetAccessPoints()
'imagine you choose the first one
Dim access_point = access_points.First()
Dim auth_access = New SimpleWifi.AuthRequest(access_point)
If auth_access.IsPasswordRequired Then
If Not access_point.HasProfile Then
'TODO: request password, then
auth_access.Password = "typed password"
End If
End If
'try connect with given password
If Not Wifi.Connect(access_point, auth_access) Then
'if not, delete profile to request new attempt
access_point.DeleteProfile()
End If
End Sub
Thanks I got errors... "ConnectionStatus" is not a member of Wifi... Any suggestion? Thanks and regards
Could you paste the exception?
The error is while compiling.
Send me an example or attach your project.
i attach the project rename from ".png" to ."zip". i don't know why i can't send the ".zip". sorry for that. thanks and regards
vb is not case sensitive, so you have to change your project name. in c# "simpleWifi" and "SimpleWifi" are two namespaces, but in vb is one. try not create projects with the same name as the libraries you use.
hi thanks, but the name is not involved in the problem... i think the problem is from declarations...
change your assembly name and root namespace in project properties and the problem is fixed.
Yes! ;-) Fixed. I will try now to play with. Thanks a lot.
Another question: How can i know if i have internet connection? If i can reach, by example, www.google.com? thanks in advance.
glad to be helpful, but try to not run from the main subject, if so, go to forums or ask google. :)
Dim isNetworkAvailable = My.Computer.Network.IsAvailable
Dim isInternetAvailable = My.Computer.Network.Ping("http://google.com")
ok. thanks a lot! Regards
Hi all. When the Wifi.Connect(access_point, auth_access) is called with wrong password, the app hangs completly while the timeout is reached. Is there any way to avoid app hangs while wait for the timeout? Or any way to set the timeout? Thanks
hi, i didn't test it, but try it:
...
access_point.ConnectAsync(auth_access, onConnectComplete:=AddressOf OnConnectComplete)
...
Private Sub OnConnectComplete(isConnected As Boolean)
End Sub
Yes! Thanks!
Hi, I already populate the wifi list into combo box, but how to connect the network. Below load the list of wifi
` Private Sub loadWifi() listWifi.Items.Clear() Dim accessPoints As IEnumerable(Of AccessPoint) = Wifi.GetAccessPoints()
For Each ap As AccessPoint In accessPoints
listWifi.Items.Add(ap.Name)
Next
Dim selectedAP As AccessPoint = listWifi.SelectedItem
End Sub`
And below I try to connect but not working
` Private Sub connectTo()
Dim selectedAP As AccessPoint = listWifi.SelectedItem
Dim authRequest As AuthRequest = New AuthRequest(selectedAP)
Wifi.Connect(selectedAP, authRequest)
End Sub`
Thanks you @marcosdvpereira
hello does anyone have the example in vb.net, please? thanks and regards