I’ll explain. string content is an html code. Using that code I can create an interface (buttons and other stuff.) How can I send back the data I’ve collected in order to control the gadgeteer? (Turning the led on for example)
The code:
public partial class Program
{
GT.Networking.WebEvent sayHello;
void ProgramStarted()
{
ethernet.UseDHCP();
ethernet.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkUp);
}
void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
{
string ipAddress = ethernet.NetworkSettings.IPAddress;
WebServer.StartLocalServer(ipAddress, 80);
sayHello = WebServer.SetupWebEvent("hello");
sayHello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(sayHello_WebEventReceived);
}
void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
{
string content = "<html><body><h1>Hello World!!</h1></body></html>";
byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);
responder.Respond(bytes, "text/html");
}
@ andre.m - I’m using WebServer and not httpServer, What differences does it make?
can I use instead
WebServer.SetupWebEvent ?
There must be some easier modification to my program…
The best way to run an HTTP web page is to use the HTTPServer implementation. You can also code your HTML page, and add it as a resource for use in your project. Ease of use is relative to the scope and complexity of your project. It would be easiest, for you to create an HTML request engine, meaning: A command can be executed from JS using a requested path, the request may also make use of queries and POST data, if you feel the need to implement this. Example:
<a href="led-on">Click Me To Turn On The LED</a>
Clicking the above button will take you request “led-on” page from the device. From the device side you will have a clause checking for the request such as:
if (request == "led-on")
{
//Turn On LED
//Send page data to the client from your resources
}
The biggest thing to remember about NETMF is that it IS NOT .NET. NETMF uses C# and conforms to CLI, however, it does not implement the larger functions that make .NET a breeze to use. You will find yourself reinventing the wheel from time to time
@ James - Can you be more specific about the HTTPServer implementation? Never heard of it. Furthermore, what changes do I need to make my simple program to work?
AND WHY THE HELL ITS SO COMPLICATED?!
This is actually all rather trivial, and very easy to accomplish for an embedded environment. Here is a snippet taken from an older post on our forums about the HTTPListener as a server. While not exactly what I told you to look into, but this should actually be easier.
The HTML variable is the value being returned outside the FEZ (so possibly a web browser on your development PC). It’s up to that the device to take this value and show it in the web browser.
James’ code was just a simple text response to the web request coming into the FEZ. It could be a HTML formatted response. The information in there could be a static response (like James’ sample) or the status of devices connected to your Panda (distance sensor? led status?).
@ mhectorgato - Thanks for replying but I need a practical example.
Let’s say that the html pops one question such as "what is your favorite color?"
and the user answers some color, gadgeteer parses it and act accordingly such as: