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

Network Settings


  • Please log in to reply
16 replies to this topic

#1 Krokonoster

Krokonoster

    Member

  • Members
  • PipPip
  • 11 posts

Posted 02 December 2012 - 07:01 PM

Hi, Can someone point me to some good tutorial or posts re. the network settings of an Netduino Plus? Reason is that I could not get this simple (uuhm..supposedly) "Hello World" webserver to work. Just hangs at "using (Socket clientSocket = _socket.Accept())" After some searching I learned it might be that my boards IP settings does not go with my home network. So I tried giving my laptop and the board the same default gateway, etc, but just could not get it work. (Yes, unique IP to the board) Thanks for reading! Krok

#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 02 December 2012 - 07:08 PM

Which version of the Netduino board are you using? Is this a ND+ or ND+2?

#3 Krokonoster

Krokonoster

    Member

  • Members
  • PipPip
  • 11 posts

Posted 02 December 2012 - 07:29 PM

Which version of the Netduino board are you using? Is this a ND+ or ND+2?

It's a ND+. Could not get a ND+2 here.

#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 02 December 2012 - 07:44 PM

I haven't played with that example in a while. I believe in the code there is something like this to enable DHCP.

Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp();
WebServer webServer = new WebServer();

I believe I was having a similar issue and had to change the code to something like this below to enable Dynamic DNS also. You can also un-comment the System.Diagnostics.Debug...... line to show if you have an IP and if DHCP is enabled.

var interf = NetworkInterface.GetAllNetworkInterfaces()[0];

interf.EnableDynamicDns();
interf.EnableDhcp();

//System.Diagnostics.Debug.WriteLine("Webserver is running on " + interf.IPAddress + " /// DHCP: " + interf.IsDhcpEnabled);

WebServer webServer = new WebServer();


#5 Krokonoster

Krokonoster

    Member

  • Members
  • PipPip
  • 11 posts

Posted 02 December 2012 - 08:27 PM

Thanks a lot for that Dave.

Not solved my issue though, but might be my own fault getting this error when hitting the line " interf.EnableDynamicDns();":
A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.Net.dll
An unhandled exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.Net.dll

The program '[4] Micro Framework application: Managed' has exited with code 0 (0x0).


Back to what I originally *thought* is the problem.
If I run ipconfig on my laptop, I get:
IPv4 address: 10.0.0.5
Subnet Mask: 255.255.255.0
Default Gateway: 10.0.0.2

I tried setting my board via MFDeploy to rather use that default gateway and give it a static IP of 10.0.0.11.
However after getting the above error and looking in MVDeploy again, I saw it was set back to the "default" settings.
So I changed it again, but alas, still gives the same error.

Oh, wait..above settings must be wrong since I cannot ping the board in WFDeploy now. On tinkering...
UPDATE..could not ping because had another demo running (also not working) and stopped at a breakpoint.

#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 02 December 2012 - 10:04 PM

Check to see if your Mac address on the board is set using the MFdeploy tool.

#7 caEstrada

caEstrada

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts

Posted 03 December 2012 - 01:56 AM

Krokonoster, You are correct, the famous sample code is blocking, which means it hangs until receives a request via TCP. I tested another code -not written by me- where very smartly the blocking code is enclosed in a separate thread. That code permits you to run two threads but avoiding the blocking code from freezing other operations you might be running simultaneously. It is supposed a web server runs perhaps I/O monitoring or any other tasks and report information gathered only after the web server received a REQUEST. Let me know if you need the code. Regards,

#8 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 03 December 2012 - 02:12 AM

i have made a simple sample too

forum link to it

#9 Krokonoster

Krokonoster

    Member

  • Members
  • PipPip
  • 11 posts

Posted 03 December 2012 - 08:13 AM

Thanks a lot for that, will be checking it out tonight. Day-time job of building web / mobile apps all of a sudden so boring compared to this!

#10 shobana

shobana

    Member

  • Members
  • PipPip
  • 15 posts

Posted 09 April 2013 - 07:04 AM

Dave VanderWekke var interf = NetworkInterface. GetAllNetworkInterfaces ()[0]; interf. EnableDynamicDns(); interf.EnableDhcp(); //System.Diagnostics. Debug.WriteLine(" Webserver is running on " + interf. IPAddress + " /// DHCP: " + interf. IsDhcpEnabled); WebServer webServer = new WebServer(); hello Dave wer shud i include dis code in the program..

#11 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 09 April 2013 - 11:28 AM

Dave VanderWekke  

 

var interf = NetworkInterface.GetAllNetworkInterfaces()[0];interf.EnableDynamicDns();interf.EnableDhcp();//System.Diagnostics.Debug.WriteLine("Webserver is runningon " + interf.IPAddress + " DHCP: " + interf.IsDhcpEnabled);WebServer webServer = new WebServer(); 

hello Dave wer shud i include dis code in the program..

 

If you have a simple program with a "Main()" method, you will place this in the main method so it will run when the code begins to execute.



#12 shobana

shobana

    Member

  • Members
  • PipPip
  • 15 posts

Posted 11 April 2013 - 07:13 AM

thnx for reply dave . now i have problem with this coding i don know what wud be the reason, the program is for netduino v4.1 but m having netduino plus 2 v4.2, i upgraded the project version 4.1 to 4.2 if i run this program i get an ip called 192.168.1.4 but if i give this ip in the web browser no data is received from the device

 

i set the network cofiguration using MFDeploy with 192.168.1.4

subnet mask is 255.255.255.0

