B4A Library Simple WIFI library

Discussion in 'Additional libraries, classes and official updates' started by HotShoe, Mar 8, 2014.

  1. Mark Hollingworth

    Mark Hollingworth Member Licensed User

    I think this might be something to do with the Android version in question, I am testing on a real device running 5.1.1 and that's where I get the problem but if I run it on a device that is running Android Version 4.2.2 the error isn't happening and the .StartScan only returns one set of results..
  2. HotShoe

    HotShoe Well-Known Member Licensed User

    The latest version I have is 5.0.1, but, I will see what I can find out on this end.

    --- Jem
  3. Mark Hollingworth

    Mark Hollingworth Member Licensed User


    If you need me to do any testing please let me know, will be happy to help out.
  4. sorex

    sorex Expert Licensed User

    hey Shoe,

    someone on the chat had issues to connect to access points with different phones so I installed the latest to test it myself.

    when I connect to an AP it immediatly gives an error that it can't connect. works fine when I use the systems connect method tho.

    Can you have a look at this pleas?
  5. oceanwanderlust

    oceanwanderlust Member Licensed User

    connectToAP does not work in my own code or the example

    I am trying the example from v2.13 on my Droid Turbo which is still running Android 4.4.4, but every saved network I select on the list results in "Could not connect to"....

    As @jjcc suggested, from Android I 'Forgot' one saved open network. When I ran the example again and clicked on this network, it did not display an error, but my IP became SSID = <unknown ssid> and ever stranger Internet=true which is obviously wrong.

    Edit: I tried the example on Android 5.1 but it still does not work.
    Last edited: Aug 12, 2015
  6. HotShoe

    HotShoe Well-Known Member Licensed User

    I'll do that, thanks.

    I'll have another look at that method and see if I can find out what is happening.

    --- Jem
  7. HotShoe

    HotShoe Well-Known Member Licensed User

    New version posted in first message of this thread. Hopefully this fixes the connectToAP method for good.

    --- Jem
    Erel and cimperia like this.
  8. Scantech

    Scantech Well-Known Member Licensed User

    Where is the mlscan? I do not see all of the method.
  9. HotShoe

    HotShoe Well-Known Member Licensed User

    MLscan is still there and unchanged. I just checked using the mlwifitest app and don't see anything missing. What are you seeing on your end?

    --- Jem
  10. Scantech

    Scantech Well-Known Member Licensed User

    My mistake. It is all there.
  11. davepamn

    davepamn Active Member Licensed User

    I have a case where the wifi from the device becomes unavailable while the application is running. We turned the wifi off then on with the device. It seems like the application is jamming the socket. if I close and open the app then the socket becomes free. If I turn the wifi off then on the device frees. If I use your code to tell when the internet becomes unavailable then turn wifi off then back on, will it clear the socket.
  12. DT1111

    DT1111 Member Licensed User

    Hello Jem, thanks for your MLWifi library and I have had good success with it where my app uses the lib to communicate with a wifi device which returns data.

    Later I added a second wifi device where I have made the SSID, IP address and the port the same as the first.

    The intention was to make the app requesting for data alternately between device 1 and device 2 on the same IP. But the app could only get response from just one device. My understanding was since the two devices are on the same IP address and with similar SSID, using the ConnectToAP method will open comm channel to both devices simultaneously and the devices will respond accordingly depending on what the app requests. Obviously it is not the case, it seems.

    Do you know what the root cause may be?

  13. HotShoe

    HotShoe Well-Known Member Licensed User

    To my knowledge, there is no way to connect 2 devices with the same IP address to the same network. The network must be able to route messages/data to the correct device via its IP address, so at least in my experience, it can't be done. Are you sure the router/access point isn't assigning a different address to the second device?

    --- Jem
  14. DT1111

    DT1111 Member Licensed User

    The IP address of the device can be manually configured and I chose to make them the same. Bad idea? The idea is the app broadcasts commands to these devices on the same IP network. My app is the master and the devices are the slaves per the master-slave model.

    If I configured each device with a unique IP address, that would mean that the app has to connect to the first device via a unique IP, send a command, wait for response and then disconnect and connect to the second device via another unique IP, etc, etc and disconnect ... and so on. Is that the right approach? I hope not.
  15. HotShoe

    HotShoe Well-Known Member Licensed User

    I didn't know that there was any access point or router that would allow that. Generally they will ignore the requested duplicate IP and issue a new one. You would need to check the IP on your devices after connecting to see if they are truly the same or not.

    --- Jem
  16. DT1111

    DT1111 Member Licensed User

    Thanks Jem.

    Would you be able suggest a more decent approach to connecting with various IP devices with the Library. My concept below seems quite wrong and cumbersome. Thanks.

  17. HotShoe

    HotShoe Well-Known Member Licensed User

    I think I would look at building a server side app on a single computer on that network to handle all of the needs of the app. Then all devices could connect to it via IP address and port and then issue commands. You could use B4J and include some type of security protocol if needed.

    --- Jem
  18. FrankBerra

    FrankBerra Active Member Licensed User

    As reported by another user, sometimes i receive a strange error that crashes my app:
    10-17 13:49:48.240 16706 16706 E AndroidRuntime: FATAL EXCEPTION: main
    10-17 13:49:48.240 16706 16706 E AndroidRuntime: Process: test.app, PID: 16706
    10-17 13:49:48.240 16706 16706 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x4000010 (has extras) } in wifi.MLwifi$MLWifiScanner$WifiScanReceiver@63297bc
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:891)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at wifi.MLwifi$MLWifiScanner.checkSSID(MLwifi.java:346)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at wifi.MLwifi$MLWifiScanner.access$0(MLwifi.java:339)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at wifi.MLwifi$MLWifiScanner$WifiScanReceiver.onReceive(MLwifi.java:324)
    10-17 13:49:48.240 16706 16706 E AndroidRuntime:     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:881)
    How to reproduce the error:
    - start a wifi scan and get the results
    - turn off wifi
    and after a couple of seconds my app crashes.
    Android version: 5 and 6

    Any suggestion?
    Last edited: Oct 17, 2015
  19. HotShoe

    HotShoe Well-Known Member Licensed User

    I think I know why and where that is happening. I'll look at it this evening.


    --- Jem
    FrankBerra likes this.
  20. Sylwek

    Sylwek New Member Licensed User


    I have a problem with addAP method. Everytime this method return false. I tried to check this method on example from v2.12, but still I have the same result.
    I'm running on Android 4.2.2.

    DO you have any suggestions ?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice