
Simple Netduino Webserver
#21
Posted 26 October 2010 - 02:44 PM
#22
Posted 06 February 2011 - 02:11 PM
#23
Posted 06 February 2011 - 08:17 PM
#24
Posted 08 February 2011 - 12:46 AM
#25
Posted 09 February 2011 - 01:35 AM
I have been attempting to rewrite the code from ConsumeNetduino.html I want it to be a webForm and asp.net code.
I have a webForm with two asp:buttons - btnON and btnOFF
Here is the code that I am trying for btnON
protected void btnOFF_Click(object sender, EventArgs e) { string strNewValue; string strResponse; // Create the request obj HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.168.1.102"); // Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; strNewValue ="/led/1/0"; req.ContentLength = strNewValue.Length; // Write the request StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(strNewValue); stOut.Close(); // Do the request to get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); }
When I run the code for above I get the following output in the "Output" window
UBO IPAdress...192.168.1.102
UBO receivedStr...POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: 192.168.1.102
Content-Length: 8
Expect: 100-continue
UBO receivedStr...Connection: Keep-Alive
UBO responseStr...HTTP/1.1 200 OK
Content-Type: text/html
Command executed at 01/01/2009 00:05:12
I also get an execution error....at line in the code above at
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
saying that I am getting an invalid return
When I use the ConsumeNetduino.html is get the following code
UBO IPAdress...192.168.1.102
UBO receivedStr...GET /led/1/0 HTTP/1.1
Accept-Encoding: gzip, deflate
Accept-Language: en-ca
Referer: http://localhost:527...aCall/HTMLPage.
UBO receivedStr...htm
Accept: application/json, text/javascript, */*
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;
UBO receivedStr... GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;
Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3;
UBO receivedStr... .NET CLR 1.1.4322; Tablet PC 2.0)
Host: 192.168.1.102
Connection: Keep-Alive
UBO responseStr...HTTP/1.1 200 OK
Content-Type: text/html
Command executed at 01/01/2009 00:25:20
Can someone give me an idea of what I am doing wrong between my code and the original ConsumeNetduino.html code
#26
Posted 09 February 2011 - 09:26 AM
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.168.1.102/led/1/0"); // Set values for the request back req.Method = "GET";
I'm assuming you're not trying to host the ASP.NET on the Netduino, and that the web form is running on your PC.
#27
Posted 20 February 2011 - 07:37 PM
Well, it's not really a webserver, but it listens to webrequests and do things based on the requested urls.
Thanks to OZ for hinting Socket.Listen() in his video.
...snip...
A well-designed browser won't invoke /led/0 or /led/1 more than once in a short period of time because it fetches the previous responses from its client-side cache. Adding a Cache-Control directive to the HTTP response header like this fixes the problem:
responseStr = "HTTP/1.1 200 OK\nContent-Type: text/html\nCache-Control: no-cache\n\n";
Kevin
#28
Posted 25 February 2011 - 01:51 AM

#29
Posted 25 February 2011 - 02:12 AM
#30
Posted 25 February 2011 - 03:34 AM
I hosted the files on my pc, and it works!
p.s I cant host and run the htm files on the netduino itself?
Working = awesome

Yes, you should be able to store HTM files on your Netduino Plus (or on a shield with SD using a regular Netduino).
Chris
#31
Posted 25 February 2011 - 09:38 AM
#32
Posted 27 February 2011 - 08:45 PM
There's just one socket in the project. I just reset my board using MFdeploy and it's still hanging on that line.
After that unsuccessful run, then i try to re-deploy and i get a "device not found or cannot be opened" error. The program randomly deploys after that.
Sorry if this was previously answered, but I'm also using a static IP, and I also ran into the issue where the code hung on this line:
newSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Upgrading the firmware to 4.1.0.6 RC2 resolved the issue.
#33
Posted 12 May 2011 - 02:49 AM
#34
Posted 15 February 2013 - 02:28 AM
Where would i find code on how to host htm files on the sd card of the netduino plus?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users