• 0
sgandhi

Using the C variable in javascript code for lwip in sdk

Question

Hello, 

I am working on lwip webserver in vivado 2018.1. The code for the webserver is in C language. I want to create a dynamic webpage that displays the value of the 32-bit system register according to my application. I came across the lwip documentation that uses an example for the web server. However, it is in 2014.3 and that creates a problem when I use it in 2018.1! Also, there is memfs folder in it that contains the .js, .css files and all! The example creates some image.mfs in ddr memory location!

In my case, I have created a const char [ ] that has html code inside and I pass it in tcp_write( ) and the web page gets displayed! It works. I have also created javascript code in the html code itself that dynamically changes the content on the webpage through button onclick event. However, I want this to be change using the C variable in my code. So, how do I link the C global variable or local variable to the javascript?

 

In simpler way, I tried to declare a global variable say UINT a=10. Then, on button onclick event, when javascript is executed, I tried to change the content on webpage using the variable "a". But it doesn't work!

Does anyone knows how to make my C code and javascript code work together?

For reference, I am attaching the html and javascript code below:

const char testdata[]= "<html>
                                         <body>
                                         <button onclick=\"start()\"> Start the countdown </button>
                                         <p id=\"demo\"> This the main page for the test application of the web server...</p>
                                         <p id=\"ch1\"> Change me with variable a...</p>
                                         <div id=\"bip\">
                                         </div>
                           

                                         <script>
                                         var counter = 10;
                                         var intervalId = null;
                                         function finish()

                                          {
                                         clearInterval(intervalId);
                                         document.getElementById(\"bip\").innerHTML = \"THE END!\";
                                         if(counter == 0) {
                                         var xhttp = new XMLHttpRequest();
                                         xhttp.onreadystatechange = function(){
                                         if(this.readyState == 4 && this.status == 200){
                                         document.getElementById(\"demo\").innerHTML =
                                         this.responseText;
                                         }}
                                         }
                                         xhttp.open(\"GET\", \"ajaxinfo.txt\", true);
                                         xhttp.send();
                                           }

 function bip()

{
if(counter == 0) finish();
else {
document.getElementById(\"bip\").innerHTML = counter + \" seconds remaining\";
}
counter--;

}
                            function start() {  intervalId = setInterval(bip, 1000);}
</script>
</body>
</html>";

I want to replace any <p> element with a global variable that will be declared in the C code that has this html code inside a const char array as shown above.

Any help is highly appreciated.

Thanks, 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Is this a bare metal application only with no Linux involved?

If yes, I will move the thread to the FPGA section.

thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now