Code Monkey home page Code Monkey logo

Comments (19)

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

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

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

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

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

Could you paste the exception?

from simplewifi.

 avatar commented on August 25, 2024

The error is while compiling.

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

Send me an example or attach your project.

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

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.

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

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

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

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

from simplewifi.

 avatar commented on August 25, 2024

ok.
thanks a lot!
Regards

from simplewifi.

 avatar commented on August 25, 2024

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

from simplewifi.

marcosdvpereira avatar marcosdvpereira commented on August 25, 2024

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

from simplewifi.

 avatar commented on August 25, 2024

Yes!
Thanks!

from simplewifi.

shahrulamir15 avatar shahrulamir15 commented on August 25, 2024

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 

from simplewifi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.