Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Simple Netduino Webserver


  • Please log in to reply
33 replies to this topic

#21 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 26 October 2010 - 02:44 PM

I was getting a few issues with this code, but managed to sort them out. I'm using IE9 (beta) and getting a lack of responsiveness every second request and cached content returned. Using Fiddler to see what was being passed helped. It seemed IE9 was a little more fussy than Firefox about the http headers. I added the following and it works much better: Content-Length: (length of content not including headers) Connection: close I also made sure that each line was terminated by \r\n and \r\n\r\n between the header and content. These issues are also there in the .NET Microframework SocketServer sample. I'll post the full code of what I'm doing when it's finished, but thought I'd add this in case anyone else was having problems. Main thing for me now it to have the web server non-blocking. Hopefully that'll just means running the code on its own thread.

#22 motta

motta

    New Member

  • Members
  • Pip
  • 2 posts

Posted 06 February 2011 - 02:11 PM

Hi. Great device, great IDE and nice job fom SecretLabs. I see many apps coming! I loaded Hari´s code to my new N+ and applied pathches to get static IP from yaksplat and also delay suggested by myszor. I´ve got same unstable results and sometimes N+ do not answer and browser got frozen. Another test may help to figure out what is happening: opening a DOS windows from a separate micro and running a continuous ping -t shows 20% loss due to a timeout which means that N+ is not answering ICMP as well. Any hints that help to fix this are welcome. Thanks

#23 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 February 2011 - 08:17 PM

Hi motta, Are you running the latest (v4.1.0.6) firmware on your Netduino Plus? If you erase the current app running on your Netduino Plus (through MFDeploy) and then ping the device, do you get replies to pings consistently? Chris

#24 motta

motta

    New Member

  • Members
  • Pip
  • 2 posts

Posted 08 February 2011 - 12:46 AM

Hi Chris, Thanks for reply. I upgraded firmware from v4.1.0.5 to v4.1.0.6 RC1. I moved Netduino Plus to another router, no traffic running, just device and micro. Ping drops now only 3% messages and Hari´s app can run concurrently with continuous ping -t. Some bad interaction exists since after ping was frozen for 4 timeouts, I activated web server reloading command http://10.10.10.200/led/0 and ping restarted running. Most pings took 1-2 ms but largest reached 2662 ms, 41ms average, still a wide range, isn´t? It´s ok the static network setup as shown below for both routers. Enabling DHCP did not succeed and IP result was 0.0.0.0. I will stay tuned for TCP/IP stack improvements. Motta ------------------------ NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface networkInterface in networkInterfaces) { //networkInterface.EnableStaticIP("192.168.10.200", "255.255.255.0", "192.168.10.254"); networkInterface.EnableStaticIP("10.10.10.200", "255.255.255.0", "10.10.10.1"); //networkInterface.EnableDhcp(); //networkInterface.RenewDhcpLease(); Debug.Print("Gateway Address: " + networkInterface.GatewayAddress); Debug.Print("IP Address: " + networkInterface.IPAddress); Debug.Print("Subnet mask " + networkInterface.SubnetMask); }

#25 John Feeney

John Feeney

    Advanced Member

  • Members
  • PipPipPip
  • 55 posts
  • LocationAuburn, ON, Canada

Posted 09 February 2011 - 01:35 AM

I downloaded the code NetduinoPlusListener01.

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 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 09 February 2011 - 09:26 AM

The parameters are passed as part of the URL (MVC style). I think you'll need this:

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 Kevin Hazzard

Kevin Hazzard

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationMid-Atlantic USA

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 LiveForever

LiveForever

    New Member

  • Members
  • Pip
  • 2 posts

Posted 25 February 2011 - 01:51 AM

hello im new here :) I tried to open the htm page http://x.x.x.x/Test.htm http://x.x.x.x/ConsumeNetduino.htm It does not load, am i doing something wrong?

#29 LiveForever

LiveForever

    New Member

  • Members
  • Pip
  • 2 posts

Posted 25 February 2011 - 02:12 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?

#30 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 February 2011 - 03:34 AM

Hi LiveForever,

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 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 25 February 2011 - 09:38 AM

I updated the web server code here to be multi-threaded (well, double threaded) and and posted here. The example in Program.cs just takes the URL and looks for the corresponding file on the SD card (in a folder "Web"). There's also a commented out bit that just serves up html from a string. I used this technique without a problem when I needed to borrow the SD card from my Plus for something else. It shoudl suit what you want to do.

#32 jdsmith

jdsmith

    Member

  • Members
  • PipPip
  • 26 posts

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 n0rx0r

n0rx0r

    New Member

  • Members
  • Pip
  • 3 posts

Posted 12 May 2011 - 02:49 AM

Any one know how to use jQuery to catch the response from netduino and put in a div?

#34 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.