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

Updated web server


  • Please log in to reply
43 replies to this topic

#21 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 29 January 2011 - 02:33 AM

Hi John,

Open up MFDeploy (Start > Programs > .NET Micro Framework SDK > MFDeploy.exe). Go to the Target Menu > Configuration > Network.

I'd recommend setting up a static IP address there. You may also be able to see your DHCP-assigned address there; if not, you can do the following in code to get your DHCP address:
Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);

Chris
  • RedSky likes this

#22 Jarrod Sinclair

Jarrod Sinclair

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationSF Bay Area, CA

Posted 29 January 2011 - 04:37 PM

I am just starting. I have a Netduino Plus. I have downloaded the code in the first post of this topic. I am using Visual Studio 2010.

I hooked a network cable to the Netduino. In my Project menu, I wnet to the project options and set the Net Micro Framework Deployment to USB.

When I run the code the blue onboard LED is blinking. (In main() I have set Thread.Sleep(500) to (5000) and I get a very slow blinking light....so I am sure that it is running ok).

What I can't figure out is how I am suppose to talk with the Netduino? From a YouTube video I got the idea of pinging the Netduino. I beleive I am on the right cable. I ping 192.168.1.103 and I get back 4 packets sent and received.

I don't have a miniSD card so, I changed the routine TrySendFile. I commented out the existing code and put in a Debug.Print("Testing...testing);. I also added using System.Diganostics to the top of the code.

I am just coding in my home. We have one Linksys router with a couple of cables coming out of it.


1. How do you tell what IP address the Netduino is on? On my laptop I turned the wireless off, pluged the network cable into my Laptop and did a IPConfig. When I got back 103 I put it into the Netduino and turned my wireless back on.
2. If you have the correct IP address and the program in this post is loaded correctly, how do you send a command to the Netduino....Ulimatedly, I would like to make one of the programs where from a webpage or windows program they are turning the light on and off from the webpage buttons. .... but to start how can i get it to receive and acknowledge by executing the debug.print that i put in TrySendFile

Thanks, John Feeney



John,
The IP address ending in .103 is your local PC. Depending on your router, your router will have that IP assigned to it for at least 24 hours. If you want to know what the IP address if of the Netduino, the you will need to log into your router and look at the DHCP table. on there you should find an entry that matched the MAC address of you Netduino. It is also possible (if your computer is connected to the usb port on the Netduino plus) to use some code to feed it back to you via the debug output. I don't have the plus to test this on (YET!!) but you should be able to use Debug.Print(Microsoft.SPOT.Net.NetworkInformation.IPAddress()); there is alos a property for the MAC called Microsoft.SPOT.Net.NetworkInformation.PhysicalAddress see here for details.


NOTE: If you want you device to be on the same IP each time it is connected, your router should allow you to set a specific IP address for a given MAC address. I use this for all my devices on my network so that I can remote access them when not at home and it works on netgear, linksys and other devices I have.

#23 fraser

fraser

    New Member

  • Members
  • Pip
  • 1 posts

Posted 30 March 2011 - 04:42 AM

I believe if you change your "Configuration Manager" from "Debug" to "Release" those lines will be excluded from the compiled code.

James

This works so great!

I had to comment out all the Debug.Print's though because after running for a week on my local PC/network (NetduinoPlus RJ45 -> router, USB power to XP PC) my System process on Windows XP was maxed out to 98%, preventing almost anything else from happening.

After drilling down into the processes it seems that the native Netduino USB driver was eating all the CPU. My theory is all the Debug.Print strings being pushed through USB back to the PC. It's a waaay older PC, circa 2002 so it only runs USB 1.0 ;)

In any case it's been running for four days now (commented Debug.Prints) without incident.

I can put the PC in sleep/standby mode and the NetduinoPlus is still powered up and serving pages!

Kudos!

Now if we could only serve up ASP.NET pages my life would be complete ;)



#24 SimonPeter

SimonPeter

    New Member

  • Members
  • Pip
  • 3 posts

Posted 03 April 2011 - 02:35 AM

Hey Fred, this is great stuff! Do you have an updated version available for download?

#25 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 03 April 2011 - 05:57 PM

No updated version at the moment - I've been busy on another Netduino project that I'll post about in the next day or two. I may get back to the project that uses this again soon.

We're all in this to have some fun, so this was never intended to be a complete solution. It was more intended as a sample or a framework to get you started. Feel free to optimize, extend or just hack it into whatever fits your particular requirement.

