2020-06-08 04:51 PM
I hope this question is not off topic.
I have a board running httpd using a STM32F407. The web server is running CGI and SSI. The cgi file is named index.shtml and is called when the browser first accesses the website.
In the SSI part of the code I populate the browser with check boxes and a input box. The idea is the user will enter text into the text box. I will use the input and update variables in the application.
In the SSI part of the code, I have this code:
if (BLUON == false)
{
char myStr5[] = "<input value=master_port name=\"led\" \"text\">";
strcpy(pcInsert, myStr5);
asm("NOP");
asm("NOP");
return strlen(myStr5);
}
The master_port I am using for the input value is a global variable that is assigned a value when the board starts. The value of master_port is 3333. That is what I want to see in the text box when the browser accesses the site. However, as shown in the jpg attached, I just see master_port.
Is there documentation somewhere that can show me how to accomplish what I want? If I enter a new number in the text box, it does not get passed back to either the cgi or the ssi functions in my code. The check boxes do work since they return a value of 1 to the cgi function if they are checked. Apparently there is no such attribute for a text box.
The big problem I have I that I don't have any html experience. I have read some tutorials online but they all reference using php to control incoming data. The STM32 apparently supports Javascript. I need to have 7 text (input) boxes on the webpage. They will be populated with variable data when the web site is accessed. The user will be able to change the data. When it is sent to the board, all the variables will be updated and stored in an on board eeprom.
Do I need to create the text boxes in the html code and use some kind of Javascript to handle user input? Will Javascript allow access to the global C variables that are in the rest of my application code? Is CGI and SSI the way to accomplish this?
2020-06-09 04:35 AM
Hello,
you have to format your myStr5 variable dynamically at runtime to fill in the value of variable "master_port". This can be achieved by snprintf, e.g.
Moerover, when you use snprintf, you can omit the variable myStr5 and write directly to your pcInsert variable. Replace LENGTH_OF_PCINSERT with the size of pcInsert or use sprintf, if you are sure the size of pcInsert is sufficient in any case.
if (BLUON == false)
{
char fmt[] = "<input value=%d name=\"led\" \"text\">";
snprintf(pcInsert, LENGTH_OF_PCINSERT, fmt, master_port);
asm("NOP");
asm("NOP");
return strlen(pcInsert);
}
See the internet, e.g. here https://www.w3schools.com/tags/tag_input.asp to learn about the form, input and label tag and to see, how textbox input is returned to the server.
You may use javascript to handle user input, but as javascript is executed in a browser sandbox, it cannot access your server's C variables.
2020-06-09 10:52 AM
Rainer,
Thanks for the comments. I will try your suggestions and monitor the traffic with Firefox or Wireshark to see what is being sent and received. I had looked at some of the w3schools.com examples. But the examples depend on responses from their server which is hidden from you so you don't know what is happening behind the scenes.
2020-06-09 02:17 PM
Hello,
maybe this helps: https://www.w3schools.com/html/html_forms.asp , look for the headline "When to use GET?". GET is the easier method to return data to the server.
The data is returned by the browser in that way, that the parameter/value pairs in the format <name>=<value>, preceeded by a '?', are appended to the original URL. <name> is the name of the input element and <value> is the content of the input element. More than one parameter=value pairs are separated by '&'. PHP will do the parsing of parameter=value pairs automatically and supply them in $_GET. As your MCU does not run PHP but C, you have to do the parsing yourself.
2020-06-09 08:46 PM
Rainer,
With your snprintf suggestion and the link suggestions, I have everything working. I only have 5 text boxes and they are all created within the SSI function. Each box is assigned a different name and I parse the data in the CGI function for each box based on the name. I then use snprintf to write the user updated information back to each box.
I tried for a few hours to create the text boxes in the html code. But apparently there is no way to access the html boxe data from within the CGI or SSI functions. If there is a way to do that I could not figure it out. When the form is submitted to the server I'm sure the data appears somewhere. But since my application is working I am not going to worry about it. Searching online for hours never turned up anyone using text boxes and httpd with an embedded STM32 part. I did find one person who was doing it with an RTOS but I don't need the overhead of that.
Thanks for all the help.:beaming_face_with_smiling_eyes:
2020-06-11 02:29 PM
The real bi-directional exchange of any data (not only text like with URL) between HTML page and web server can be done with AJAX. For that to work the web server needs POST request support. lwIP's httpd can do it, but it's not trivial.
Here are a series of blog posts that explains the principles of this method:
2020-06-11 05:37 PM
When I was poking around in the lwip files I remember reading somewhere that POST requests would be ignored. I don't remember if it was in the CGI or SSI parts of lwip code.
It would be nice if ST would create a document telling how to implement POST on the STM32 parts. I don't need it for my application as it is on a private network. But I can see it as being nice to have the option to use it if needed. And it should be able to work without an RTOS.