MQX 3.8 http server submit a form?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX 3.8 http server submit a form?

6,724 Views
Tim562
Senior Contributor I

Hi All,

 

     Is there any way to submit the data from a form (on a webpage served by the MQX http server) to the MQX http server so that it can be processed by my application? Thanks!

 

~Tim

Labels (1)
Tags (1)
0 Kudos
4 Replies

361 Views
dspNeil
Contributor III

Have a look at the web_hvac demo provided with MQX. Specifically, hvac_input.html does just this with the form named "HVAC".

0 Kudos

361 Views
Tim562
Senior Contributor I

Hi dspNeil,

 

     Thanks for your reply. I've looked at the HVAC demo and it's close to what I need to do but missing one critical piece. I need to be able to upload the contents of a file from the remote PC client that's displaying the HVAC webpage to the httpd server. I need to do this for the purpose of uploading a new application binary for my bootloader to the TWR-MPC-5125 module.

 

     The HVAC demo does send the value of the various <input /> fields (temp, unit, fan, etc) on the HVAC page to the cgi_hvac_output() function when the "Set" button is clicked. But when I added a <input type="file" name="img_file" /> input to the HVAC form all I got in the cgi_hvac_output() function was the name of the file selected by the user. I need to know how to send the file data to the cgi function and how to receive/decode it once it's been sent.

 

    The HVAC demo is real good but there's so little documentation on the MQX httpd server that if there's no example code to review I'm not sure how to proceed. If anybody has any suggestions on this or can offer any guidance I would really appreciate it. Thanks!

 

~Tim

0 Kudos

361 Views
Tim562
Senior Contributor I

Hi All,

 

     I've worked some things out with regards to sending the contents of a file back to the httpd server with the HVAC webpage but I have a question that I'm hoping somebody can help with.

 

     The key to getting the webpage to send the contents of the file when the "Submit" button is clicked on the form was to add the ENCTYPE="multipart/form-data" line to the <form /> tag like this:

 

<form name="HVAC" action="http:hvacoutput.cgi" ENCTYPE="multipart/form-data" method="POST">

<input type="file" id="img_file" name="img_file" />
... other <input /> tags as required

<input type="submit" value="Set">
<form />

 

Now, when the following code in the cgi_hvac_data(HTTPD_SESSION_STRUCT *session) function is run, the contents of the user selected file appears in "buffer" (along with values for the other <input /> tags).

 

if(session->request.content_len)    {    length = session->request.content_len;    length = httpd_read(session, buffer, length);    buffer[length] = 0;    }

 

But, the MQX functions that were being used to parse the values from the various <input /> tags:

 

httpd_get_varval(session, buffer, "unit", unit, sizeof(unit))

no longer work properly. This is probably because the data stored in "buffer" is arranged differently and the functions are unable to isolate the "input=value" pairs. I'm sure I could write my own functions to parse the data in "buffer" to extract the "input=value" pairs data along with the contents of the file but I'm wondering if MQX already has functions to do this?

 

Thanks!

 

~Tim

 

 

 

 

 

 

 

 

 

0 Kudos

361 Views
pbanta
Contributor IV

Hi,

I want to do the same thing you have done here.  Were you able to resolve the issue with httpd_get_varval() ?

Thanks,

Paul

0 Kudos