Some things that might be useful:
  • Adding a simple upload of files to the SD card (HTTP post or FTP)
  • Improved handling of things like IE's zero length request. Whatever I do seems to still occasionally fail to respond as expected.
  • Handling errors on the listener thread and ensuring it's restarted. I've managed to crash it and lose HTTP responsiveness but still have the rest of my code running OK.
  • Handling parallel requests on different threads. (Not sure how useful this would be as we've only got one processor to do the work anyway.)


#26 FelixEmman

FelixEmman

    Member

  • Members
  • PipPip
  • 25 posts

Posted 04 April 2011 - 02:27 PM

Fred,
I did try your webserver and I did notice that trying a request while another is still serving, will throw a socket exception and crash it.
See this post for more details. I think it's because the webserver is single threaded. It's true that there's a single core, but remember, any real webserver is threaded or able to handle many requests at once. And most useful applications have to make use of threading in order to provide a smooth user experience.

So if you make improvements I would encourage threading your webserver.
If you have time and want to get fancy, see Quiche31's implementation http for ideas. I think it's rather SLOW compared to yours, but he handles the request a bit more gracefully.

#27 Jony

Jony

    New Member

  • Members
  • Pip
  • 7 posts

Posted 10 April 2011 - 07:07 PM

Hi i'm a new user and i'm trying to acces to the Netduino+ via Internet and not only in the local area network, but could someone tell me the settings that i need to do please? Thanks to the community

#28 Terry Massey

Terry Massey

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationPekin, IL

Posted 11 April 2011 - 05:09 AM

Hi i'm a new user and i'm trying to acces to the Netduino+ via Internet and not only in the local area network, but could someone tell me the settings that i need to do please? Thanks to the community


that is more a routing issue than a netduino issue. as for netduino getting an IP I don't have one yet... but i do know web servers. and the key is in your router.... can you tell me how you connect it to the network/internet and what devices you have I can help with the router config... well depending on the model.....
Thanks,
Terry Massey

#29 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 April 2011 - 05:35 AM

Yep, that's no a Netduino issue, rather a IP mapping problem. The simplest way is to make Netduino connecting to a fixed IP where you will create a kind of bridge. The clients (who's connecting to Netduino) also will connect to the same fixed IP. At the fixed IP, you'll have an app, accepting lots of socket connections. Once there are the N connection and some other client, just route the clients to N. Cheers
Biggest fault of Netduino? It runs by electricity.

#30 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 11 April 2011 - 06:42 AM

Hi i'm a new user and i'm trying to acces to the Netduino+ via Internet and not only in the local area network, but could someone tell me the settings that i need to do please? Thanks to the community


This really depends upon the scenario. Couple of options:
  • N+ connected to a router
  • N+ connected through a PC using internet connection sharing (there was a post about this yesterday here)
In both cases I'd satrt with a static IP address on the N+ and then move to DHCP if needed.

In case 1, you would need to determine / configure the N+'s IP address so that it is on the same subnet as the rest of the machines on your network. As Terry mentioned, you can get this information from you routers admin/config page. MFDeploy will let you configure the N+. Once you have done this I'd make sure that you can talk to the N+ on your local network. Note that if you intend you use static IP then you have to maker an address reservation in you router to ensure that it never tries to assign this IP address.

Next step is to get the N+ to talk to the outside world. So back to MFDeploy and set the DNS and gateway settings on the N+. You can get this information from any PC on the network - in windows open a command prompt and enter the command "ipconfig /all". You should be able to glean the information from the output. Failing that, go back to the router config / admin page. Once this information is entered into the N+ you should be able to get an outbound connection to the internet and this can be confirmed by writing a small socket application which tries to make a web request. There are samples in the SDK which should help.

Next step, think about using DHCP. You can do this if your N+ is only making outbound connections. If it is expecting to receive incomming connections I'd stick with static IP as it is acting as a server.

As for case 2, well I'd go and have a look at the previous post.

Hope this helps,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#31 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 April 2011 - 07:14 AM

@Mark: you're right, but it seems all too much rigid. I'd like much more an approach like Hamachi or TeamViewer, where there is a well-defined point somewhere in the internet, where anything will meet to share a connection. Anyway, it depends on what you have to do.
Biggest fault of Netduino? It runs by electricity.

#32 Jony

Jony

    New Member

  • Members
  • Pip
  • 7 posts

Posted 11 April 2011 - 03:27 PM

I have the Netduino+ conected to a Linksys router and I access it by a computer inside the network but I would like to acces it from my smart phone through 3G. I had heard something about opening ports on the router but I have no idea how do that. I configured the Netduino with a static IP. I am not currently interested in obtaining an IP by DHCP. The Netduino+ is running the program published in this post with some modifications. Thanks to everybody for the replies.

#33 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 11 April 2011 - 03:40 PM

