This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trouble showing data in webpage, enet_lwip example, javascript-c functionality



Hi fellows I’m working with a ek-tm4c1294l board, with the enet_lwip example. I’m having problems showing some data when I load a webpage. To achieve this I’m using HTTP requests in javascript, and the webpage is programmed in HTML.

I’m trying to show an integer variable which I get from the board. The strange fact is that sometimes I see the variable and sometimes not, in a kind of random way , as you can see in the following images, respectively:

The javascript function used is:

<script>

//function executed when the webpage is load

function Historial(){

 

var req = false;

    function nReturned()

    {

        if(req.readyState == 4)

        {

            if(req.status == 200)

            {  

                n = req.responseText;

                document.getElementById("prueba").innerHTML = "<div>" + n + "</div>";

    

                    

              }

        }

         

    }

 

    if(window.XMLHttpRequest)

    {

        req = new XMLHttpRequest();

    }

        else if(window.ActiveXObject)

    {

        req = new ActiveXObject("Microsoft.XMLHTTP");

    }

    if(req)

    {

        req.open("GET", "/hist_def?id=" + Math.random(), true);

        req.onreadystatechange = nReturned;

        req.send(null);

    }

}

 

</script>

And the C code who executes the URL of the request:

//c code

if(ustrncmp(pcName, "/hist_def", 8) == 0){

           def++;

                                

          static char pcBuf[6];

          h_inicial(pcBuf);

         

                              

          psFile->data = pcBuf;

          psFile->len = strlen(pcBuf);

          psFile->index = psFile->len;

          psFile->pextension = NULL;

                     

          return(psFile);

                              

 }  

 

// h_inicial() function

void h_inicial(char *inic_data){

 

     while(pd>pe){

          n++;

          pe++;

     }

 

     pe=med;

     sprintf(inic_data, "%d%", n);

}            

 

<!—html code -->

<p id="prueba"></p>

 

The h_inicial() function returns the difference between two pointers pd and pe in an integer variable (n) .

I do the HTTP request following the example of the enet_lwip, and enet_io code. So If anyone could advice me in anyway please do it!

Thanks in advanced, regards!

Matias Kormos