B4A Library VBWep 1.0 Library (WEP)

VBWep 1.1 Library (WEP)

Releasing VBWep 1.1
Allows you to connect to a WIFI via WEP with SSID,PASSWORD

  • VBConnect
    Permissions:
    • android.permission.CHANGE_NETWORK_STATE
    • android.permission.WAKE_LOCK
    • android.permission.INTERNET
    • android.permission.UPDATE_DEVICE_STATS
    • android.permission.CHANGE_WIFI_STATE
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.ACCESS_WIFI_STATE
    Properties:
    • BSSID As String
      Return a wifi BSSID as STRING
    • IPADDRESS As String
      Return a wifi IP ADDRESS as INT
      *(not sure if this works)
    • SupplicantState As SupplicantState
      Return a STATUS STATE
      *
      *ASSOCIATED - Association completed.
      *ASSOCIATING - Trying to associate with an access point.
      *COMPLETED - All authentication completed.
      *DISCONNECTED - client is not associated, *likely to start looking for an access point*
      *DORMANT - An Android-added state that is reported when a client issues an explicit DISCONNECT command.
      *FOUR_WAY_HANDSHAKE - WPA 4-Way Key Handshake in progress.
      *GROUP_HANDSHAKE - WPA Group Key Handshake in progress.
      *INACTIVE - Inactive state.
      *INVALID - A pseudo-state that should normally never be seen. SCANNING - Scanning for a network.
      *UNINITIALIZED - No connection.
    • mac As String
      Return a wifi mac address as STRING
    Methods:
    • GetWifiList As List
      Return a List of the names of available WIFI Spots.
    • RemoveAllSavedNetworks
      Removes all saved networks on device
      *Good when you want to reset wifi configurations
      *WARNING: Will remove all passwords of saved wifi locations
    • cWEP (wepSSID As String, wepPASS As String)
      Connect to the given WEP network ssid with the password.
      *No quotes or backslashes needed.
      wepSSID:*
      wepPASS:*
    • intToIp (i As Int) As String
    • readWepConfig
      readWepConfig()
      *displays info to the b4a debug log window
    • weconnected As String
      If connected:
      *Returns a String *YES *
      *If not connected:
      *Returns a String *NO

cWep(ssid,password)
connects device to the wifi WEP/SSID

weconnected()
returns if you are connected to wifi

GetWifiList()
returns a list of available wifi's
returns the % of strength
returns the type of network
example: Igloo ::: [WPA-PSK-TKIP][WPA2-PSK-TKIP+CCMP] ::: 16

Msgbox(MyWiFi.mac,"mac address")
Msgbox(MyWiFi.IPADDRESS,"IP")
Msgbox(MyWiFi.BSSID,"BSSID")
Msgbox(MyWiFi.SupplicantState,"SUPSTATE")

* Return a STATUS STATE
*
* ASSOCIATED - Association completed.
* ASSOCIATING - Trying to associate with an access point.
* COMPLETED - All authentication completed.
* DISCONNECTED - client is not associated, likely to start looking for an access point
* DORMANT - An Android-added state that is reported when a client issues an explicit DISCONNECT command.
* FOUR_WAY_HANDSHAKE - WPA 4-Way Key Handshake in progress.
* GROUP_HANDSHAKE - WPA Group Key Handshake in progress.
* INACTIVE - Inactive state.
* INVALID - A pseudo-state that should normally never be seen. SCANNING - Scanning for a network.
* UNINITIALIZED - No connection.

RemoveAllSavedNetworks()
clears out all Saved Networks in your wifi list
this will remove all saved configurations
don't use if you have and need wifi passwords stored on device



Attached is an example program, please test and give feedback.

Credits: Tomas for helping me start this a few months ago

Thanks in Advance
Vb1992

Library Revision History:

old...... Library is version 1.0 - July 17th, 2012
New...... Library is version 1.1 - July 19th, 2012

