10 years, 2 months ago.

webserver mbed

Hi all, I used the open source code provided by the avnet WI-GO module to build the webserver on K64F, i removed the unnecessary stuff, and got the final web page with buttons and text boxes. My button works perfectly fine, i used get request for the buttons.

In my avnet.html file i have this piece of code

 "<form method=\"get\" action=\"index.html\" name=\"server\">"


"<input name=\"ledCon\" type=\"submit\" value=\"-Red-\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
"<input name=\"ledCon\" type=\"submit\" id=\"open\" value=\"Green\">"

"</form></div>"  

I extract values of this code in demo.cpp file request handler in demo.cpp is like this :

void handleHTTPRequest(TCPSocketConnection *client)
{
    char * reqline[3];
    
   
    char * cgiTok;

    int i = 0;
    char paramBuf[20];
    int bytesRecvd;
    char tempStr[40]; //PF was 26

    memset(requestBuffer,0,sizeof (requestBuffer));
    bytesRecvd = client->receive(requestBuffer, sizeof(requestBuffer));

 if(bytesRecvd > 0)
    {
        // Received some data, check it and send data back
        reqline[0] = strstr(requestBuffer, "GET");
        postline[0] = strstr(requestBuffer, "POST");
   
            if ( reqline[0] != NULL )
        {
            if (strstr (requestBuffer, "HTTP/1.0") != NULL && strstr (requestBuffer, "HTTP/1.1") != NULL )
            {
                client->send_all("HTTP/1.0 400 Bad Request\n", 25);
            }
            else
            {

#ifdef HTTP_CGI_ENABLED
                // Do we have CGI parameters we need to parse?
                if(strchr(requestBuffer, '?') != NULL)
                {
                    // Decode URL and handle each parameter sequentially
                    // according to table previously setup.
                    cgiTok = strstr(requestBuffer,"=");
                    if(cgiTok != NULL)
                    {
                        memset(paramBuf,0,sizeof(paramBuf));
                        memcpy(paramBuf,cgiTok+1,5);     // hard-coded for demo: 5 character parameter (-Red-/Green/Blue-)
                        chList->cgiHandlerFunc[0](paramBuf);

                    }
  sendHTTPData(HTTP_RESP, strlen(HTTP_RESP), client);
                                
                for(i = 0; i < strlen(indexPage); i += HTTP_TX_BLOCK_SIZE)
                {
                    if(strlen(indexPage) - i < HTTP_TX_BLOCK_SIZE)
                    {
                        sendHTTPData(&indexPage[i], strlen(indexPage) - i, client);
                    }
                    else
                    {
                        sendHTTPData(&indexPage[i], HTTP_TX_BLOCK_SIZE, client);
                    }
                }
            }

I have made some text boxes as well, so that i can enter some text in it, my next challenge is to extract values from those text boxes, can any one help me out, i know i have to add some post form in avnet.html file, but i am lost how can i extract those values in demo.cpp file..

your help would be appreciated.

thanks in advance,

Zain

I sorted out the problem, i created simple text boxes and button with get request in avnet file. and made few changes in demo.cpp like replacing 5 in memcpy(paramBuf,cgiTok+1,5) with 55, because now i am getting value of 3 textboxes so i am supposed to get longer string. every thing is working fine :)

posted by zain aftab 19 Sep 2014
Be the first to answer this question.