default gateway is 192.168.1.1

but dns primary i gave the default 8.8.8.8

dns secoundary 8.8.4.4

 in my pc i use one lan for that it shows ip 192.168.1.7

for device in the output window it shows 192.168.1.4

 

but if i put in the web browser the page is not opening

 

this is the source code

 

weserver.cs

 

using System; using System.Net.Sockets; using System.Net; using System.Threading; using System.Text; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoGarageDoorOpener {   public class WebServer : IDisposable   {   private Socket socket = null;   //open connection to onbaord led so we can blink it with every request   private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);   private OutputPort Garage2CarOpener = new OutputPort(Pins.GPIO_PIN_D13, false);

  public WebServer()   {   //Initialize Socket class   socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);   //Request and bind to an IP from DHCP server   socket.Bind(new IPEndPoint(IPAddress.Any, 80));   //Debug print our IP address   Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);   //Start listen for web requests   socket.Listen(10);   ListenForRequest();   }

  public void ListenForRequest()   {   while (true)   {   using (Socket clientSocket = socket.Accept())   {   //Get clients IP   IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;   EndPoint clientEndPoint = clientSocket.RemoteEndPoint;   //int byteCount = cSocket.Available;   int bytesReceived = clientSocket.Available;   if (bytesReceived > 0)   {   //Get request   byte[] buffer = new byte[bytesReceived];   int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);   string request = new string(Encoding.UTF8.GetChars(buffer));   string firstLine = request.Substring(0, request.IndexOf('n')); //Example "GET /activatedoor HTTP/1.1"   string[] words = firstLine.Split(' ');  //Split line into words   string command = string.Empty;   if (words.Length > 2)   {   string method = words[0]; //First word should be GET   command = words[1].TrimStart('/'); //Second word is our command - remove the forward slash   }   switch (command.ToLower())   {   case "activatedoor":   ActivateGarageDoor();   //Compose a response   string response = "I just opened or closed the garage!";   string header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";   clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);   clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);   break;   //   default:   //   //Did not recognize command   //   response = "Bad command";   //   header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";   //   clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);   //   clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);   //   break;   }   }   }   }   }   private void ActivateGarageDoor()   {   led.Write(true);   //Light on-board LED for visual cue   Garage2CarOpener.Write(true); //"Push" garage door button   Thread.Sleep(1000); //For 1 second   led.Write(false); //Turn off on-board LED   Garage2CarOpener.Write(false);  //Turn off garage door button   }

  #region IDisposable Members   ~WebServer()   {   Dispose();   }   public void Dispose()   {   if (socket != null)   socket.Close();   }   #endregion

  } }

 

program.cs

 

using System; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoGarageDoorOpener {   public class Program   {   public static void Main()   {   Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp();   WebServer webServer = new WebServer();   webServer.ListenForRequest();

  }

  } }



#13 shobana

shobana

    Member

  • Members
  • PipPip
  • 15 posts

Posted 11 April 2013 - 07:19 AM

hello dave,

 

http://netduinohacki...-with-your.html visit dis link this code is not giving me the output..

 

i want interface android app with this board to controll the garage door open/close



#14 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 12 April 2013 - 06:05 AM

Hi shobana, If you ping the Netduino Plus from your PC (from the command line), do you get a response? If you run the SocketClient test app on your Netduino Plus, can you request data from a web server? [Be sure to remove the proxy server defaults from the sample.] Chris

#15 shobana

shobana

    Member

  • Members
  • PipPip
  • 15 posts

Posted 15 April 2013 - 08:20 AM

HI CHRIS,

 when i ping my netduino plus 2 from pc itz not responding itz telling destination host is unreachable

 

mean while how to find out my netduino plus 2 ip can u jus tell me the solution to use the netduino plus 2 for internet(webserver transmit/receive) pls look into my above webservice.cs and program.cs coding whether itz working with ur netduino plus 2 or can u pls modify the codings and put in the post .zip file..

 

Thnx in advance chris..



#16 shobana

shobana

    Member

  • Members
  • PipPip
  • 15 posts

Posted 15 April 2013 - 09:16 AM

HI CHRIS,

I am not able to connect my netduino plus 2 to erase and when i deploy the ERROR-CONFIG , FLASH file not able deploy itz telling unable to deploy,

 

hope i don know the proper procedure

 

first i hold the button n plugged into the micro usb to pc when i ping in mf deploy the device doesnt appears m not able to erase and not able to deploy the browsed EROR_CONFIG EROR_FLASH files, if i remove it n connect then the device is showing but could'nt deploy the hex files what is reason pls tel me the solution.. 

 

can u pls tel me the proper procedure for netduino plus 2 to do the above settings..



#17 sebswed

sebswed

    Advanced Member

  • Members
  • PipPipPip
  • 45 posts
  • LocationSweden

Posted 15 April 2013 - 09:30 PM

I used the following tutorial to get my IP from my Netduino +2 http://wiki.netduino...duino-Plus.ashx Maybe you could try a different webserver application? I downloaded many examples and played a lot before I got it working (14 hours of reading, copy, pasting and testing). The webserver application that I have works for me but I don't know if it will work for you, it never hurts to try. It might feel like a slope learning curve but its like a puzzle. You have to find the right piece to make your project work.

 

My wife studies and lives in a different city and will be there for 2 years. I figured I could play Skyrim for 2 years (I love that game) or start learning programming, I chose programming ^_^


Netduino Plus 2 (v4.2.2.2)





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.