Hi
I would like to make a webpage that accepted two values and passes to the main code. I modified the HTTPPostLCD, my function called HTTPPostSetting. It complied and worked OK, except for only the first value has been accepted. I can't find the way to make the code accepted the second value. Here is my CustomHTTPApp.c and settings.html.
Partial CustomHTTPApp.c
HTTP_IO_RESULT HTTPExecutePost(void)
{
DEBUG_PUT_STR(DEBUG_LEVEL_INFO, "\nHTTPExecutePost()"); //MODTRONIX added this line
// Resolve which function to use and pass along
BYTE filename[20];
// Load the file name
// Make sure BYTE filename[] above is large enough for your longest name
MPFSGetFilename(curHTTP.file, filename, sizeof(filename));
//#if defined(USE_POSTUREPLANE)
if(!memcmppgm2ram(filename, "protect/settings.htm", 20))
return HTTPPostSetting();
//#endif
#if defined(USE_LCD)
if(!memcmppgm2ram(filename, "forms.htm", 9))
return HTTPPostLCD();
#endif
#if defined(STACK_USE_HTTP_MD5_DEMO)
if(!memcmppgm2ram(filename, "uploadfile.htm", 14))
return HTTPPostMD5();
#endif
#if defined(STACK_USE_AUTOUPDATE_HTTPSERVER) && defined(WF_CS_TRIS) && defined(MRF24WG)
if(!memcmppgm2ram(filename, "upload_Image.htm", 16))
return HTTPPostImage();
#endif
#if defined(STACK_USE_HTTP_APP_RECONFIG)
if(!memcmppgm2ram(filename, "protect/config.htm", 18))
return HTTPPostConfig();
#if defined(STACK_USE_SNMP_SERVER)
else if(!memcmppgm2ram(filename, "snmp/snmpconfig.htm", 19))
return HTTPPostSNMPCommunity();
#endif
#endif
#if defined(STACK_USE_SMTP_CLIENT)
if(!strcmppgm2ram((char*)filename, "email/index.htm"))
return HTTPPostEmail();
#endif
#if defined(STACK_USE_DYNAMICDNS_CLIENT)
if(!strcmppgm2ram((char*)filename, "dyndns/index.htm"))
return HTTPPostDDNSConfig();
#endif
//Default processing of all other post commands
cmdParseHTTPPost();
return HTTP_IO_DONE;
static HTTP_IO_RESULT HTTPPostSetting(void)
{
BYTE* cDest;
CHAR paraNumber;
int paraValue;
#define SM_POST_PP_READ_NAME (0u)
#define SM_POST_PP_READ_VALUE (1u)
switch(curHTTP.smPost)
{
// Find the name
case SM_POST_PP_READ_NAME:
// Read a name
if(HTTPReadPostName(curHTTP.data, HTTP_MAX_DATA_LEN) == HTTP_READ_INCOMPLETE)
return HTTP_IO_NEED_DATA;
curHTTP.smPost = SM_POST_PP_READ_VALUE;
// No break...continue reading value
// Found the value, so store the LCD and return
case SM_POST_PP_READ_VALUE:
// If value is expected, read it to data buffer,
// otherwise ignore it (by reading to NULL)
if(!strcmppgm2ram((char*)curHTTP.data, (ROM char*)"cycles"))
{
cDest = curHTTP.data;
paraNumber = 0;
}
else if(!strcmppgm2ram((char*)curHTTP.data, (ROM char*)"deceleration"))
{
cDest = curHTTP.data;
paraNumber = 1;
}
else
{
cDest = NULL;
paraNumber = -1;
}
// Read a value string
if(HTTPReadPostValue(cDest, HTTP_MAX_DATA_LEN) == HTTP_READ_INCOMPLETE)
return HTTP_IO_NEED_DATA;
// If this was an unexpected value, look for a new name
if(!cDest)
{
curHTTP.smPost = SM_POST_PP_READ_NAME;
break;
}
// Get the value as an integer
paraValue = atoi(cDest);
switch(paraNumber)
{
case 0:
stretchLimit = paraValue;
sprintf(debugTempBuf, "\ncycles = %d", stretchLimit);
cbufPutString(CIRBUF_TX_DEBUG, debugTempBuf);
break;
case 1:
stopValue = paraValue;
sprintf(debugTempBuf, "\nstop = %d", stopValue);
cbufPutString(CIRBUF_TX_DEBUG, debugTempBuf);
break;
}
// This is the only expected value, so callback is done
strcpypgm2ram((char*)curHTTP.data, "settings.html");
curHTTP.httpStatus = HTTP_REDIRECT;
return HTTP_IO_DONE;
}
// Default assumes that we're returning for state machine convenience.
// Function will be called again later.
return HTTP_IO_WAITING;
}
}
Partial settings.html
~inc:PPheader.inc~
<div id="content">
<h1>Machine Settings</h1>
<!--
<p>Allan's testing. Updating this page and upload to the webserver using MPFS application. Hello</p>
-->
<p>Machine 1</p>
<br>
<br>
<form name="input" action="" method="post">
<table style="width:300px">
<tr>
<td>Number of Cycles: </td>
<td><input type="text" name="cycles"></td>
</tr>
<tr>
<td>Stop Calibration Value: </td>
<td><input type="text" name="deceleration"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
<script type="text/javascript">
<!--
document.getElementById('hello').innerHTML = "~hellomsg~";
-->
</script>
~inc:footer.inc~
Thanks,
Bua