### Author Topic: HTTPPost for two sets of parameters  (Read 2217 times)

#### Bua

• Sr. Member
• Posts: 34
##### HTTPPost for two sets of parameters
« on: March 25, 2014, 11:28:51 PM »
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
Code: [Select]
`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
Code: [Select]
`~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

#### Bua

• Sr. Member
• Posts: 34
##### Re: HTTPPost for two sets of parameters
« Reply #1 on: March 26, 2014, 06:13:23 AM »
I guessed there is not an easier way, so I re-wrote the HTTPPostSetting function.  It is a bit inefficient, but it works now.

Code: [Select]
`static HTTP_IO_RESULT HTTPPostSetting(void){ BYTE* cDest;        int paraValue; #define SM_POST_PP_READ_NAME1 (0u) #define SM_POST_PP_READ_VALUE1 (1u)        #define SM_POST_PP_READ_NAME2 (2u) #define SM_POST_PP_READ_VALUE2 (3u)        switch(curHTTP.smPost)        {                // Find the name                case SM_POST_PP_READ_NAME1:                        // 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_VALUE1;                        // No break...continue reading value                // Found the value, so store the number of cycles value to stretchLimit                case SM_POST_PP_READ_VALUE1:                        // 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;                        else                            cDest = NULL;                        // 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_NAME1;                            break;                        }                        // Get the value as an integer                        paraValue = atoi(cDest);                        stretchLimit = paraValue;                        curHTTP.smPost = SM_POST_PP_READ_NAME2;                        // No break...continue reading another name                         // Find the name                case SM_POST_PP_READ_NAME2:                        // 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_VALUE2;                        // No break...continue reading the second value                // Found the value, so store the deceleration value to stopValue                case SM_POST_PP_READ_VALUE2:                        // If value is expected, read it to data buffer,                        // otherwise ignore it (by reading to NULL)                        if(!strcmppgm2ram((char*)curHTTP.data, (ROM char*)"deceleration"))                            cDest = curHTTP.data;                        else                            cDest = NULL;                                                // 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_NAME2;                            break;                        }                        // Get the value as an integer                        paraValue = atoi(cDest);                        stopValue = paraValue;                    // 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;}`

Cheers,
Bua