Copy That, Server!

I have bumped into this post by Laurent Ellerbach, he managed in creating a rudimentary webserver that will run on the .NET MF.

So I made a controller, and used his class and implemented that into my code as follows:

private static void RegisterControllers()
 _tempertureController = new OneWireTemperatureSensorController(Pins.GPIO_PIN_D0);
 _webserverController = new WebServerController(80, 10000);
 _webserverController.CommandReceived += new WebServerController.GetRequestHandler(ProcessClientGetRequest);
 // Start the server.

And then some parameter parsing

private static void ProcessClientGetRequest(object obj, WebServerController.WebServerEventArgs e)
 Debug.Print(e.rawURL + " Received");
 if (e.rawURL == "LEDSOFF")
 if (e.rawURL == "LEDSON")
 if (e.rawURL == "STATUS")
 var temp = ReadHumidityAndTemperature();
 SendResponse("TemperatureReading:" + temp + "C", e.response);
 }//Send Status Report
 if (e.rawURL == "TEMP")
 var temp = ReadHumidityAndTemperature();
 SendResponse("TemperatureReading:" + temp + "C", e.response); //SendResponse(temp + "", e.response);
 }//Send Temp

private static void SendResponse(string temp, Socket response)
 WebServerController.OutPutStream(response, temp);




You see I was ambitious and believed I could get both receive & response working from the first time, but no such luck.
Now comes the cool part! Clicking that Toggle Lights button does indeed flick on/off the LEDS of my NP2, which is cool, remote light switch!! 🙂

However! After each call I made to NP2, I receive a connection closed exception, so when I really want a response I can’t get it.
So I can talk to it, but it can’t respond (… sounds weird this way..)
So when I try to talk to him, he can’t respond.  (sounds better, guess I should name him now that he can listen.. but I’m drifting)

The controller calls were made like this:

private void LightButton_Click(object sender, RoutedEventArgs e)
 var action = LightsOn ? "LEDSOFF" : "LEDSON";
 var url = string.Format("http://{0}/{1}", IpAddress, action);
 LightsOn = !LightsOn;
 WebRequest webRequest = WebRequest.Create(url);
 WebResponse webResp = webRequest.GetResponse();
 catch (Exception ex)
 ErrorMessageLabel.Content = string.Format("While Setting LED State, more info: {0}", ex.Message);


So now I guess, back to debugging & googling 🙂

Up next! Reading the interval time of my temperature sensor from my SD Card on startup, so I can overwrite that value using my new webserver, and rebooting (if Netduino can do that?).


Care to comment?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s