I am using the Nano33IOT for a project where I would like to have the user configure the wifi to connect to whatever network is available. All of the examples with the WifiNINA library, etc use a compile time set SSID and password. The Wifi.begin function takes const char* ptr which only seems to work if the thing that is being pointed to is a compiled string. (ie one in "quotes").
So this isn't specifically about the Nano I'm wondering if anyone has figured out a work-around this. For example is there a modified library that allows a more general char or string to be passed, even by value?
I figured it out. I can do this with a const char* pointers to a char array. My problem that I'm still working on is that the string.length() is giving me the wrong result.
Here's the code I eventually settled on. curid and curpwd are strings. the buffer declarations are ssid[30] and pass[30].
if(curid.length()<=curid.indexOf(0x0D)){
clen = curid.length();
} else {
clen = curid.indexOf(0x0D);
}
if(curpwd.length()<=curid.indexOf(0x0D)){
plen = curpwd.length();
} else {
plen = curpwd.indexOf(0x0D);
}
curid.toCharArray(ssid,clen+1);
curpwd.toCharArray(pass,plen+1);
Just as a friendly brain stimulus, I found it interesting that you are using Strings in your Arduino sketch, but you seem to prefer const char in your brain and source code for your variable names.
Since both your PC and your brain seem to be much better equipped to handle longer strings than your Arduino, maybe it’s time to break with old habits. 