With my Flutter app on Android I can add an ESP to my WiFi and send requests to it.
However provisioning and sending requests are working perfectly on their own, but not in direct succession.
Goal is to do the whole connection handling inside the app:
I start with connecting to the ESPs own WiFi, next i provide my local WiFi credentials and apply the config through SoftAp provisioning.
After that the ESP and my smartphone are in the same local WiFi and i can discover the ESP. I choose the ESP and send an authentication request, which results in this Error message:
E/flutter (31739): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Connection failed
E/flutter (31739): #0 IOClient.send (package:http/src/io_client.dart:88:7)
E/flutter (31739): <asynchronous suspension>
E/flutter (31739): #1 ChopperClient.send (package:chopper/src/base.dart:305:23)
E/flutter (31739): <asynchronous suspension>
E/flutter (31739): #2 ESPDevice.sendRequest ([...filepath...])
E/flutter (31739): <asynchronous suspension>
Sending the request will work perfectly …
Sending the request won’t work …
Here is my (simplified) Code:
await WiFiForIoTPlugin.connect(ssid, password: password);
await WiFiForIoTPlugin.forceWifiUsage(true);
Provisioning provisioning = Provisioning(transport: TransportHTTP(hostname: '192.168.4.1:80'), security: Security1(pop: pop));
await provisioning.establishSession();
await provisioning.sendWifiConfig(ssid: newSsid, password: newPassword);
await provisioning.applyWifiConfig();
await WiFiForIoTPlugin.disconnect();
OnWillPop
await provisioning.dispose();
await WiFiForIoTPlugin.disconnect();
I'm using the following packages:
I fixed my problem by adding the following line to my OnWillPop Method:
await WiFiForIoTPlugin.forceWifiUsage(false);
Somehow the forceWifiUsage had problems using WiFi.