Questions about LwIP POST Operation
I have a custom STM32F407 board that I have been working with over the last month or so. I developed a httpd application using the STM32CubeIDE tool. I am using GET to control my devices and everything works as planned.
I have a couple of spare boards so I have been digging deeper into the LwIP functions to get a better understanding of how they work. I am trying to figure out how POST works. I have been able to get it to work on my board up to a certain point.
I can send a POST request to the board and take action based on the contents of the message. I have two text boxes on my index.html page. I can turn LEDs on or off depending on what I put into the text boxes. Before I close the connection, I can display different pages on the board's website depending on what information was in the text boxes when the POST was sent. The POST code is shown here:
err_t httpd_post_begin(void *connection, const char *uri, const char *http_request,
uint16_t http_request_len, int content_len, char *response_uri,
uint16_t response_uri_len, uint8_t *post_auto_wnd)
{
snprintf(response_uri, response_uri_len, "/newndx.html");
return ERR_OK;
}
err_t httpd_post_receive_data(void *connection, struct pbuf *p)
{
char *ret, readval [100];
strcpy(readval, p->payload);
ret = strstr(readval, "Jack");
if(ret != NULL)
{
HAL_GPIO_WritePin(ETH_GPIO_Port, ETH_Pin, 1);
}
ret = strstr(readval, "newndx");
if(ret != NULL)
{
HAL_GPIO_WritePin(ETH_GPIO_Port, ETH_Pin, 0);
strcpy(inputval, "newndx"); // inputval is a global variable
}
pbuf_free(p);
return ERR_OK;
}
void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len)
{
char *ret;
ret = strstr(inputval, "newndx");
if(ret == NULL)
{
snprintf(response_uri, response_uri_len, "/newndx.html"); // show default page
connection = NULL;
}
if(ret != NULL)
{
snprintf(response_uri, response_uri_len, "/index.html"); // go back to home page
connection = NULL;
}
}The one thing I haven't been able to figure out is how to return information to the browser to change the contents of the text boxes using POST. Assume I have "Jack" in box one and "Sprat" in box two and I want to return "Sponge" to box one and "Bob" to box two. How would I do that?
What if I want to use POST to check the status of a relay on the board? I can get the status of the LED in the httpd_post_receive_data function easily enough. How would I return a variable to indicate the relay status and display it in the browser?
Both of these are simple to do with GET but maybe it isn't possible with POST?