You will need to have a look at the documentation for you router to work out how to do this. You should also review security arrangements and make sure you are fully aware of what you are doing and the security implications. You will usually open a port and then tell the router to send all traffic on that port to a specific IP (the N+ address). Something else you need to review is you Internet facing IP address - is this static or dynamic? If it is dynamic then you will need to look at a service like dyndns (I think that's the name - it's been a long time since I used them). Regards, Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#34 Terry Massey

Terry Massey

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationPekin, IL

Posted 11 April 2011 - 04:38 PM

You will need to have a look at the documentation for you router to work out how to do this. You should also review security arrangements and make sure you are fully aware of what you are doing and the security implications. You will usually open a port and then tell the router to send all traffic on that port to a specific IP (the N+ address).

Something else you need to review is you Internet facing IP address - is this static or dynamic? If it is dynamic then you will need to look at a service like dyndns (I think that's the name - it's been a long time since I used them).

Regards,
Mark


Nevyn - DynDNS is correct.

Jony - Linksys has a very nice feature that will allow you to do exactly as Nevyn just said. It is called Port Fowarding. All you need to do is login to your router using your gateway address. Your gateway will be the address of your router. Then depending on the exact model where that is located is different. However also depending on your service provider many ports are blocked to force you to purchase a business account. If you need more detailed help I can but the forum is not the best place to do this. a Chat would be better. You can PM me your Info I can help.
Good Luck,
Terry
Thanks,
Terry Massey

#35 andysa

andysa

    New Member

  • Members
  • Pip
  • 9 posts

Posted 21 April 2011 - 02:28 AM


Some things that might be useful:

  • Improved handling of things like IE's zero length request. Whatever I do seems to still occasionally fail to respond as expected.



I am experiencing this also. Can you please shed some more light on the IE zero length request?

I am finding that it is not consistent from one IE client trying to access the webserver to the next. eg. I had a couple of friends individually access the webserver, each running IE. One consistently gets logged at the webserver as a zero byte request, resulting in no page being served. Whereas the other friend comes through fine, with at least a couple of hundred bytes being detected.

Could this possibly more likely be a timeout issue and are there any thoughts on addressing this in the code?

On another note, does anyone know how to set a Hostname within the N+, in order for it to appear in the routers DHCP lists?

#36 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 24 October 2011 - 05:36 PM

An updated simple web server for the Netduino Plus. Obviously based on the SocketServer .NET framework example and code posted here by oz-solutions and hari.

Some slight tweaks to headers should help prevent lost requests when using IE9 beta.
Has a Request object to help with parsing the incoming request.
Threaded so your code can get on with whatever it's doing and still respond to a http request.

[30/11/2010 - project updated]


Fred,
Nice work. Thanks for doing this. I have been using your code to try to download a text file from SD to the browser rather than display it. I changed the header to:

string header = "HTTP/1.0 200 OK\r\nContent-Type: application/octet-stream; charset=utf-8\r\nContent-Disposition: attachment; filename=Log.txt\r\nContent-Length: " + inputStream.Length.ToString() + "\r\nConnection: close\r\n\r\n";

based on a Microsoft suggestion (http://support.microsoft.com/kb/260519). It does not bring up a download dialog. Do you have any suggestions?

#37 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 24 October 2011 - 05:59 PM

Not sure off the top of my head. I'd be tempted to find a page that works how you want, install Fiddler and spy on the http response. Then you can mimic this.

#38 ColinR

ColinR

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationCape Town, South Africa

Posted 24 October 2011 - 06:09 PM

using (FileStream inputStream = new FileStream(@"\SD\log.txt", FileMode.Open, FileAccess.Read))
{
	// Send the header
	string header = "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Disposition: attachment; filename=log.txt\r\nContent-Length: " +
	inputStream.Length.ToString() + "\r\nConnection: close\r\n\r\n";
	client.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);

	byte[] readBuffer = new byte[SocketBufferSize];
	while (true)
	{
		// Send the file a few bytes at a time
		int bytesRead = inputStream.Read(readBuffer, 0, readBuffer.Length);
		if (bytesRead == 0)
			break;

		client.Send(readBuffer, bytesRead, SocketFlags.None);
	}
}

client.Close();
client = null;


#39 PhilG

PhilG

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMaine

Posted 24 October 2011 - 06:34 PM

That works beautifully, thanks Collin

#40 acetate

acetate

    Member

  • Members
  • PipPip
  • 26 posts
  • LocationSeattle, WA

Posted 28 April 2012 - 07:32 AM

I've been using these classes for access to my netduino via my WP7 device. I just tried to consume the responses via a metro application using HTTPClient and am getting errors that the application is Unable To Connect to the Remote Server. However, I am able to connect from a browser on the same machine. I am using the HTTPClient sample from the Windows SDK. I spent too many hours trying to figure this out. Anyone have any ideas?




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.