Temporary Network while trying to connect to my ESP32 via wifi?

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) sel…


This content originally appeared on DEV Community and was authored by Delfi No

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?


This content originally appeared on DEV Community and was authored by Delfi No


Print Share Comment Cite Upload Translate Updates
APA

Delfi No | Sciencx (2024-10-13T17:17:15+00:00) Temporary Network while trying to connect to my ESP32 via wifi?. Retrieved from https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/

MLA
" » Temporary Network while trying to connect to my ESP32 via wifi?." Delfi No | Sciencx - Sunday October 13, 2024, https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/
HARVARD
Delfi No | Sciencx Sunday October 13, 2024 » Temporary Network while trying to connect to my ESP32 via wifi?., viewed ,<https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/>
VANCOUVER
Delfi No | Sciencx - » Temporary Network while trying to connect to my ESP32 via wifi?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/
CHICAGO
" » Temporary Network while trying to connect to my ESP32 via wifi?." Delfi No | Sciencx - Accessed . https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/
IEEE
" » Temporary Network while trying to connect to my ESP32 via wifi?." Delfi No | Sciencx [Online]. Available: https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/. [Accessed: ]
rf:citation
» Temporary Network while trying to connect to my ESP32 via wifi? | Delfi No | Sciencx | https://www.scien.cx/2024/10/13/temporary-network-while-trying-to-connect-to-my-esp32-via-wifi/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.