I am creating a project where my Arduino Nano IoT 33, needs connection to Internet (and it's crucial indeed), so I do use flutter_blue_plus to send all the data gathered in my app created in flutter, to send it to Arduino via bluetooth. The problem is, when gathering that data (which involves SSID and password), there are no libraries that can actually check if the password introduced by the user, is correct or not (I have tried several ones, such as wifi_IoT). They all authenticate with the credentials, leading the app to lose internet connection, as you can see in this image:
This is the code that I used:
//Try to connect using WiFiForIoTPlugin with findAndConnect
bool connectionSuccessful = await WiFiForIoTPlugin.findAndConnect(
ssid,
password: password,
withInternet: false,
);
print("Connection result: $connectionSuccessful");
if (!connectionSuccessful) {
_showErrorMessage("Could not connect to the Wi-Fi network.");
return; // Stop the flow if the connection failed
}
// Verify if we are connected to the desired SSID
final connectedSSID = await WiFiForIoTPlugin.getSSID();
if (connectedSSID != ssid) {
_showErrorMessage("Connection to the expected SSID was not completed. Please check the password.");
return; // Stop the flow if the SSID does not match
}
// If everything is successful, navigate to the next screen
Get.to(() => AEMETAPIScreen(
user: widget.user,
password: widget.password,
localidad: widget.localidad,
wifi: ssid,
wifiPassword: password,
));
} catch (e) {
_showErrorMessage("Error while attempting to connect: $e");
}
When I use withInternet: true
This code is returned from the Network log even if the password is wrong introduced by the user.
Status: 0
And also the boolean variable connectionSuccesful, follows a pattern too, first time of execution of the function (does not depend on the password input if it's correct or not according to the SSID) returns false, then, clicked again returns true, and navigates to the next screen.
So basically, it navigates always even if the password is incorrect.
I have also used "connect()" instead of "findAndConnect()" function but still does the same.
I even tried to implement the same idea in a lower abstraction language: using Kotlin. But even that way, I get the same pop up with the same notification, and the app loses again connection (which is also crucial, because I use the flutter MQTT library later on the app).
Other libraries that I have tried, seem to do the same process (Show pop-up, access to the next page, lose connection to Wi-Fi making the user have to manually restart it and navigate to the next screen even if the password is not correct).
I truly want to avoid the idea to just bypass the password introduced and send whatever writes the user in the parameter.
I would suggest sending the SSID and password as a parameter to the Arduino, and then attempting to connect to the WiFi using the WiFi library for Arduino. You can return a success value from your Arduino code if the connection is made, and then continue authentication on your app. Otherwise, you can use a timeout alongside the Arduino's WiFi connection attempt to return a failure value to your app.