Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example in vb.net #24

Open
ghost opened this issue Nov 23, 2016 · 19 comments
Open

example in vb.net #24

ghost opened this issue Nov 23, 2016 · 19 comments

Comments

@ghost
Copy link

ghost commented Nov 23, 2016

hello
does anyone have the example in vb.net, please?
thanks and regards

@marcosdvpereira
Copy link

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

@ghost
Copy link
Author

ghost commented Dec 15, 2016

thanks a lot.
but... how to use it?
why 2 connect funcions?
thanks and regards

@marcosdvpereira
Copy link

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

@ghost
Copy link
Author

ghost commented Dec 15, 2016

Thanks
I got errors...
"ConnectionStatus" is not a member of Wifi...
Any suggestion?
Thanks and regards

@marcosdvpereira
Copy link

Could you paste the exception?

@ghost
Copy link
Author

ghost commented Dec 17, 2016

The error is while compiling.

@marcosdvpereira
Copy link

Send me an example or attach your project.

@ghost
Copy link
Author

ghost commented Dec 18, 2016

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

simplewifi zip

@marcosdvpereira
Copy link

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.

@ghost
Copy link
Author

ghost commented Dec 19, 2016

hi
thanks, but the name is not involved in the problem... i think the problem is from declarations...

@marcosdvpereira
Copy link

change your assembly name and root namespace in project properties and the problem is fixed.

@ghost
Copy link
Author

ghost commented Dec 19, 2016

Yes! ;-)
Fixed. I will try now to play with.
Thanks a lot.

@ghost
Copy link
Author

ghost commented Dec 19, 2016

Another question:
How can i know if i have internet connection?
If i can reach, by example, www.google.com?
thanks in advance.

@marcosdvpereira
Copy link

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")

@ghost
Copy link
Author

ghost commented Dec 21, 2016

ok.
thanks a lot!
Regards

@ghost
Copy link
Author

ghost commented Dec 28, 2016

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

@marcosdvpereira
Copy link

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

@ghost
Copy link
Author

ghost commented Dec 29, 2016

Yes!
Thanks!

@shahrulamir15
Copy link

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 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants