简体   繁体   English

Flutter | 物联网 | Http SoftAp 配置后请求失败

[英]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 …发送请求将完美地工作......

  • again, after closing the app completely and opening it again.再次,完全关闭应用程序并再次打开它。
  • with a smartphone (which was not involved in the provisioning).使用智能手机(未参与配置)。
  • with postman.与 postman。
  • if the provisioning is done via Apple Home.如果配置是通过 Apple Home 完成的。
  • if the app is freshly opened after provisioning with the ESP SoftAP Prov app.如果应用程序是在使用ESP SoftAP Prov应用程序配置后重新打开的。

Sending the request won't work …发送请求将不起作用...

  • if the provisioning is done in the app.如果配置是在应用程序中完成的。
  • if the app is running in background, while provisioning with the ESP SoftAP Prov app.如果应用程序在后台运行,同时使用ESP SoftAP Prov应用程序进行配置。

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();

Packages套餐

I'm using the following packages:我正在使用以下软件包:

  • bonsoir: ^2.0.0 (find the devices in my WiFi) bonsoir:^2.0.0(在我的 WiFi 中找到设备)
  • http: ^0.13.5 (send requests) http:^0.13.5(发送请求)
  • chopper: ^4.0.6 (send requests)斩波器:^4.0.6(发送请求)
  • esp_provisioning_softap: ^1.0.3 (add the ESP to my WiFi) esp_provisioning_softap:^1.0.3(将 ESP 添加到我的 WiFi)
  • wifi_iot: ^0.3.18 (connect to the ESP to provide WiFi credentials inside my app) wifi_iot:^0.3.18(连接到 ESP 以在我的应用程序中提供 WiFi 凭据)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM