Hi,
I kind ask for your help. Following the instruction from your article “ESP32 Over-the-air (OTA) Programming – Web Updater Arduino IDE”
https://randomnerdtutorials.com/esp32-over-the-air-ota-programming/
I’m using the Arduino IDE’s OTA WebUpdater example. In the statement:
"<center><font size=4><b>ESP32 Login Page</b></font></center>"
I’d like to replace the “ESP32 Login Page” text with a variable, but I did not success in anyway.
Could you please tell me a way to do that?
Thanks in advance.
Paul
Hi Paul.
You probably cannot do it because those variables are defined as const char* variables and it is not straightforward to concatenate const char*.
Can you try one of the suggestions in this link and see if it works?
https://stackoverflow.com/questions/1995053/const-char-concatenation
Regards,
Sara
Hi Sara, thanks for your response.
I’m afraid that my question was not clear enough and I did not make myself understood.
I’d like to replace “ESP32 Login Page” that is plain text with a variable. Being a new one I can define that variable according your instructions in order to succeed replacing the text.
Paul
In order to make that work in an easy way, you need to change these two variables to String type:
String loginIndex =
String serverIndex =
In the setup(), you need to convert them to char with .c_str():
server.on("/", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", loginIndex.c_str());
});
server.on("/serverIndex", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", serverIndex.c_str());
});
To concatenate/add a variable to your web page, it needs to be String variable and you do it with + +:
String yourVariable = "My custom message";
String loginIndex =
"<form name='loginForm'>"
"<table width='20%' bgcolor='A09F9F' align='center'>"
"<tr>"
"<td colspan=2>"
"<center><font size=4><b>" + yourVariable + "</b></font></center>"
"<br>"
(....)
Can you try that and let me know if it works for you?
Hi Paul.
Can you be more specific? Why you say it is not working? What error do you get?
We’ve tested the code, and it was working.
You can try our example here: https://gist.github.com/RuiSantosdotme/beb5723d11582b0af1701b7745d65e79
The custom variable is declared on line 13. You should change that variable with the value or text you want. But it needs to be a String.
Thank you very much Sara. I tried your example and it worked seamlessly. Even that I followed your instructions carefully, my code did not work, now I’ll check it again to find where is the problem.
Paul