VBWep.zip is the project (also see in this thread NJDUDE's advanced example project)
VBWep1.1.zip is the library
 

Attachments

  • VBWep.zip
    5.8 KB · Views: 1,243
  • VBWep1.1.zip
    7.7 KB · Views: 1,633
Last edited:

westingenieria

Active Member
Licensed User
Longtime User
I have a temporal solution for this.. i manage the duplicate SSID in b4a using arrays. If anyone want to know i can share the code.

Great library. Thank you for your work. Now i made a little modification (WPA+static IP) if someone has some interest i can upload the library...



I have a problem with scanning networks... i have duplicate SSID in my list :sign0148:(also in the log). I cant find the problem... Ill appreciate if someone can help me.

PD. sorry for my english, i know it sucks!
 

suciwulans

Active Member
Licensed User
Longtime User
i tested the example project in this thread, but didn't work.
"no network found"
and when "refresh" still show up no network found.
i don't know what's the problem
 

fabpalma

Member
Licensed User
Longtime User
Hi Vb1992,

there is a way to get an event when a new network is available ? I would get notice when a new Wifi is available without doing a time scheduled scan ...

Thanks
Fab
 

Turbo3

Active Member
Licensed User
Longtime User
I get a divide by zero error using sample 1.2 with library 1.1 and 1.5. It fails on line 120 "Buffer = MyWiFi.GetWifiList" and log shows it gets my network data but dies when it sees my neighbors network.

B4X:
** Activity (main) Create, isFirst = true **


###################


## GetWifiList  ##
###################
-----Receiving available wifi's


###################
SSID:  VorlanF
VorlanF ::: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP] ::: 44
###################
###################
SSID:  towers-wlan
main_refresh (B4A line: 120)


Buffer = MyWiFi.GetWifiList
java.lang.ArithmeticException: divide by zero


    at android.net.wifi.WifiManager.calculateSignalLevel(WifiManager.java:840)
    at vb.connect.Mywifi.Mywifi.GetWifiList(Mywifi.java:465)
    at vbwep.wifi.cool.main._refresh(main.java:491)
    at vbwep.wifi.cool.main._activity_create(main.java:347)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at vbwep.wifi.cool.main.afterFirstLayout(main.java:98)
    at vbwep.wifi.cool.main.access$100(main.java:16)
    at vbwep.wifi.cool.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)


    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
    at dalvik.system.NativeStart.main(Native Method)

This library seems to be the only one that has the functions I need but with this bug it will not work.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Tried to connect to a network that was known, manually disconnected. Android 4.2.
Lib is 1.1 from the first post, but in the lib list is shown as v 1.00.
B4A 3.80.

B4X:
###################
** Activity (main) Pause, UserClosed = false **


** Activity (connect) Create, isFirst = true **


** Activity (connect) Resume **


---------Starting VBWIFI now


----Entered Network info


--SSID PASSWORD: [password]
------Done new conf.WifiConfiguration.
...........entering wifiManager.
-----Adding network: wifiManager.addNetwork(conf);
-----Receiving current wifi list
java.lang.NullPointerException
    at vb.connect.Mywifi.Mywifi.cWEP(Mywifi.java:179)
    at peacemaker.wificonnecttest.connect._connectbutton_click(connect.java:350)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
    at android.view.View.performClick(View.java:4209)
    at android.view.View$PerformClick.run(View.java:17431)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5297)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Also error at
B4X:
wfSignal.BSSID = WiFiData(3)
no such 3rd item :-(

Please, who is interested - try my project, attached.
 

Attachments

  • b4a3.8_project.zip
    10 KB · Views: 392

Harish Kumar Arya

Member
Licensed User
Longtime User
Hi vb1992 & NJ,

I have just tried using the sample apps(version 1.1 and 1.2) and also the APK with the library(1.5 BETA). I can get the list of all WiFi networks, but when i try to connect to one of them, I get the following error:

android.system.ErrNoException: recvfrom failed: ETIMEDOUT (Connection timed out).

Any pointers or things that I can try?

TIA,

Harish
 
Top