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

Unable to connect with the IoT wifi endpoint #174

Open
vpalcar opened this issue Sep 16, 2021 · 11 comments
Open

Unable to connect with the IoT wifi endpoint #174

vpalcar opened this issue Sep 16, 2021 · 11 comments

Comments

@vpalcar
Copy link

vpalcar commented Sep 16, 2021

Hi there,

I am developing the app strictly for Android 11 and want to connect to wifi through the app. It says and shows that it is connected to the wifi (when I go to the wifi settings it is said that wifi is connected through the app and there is an exclamation mark next to the wifi icon). When I try to send the simple get request to the IoT device I am connected to, it doesn’t work (although I can successfully send that same request when I connect manually to the wifi endpoint). I am not sure if there is something I am doing wrong about it or I understand the documentation incorrectly.

Here is the code snippet of the function that triggers the connection process:

Future<String> connect(String ssid) async {
    try {
      bool result = await WiFiForIoTPlugin.connect(ssid, withInternet: false);
      print("connecting");
      if (result) {
        return "Successfully connected";
      } else {
        return "There was an error connecting to that wifi!";
      }
    } catch (e) {
      throw Exception(e);
    }
  }

Thank you for your response.

@daadu
Copy link
Member

daadu commented Sep 16, 2021

need to use forceWifiUsage(true) and disable it again - when you make network call with the wifi connected.

@vpalcar
Copy link
Author

vpalcar commented Sep 16, 2021

Sorry, could you add some more context to that? I also use a webview to show the interface of the connected IoT device, so I am not really sure where to use this forceWifiUsage and when to disable it.

@daadu
Copy link
Member

daadu commented Sep 19, 2021

forceWifiUsage when enabled, binds the app processes to the network that is connected with connect method, therefore to make network calls via the connected network you need to enable it and since the network restricts "the Internet" usage, you need to disable it when making network call to "the Internet"

@luna-almeida-coding
Copy link

luna-almeida-coding commented Oct 1, 2021

My code was working normally, and then i just receive the log "ConnectivityManager.CallbackHandler(25762): callback not found for CALLBACK_IP_CHANGED message".
It's a weird behavior, the Future dosent wait anymore just go through the rest of the code.

My code is like this:
bool result = await WiFiForIoTPlugin.connect(ssid: 'wifi_ssid: 'wifi_password', security: NetworkSecurity.WPA, );

In the morning it was working normally. When calling the .connect, the cell phone's wifi was disabled and I tried to connect to the network I informed.
Now it just goes straight through and returns false.
I haven't really touched anything from the morning version to the now, it's very strange behavior

@daadu I dont get the "forceWifiUsage" after i connect to the wifi network i have to call this method?

@daadu
Copy link
Member

daadu commented Oct 2, 2021

@Mluan any clue in the logs? Why it is not connecting.

forceWifiUsage needs to be called to access network through the connected wifi, also while it is enabled network calls through main network (with internet) does not work so you should disable it when you want to use that. This is the reason it is not enabled by default by the app.

@lucaslannes
Copy link

Hello, @daadu, first thanks for the great plugin.

I think that you forgot to add the forceWifiUsage documentation in the dart-side like is described on java-side.

/// Method to force wifi usage if the user needs to send requests via wifi
/// if it does not have internet connection. Useful for IoT applications, when
/// the app needs to communicate and send requests to a device that have no
/// internet connection via wifi.
/// Receives a boolean to enable forceWifiUsage if true, and disable if false.
/// Is important to enable only when communicating with the device via wifi
/// and remember to disable it when disconnecting from device.

Maybe this can solve the issues like #154 and #160.

Do you agree?

@daadu
Copy link
Member

daadu commented Mar 24, 2022

@lucaslannes I have added it in readme, for wifi_iot the docs are not at par. New plugins will have proper API docs.

@lucaslannes
Copy link

Calling forceWifiUsage(true) after a success connection (using withInternet: false) solved my problem to connect to the IoT socket server. Without enabling the forceWifiUsage on Android 10+ the app cannot connect to the IoT device through Socket.connect(ip, port).

But testing on Android less than 10 (in my case Android 8), there is no need to call forceWifiUsage(true) to establish the socket connection.

@daadu
Copy link
Member

daadu commented Mar 27, 2022

@lucaslannes Android API (esp. for WiFi) is mess, so try to be as redundant as possible!

@Adrianvcp
Copy link

Do we have any update on this issue? How can we use it.

@Heidelbergg
Copy link

Any updates yet?

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

6 participants