🔧 Temporary Network while trying to connect to my ESP32 via wifi?
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
Hey everyone,
I have a simple project where I wanted to create an app to communicate with my ESP32. In fact, the app should be able to do the following things:
- scan WIFIs for an ESP device (filter for an certain SSID)
- connect to the (by the user) selected wifi
- get and post JSON data via that wifi connection
I setup a simple server on the esp32 with an simple API. I also wrote the flutter app that first scans available networks for networks that could belong to my ESP32. I used this code for connecting to that wifi:
Future<void> connectToESP32() async {
await WiFiForIoTPlugin.connect(
esp32SSID, // SSID des ESP32
password: "12345678", // if there is a password
security: NetworkSecurity.WPA,
joinOnce:
true,
withInternet:
false,
);
await checkConnection();
}
The code to send the API request is:
final response = await http.post(
Uri.parse('http://123.567.8.9/save'), // not the real ip
headers: {'Content-Type': 'application/json'},
body: jsonEncode(data),
);
Now the problem:
I have been testing it on android and when you connect to the wifi using the app, an android popUp occurs telling the user that the app tries to connect to an device via wifi and that a temporary wifi connection will be made. When you look in the wifi menu of android after that, you can see that there is an established "temporary" connection to the esp32 wifi. When I try to send the API request, it fails because it cannot establish a connection to the server. I found, that the request is not sent via this wifi connection because android recognizes that this connect has no internet and therefor cannot send API requests. When I connect to that wifi manually, enter the password and click on "hold connection without internet" and then send the request, it works.
Sure, I could redirect the user to the wifi menu and explain that he has to connect manually to the wifi and he has to disable his mobile internet connection, but that is not pretty. I'd rather use the the temporary wifi connection, to connect and communicate to the device, but I have no idea how I would do that.
Does anyone know more to that topic?
...
🐧 Trying to connect to the network
📈 22.79 Punkte
🐧 Linux Tipps
🐧 Trying to connect to the network
📈 22.79 Punkte
🐧 Linux Tipps