Question about the example "Html File Reader with Dynamic Token Replacement"

If I run the example “Html File Reader with Dynamic Token Replacement” (Link:

what IP adresse should I type in the webbrowser, so that I can see the result of html pages?

Workhard, you should type the IP address of your device. You will need to open the code and examine it.

Or even use MFDEPLOY to check the network configuration of the module…

I want to use the classes in the example “348”, so I have tried the example “363” to learn the classes for a long time.

The example"363" is for “FEZ Panda” and I have only “Cobra”. The example “363” is very hard and complicated for me, there are too many claases in the example.
I have tried changed the example many times, but it can’t run on my Cobra.

Can you give me some tipps, how I can run the example “363” on my Cobra?

I really want to know, how I can show the live data (for example real time clock) of Cobra on a webbrowser, if I type a IP in the webbrowser.

Workhard, we really need a lot more info about what you want to do.

Example 348 is a HTML token replacement. So you have a “variable” within your code, and your HTML simply has a “token” that jasdev’s code replaces with the value of the variable. So it’s perfect for say displaying the Cobra’s system time onto a web page.

You must take this in small steps.

Do you have a working knowledge of HTML code that renders content in a browser? If not, you need to look at static HTML pages and understand what they’re doing.

Do you have a working knowledge of how to get Fez Cobra to serve HTML pages to a browser? If not, use the simplest example possible and understand how to get it working.

I have a Cobra and perhaps some time one night this week. How about we start working through this together? (I’m going to use 4.1 framework; are you using 4.1 or 4.2?)

@ Brett -

Thank your for help! I use 4.1 framework. I haven’t any working knowlege of HTML and browser. I have lerned some knowlege about html, javascript and CSS, but I think it’s not enough, I still can’t build a webpage, where I can see the live data of Cobra.

I have built a 16 channels temperatur circuit board, the circuit consists a ADC(SPI interface) and two 8-channel-MUX, the SPI of Cobra can control the circuit board and read the temperatur-input, I can see the live data of 16 temperatur-input with LCD. The timing of LCD is 1 second. The LCD can also show me the status of 3 buttons(press or release), I have defined Inputport for GPIO of buttons.

Now what I want is, I want to show these information( live data of 16 temperatur and status of 3 buttons) with webbrowser. if I type the IP of Cobra in a webbrowser. We have discussed about the example 315 about 3 weeks ago, it seems like what I want, but the example refers to “Adobe Flex”, I have no idea about it, so I give up the example 315. I think these is much better method to resolve my thinking.

I have some knowlege about the webserver, it refers to http “GET” and “POST” and Socket, but I have too little experience to resolve my thinking . I have investigated many examples with “google” but I didn’t find a good tutorial for my thinking. I’m am very confused that some html , image and CSS files are saved in a “Resources folder” or saved in SD card, then these files will be invoked.

If possible I want a example that there are 20 variable in cs file, the variables are int and they are in a timing (1 second). 16 variables will be incremented form 1 to 100 periodly with funktion “Random()” , the other 4 variables wait the data from webpage. If I type a IP in browser, I can see the 16 live variables and they are running from 1 to 100 periodly. they are 4 leer box on the webpage, if I type a value in the box and press a button for send on the webpage, the value will be sent to the other 4 variables in cs file. The webpage html file is save in “Resources folder” or in SD Card. I am interesting in the two situations.

Thank you again for your help.

Breaking the project down into chunks is great. So for now, you have the temperature and other aspects sorted, and you have the LCD stuff sorted. So now lets just do the webserver stuff and not focus on integrating that with the other code, but lets keep that as a goal in mind.

First, lets ignore the incrementing, lets go with showing the time when the page is refreshed.

Here’s what I am going to do as first step.

Grab Wouter’s code, and make it work.

See you back here tonight (~11hrs)

I’ve created the shell of this.

Create a new empty Project, using the Fez Cobra Console application template.

The image attached is the added files and references. I am away from my Cobra but it builds successfully with these added. is a zip of my project (it won’t include Wouter’s files, they’re external to that file structure).

Let me know when you get to that point ! :slight_smile:

@ workhard10 - Sorry I can’t help you with this. I don’t have a development system setup here where I’m living now. If I get a chance this weekend, I will port the web server project to the Cobra and post it to codeshare.

@ Brett - Thanks again for your help.

OK, that project deployed to my Cobra first go. I then went into MFDeploy and set my IP address right, and when I went to the assigned IP address in my browser I got the default page come up - which is a simple HTML form that has some fields for first/last name and email address. So first up, we’re making progress.

Fill in the form and POST the form. Voila, the second page comes up.

The resultant posted message, the results page, is actually using variables in the code - lets add the system time. Find the AnalyseForm handler and add this second line:

           response += "Thanks for your inquiry.";
            response += "<br /> The time you submitted this query was "+ System.DateTime.Now.ToString() ;

Go back to the original URL and refresh, fill in the form again, and there’s the new line with the time - well probably not the real time, probably some minutes and seconds after 1 January 2009, the default system time value after restart.

Nice eh? Where to next?

@ jasdev -

thank you for your help!!

@ Brett -

thank you for your example code, I have run your example code. My LCD show me the IP “” and my gate is “”

After writing the example code to EMX I type the “” to firefox, but I saw nothing.

I don’t know where is my problem.

No, I don’t think you do have that IP address, DHCP is set to ON which will override the static IP you have set. Even if that’s not the case, it’s confusing the issue…

Untick the DHCP option in MFDeploy and save that. Confirm the screen updates with the new IP address.

From your command prompt, you should be able to PING the IP address. For me, I get my first response in 5msec, the next three are each 2msec each.

@ Brett -

I have set a new IP "“” for my Cobra, DHCP is untick, PING is OK.
It seems so strange, I still see nothing from webbrowser after typing “”.

@ Brett -

… I must tell you something, my Cobra is not original Cobra. actually I have built a Cobra Demo board by myself on the basis of original Cobra board.

But the layout(Ethernet, USB, SD card, LCD) of my Demo board is the same as the original Cobra board.

I have run the “example 315” and some simple ethernet examples successfully ago, so I think the connection of ethernet is no problem.

But I am not sure, whether your example code only work in original Cobra board?

I’m online at the moment - my HOTMAIL name is my Messenger name and you can get my Hotmail account details in my profile here.

I don’t expect anything in this code to not work on a generic EMX. The fact that the Cobra enumerations are loaded shouldn’t be an issue assuming you have the standard pins working. The only thing the code does is flash the LED - oh, lightbulb just went back on !

            using (HttpServer server = new HttpServer())
                server.AddEvent("/", new HttpServer.EventCallback(sendForm));
                server.AddEvent("/form", new HttpServer.EventCallback(analyseForm));
//                server.AddEvent("/resource", new HttpServer.EventCallback(sendResource));
                while (true)
                    // Sleep for 500 milliseconds

                    // toggle LED state
                    ledState = !ledState;

I don’t think I had saved the project and I did make one update before I got home and deployed it. The LED flash needs to be within the “USING” loop otherwise the webserver goes out of scope and gets GCed.

And debug is your friend - use breakpoints

Actually I’ve just seen the time and I won’t be around for too much longer tonight (I’m in GMT+11 at the moment) - feel free to IM me though and I should see it in the morning and we can pick up a sharing session to make more progress.

@ Brett -

ok! I keep trying. We can go on tomorrow. thank you very much for your help!!!

I don’t find your Hotmail account in your profile. Is your hotmail “brett@”?

@ Brett -

Because I don’t have original Cobra board, and I have some free GPIO pins on my Cobra demo board, I have defined a GPIO pin as “OutputPort” for led definition. see as follow:

OutputPort led = new OutputPort((Cpu.Pin)EMX.Pin.IO12, true);

            using (HttpServer server = new HttpServer())
                server.AddEvent("/", new HttpServer.EventCallback(sendForm));
                server.AddEvent("/form", new HttpServer.EventCallback(analyseForm));
//                server.AddEvent("/resource", new HttpServer.EventCallback(sendResource));


            while (true)
                // Sleep for 500 milliseconds

                if (a == 1)
                    a = 0;
                    b = 1;
                else if (b == 1)
                    b = 0;
                    a = 1;

                // toggle LED state
                //ledState = !ledState;

After pressing “Start Debugging”, I can see the Square wave from the GPIO pin “IO12” with oscilloscope. I know it means the project is running in EMX. but after typing the Cobra IP in firefox webbrowser I couldn’t see the first webpage.

I set a breakpoint at “server.AddEvent(”/", new HttpServer.EventCallback(sendForm))", after pressing “Start Debugging” the programm stoppted at the breakpoint. I typied the IP at the firefox webpage and ran the programm step by step. At some time I could access the first webpage, I could see some fields as you said, after typing the fields and pressing “Submit button” I could see the second webpage.

I don’t understand why the webpage can not repond the “server.AddEvent” automatically after being given IP address.

brett_pound. It’s written in text if you search for “if you need me” or “Hotmail”

Adding a breakpoint when you’re defining the callback is not going to allow the server to run. The more likely area you’d want to use a breakpoint is in the “sendform” method itself where the form gets assembled.

You didn’t change where the while (true) loop lives like I said. In the code you have just posted, you will dispose the HttpServer object before the LED flash starts.

If you had something working before, the logical test is to put a working code back and verify that it still works with the connections the way you have it. This means the hardware still functions; but without the above change I don’t expect you’ll get this working :slight_smile: