-->
Page 1 of 1

Insert variable in HTML server (ESP8266)

PostPosted: Sat May 12, 2018 9:18 am
by Piergiusepp1996
Hy guys, I crated a server on my esp and the HTML code is this:

<form>
<label for="ssid"><b>SSID</b></label>
<input type="text" placeholder="Enter SSID" name="ssid" required>

<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>

<button type="submit">Invia</button>
</form>

I need to save what I write in ssid and psw form in a local variable (char*) called SSID and password.
How can I do that?
Thanks to all

Re: Insert variable in HTML server (ESP8266)

PostPosted: Tue May 15, 2018 7:53 pm
by svideo
Because you're going to allow the user to enter data you are going to need to start with allocating enough room in your char for the SSID and password. Try something like this for defining those values:

Code: Select allchar wifiSSID[33] = "defaultssid";
char wifiPass[64] = "defaultpass";


To prevent problems you might want to use the "maxlength" HTML tag on your inputs, like this:
Code: Select all<input type="text" placeholder="Enter SSID" name="ssid" required maxlength="32">
<input type="password" placeholder="Enter Password" name="psw" required maxlength="63">


Finally, to grab those values in the handler function for this page, do something like the following:
Code: Select allserver.arg("ssid").toCharArray(wifiSSID, 33);
server.arg("psw").toCharArray(wifiPass, 64);

Re: Insert variable in HTML server (ESP8266)

PostPosted: Mon May 28, 2018 8:10 am
by Piergiusepp1996
Thank you very very much!