[英]Flutter | IoT | Http Request fails after SoftAp Provisioning
With my Flutter app on Android I can add an ESP to my WiFi and send requests to it.通过我在 Android 上的 Flutter 应用程序,我可以将 ESP 添加到我的 WiFi 并向其发送请求。
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.我首先连接到 ESP 自己的 WiFi,接下来我提供我的本地 WiFi 凭据并通过 SoftAp 配置应用配置。 After that the ESP and my smartphone are in the same local WiFi and i can discover the ESP.
之后,ESP 和我的智能手机处于同一个本地 WiFi 中,我可以发现 ESP。 I choose the ESP and send an authentication request, which results in this Error message:
我选择 ESP 并发送身份验证请求,这导致出现以下错误消息:
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 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:我通过将以下行添加到我的 OnWillPop 方法来解决我的问题:
await WiFiForIoTPlugin.forceWifiUsage(false);
Somehow the forceWifiUsage had problems using WiFi.不知何故,forceWifiUsage 在使用 WiFi 时遇到了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.