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

Netduino Plus 2 network question


Best Answer StefanUSMC, 26 January 2013 - 02:45 PM

I'd try turning on the router and letting it start up to the point where it can give out IP addresses. 

Definitely.

 

When I use DHCP, I typically include something like:

 

public static Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NetInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];public static void ObtainDHCP()        {            NetInterface.EnableDhcp();            Thread.Sleep(3000);            if (NetInterface.IPAddress == "0.0.0.0")            {                Debug.Print("Waiting on DHCP...");                Thread.Sleep(3000);            }            if (NetInterface.IPAddress == "0.0.0.0") { Debug.Print("ERROR: Unable to obtain IP");               }            Globals.NIC_IP = NetInterface.IPAddress;            Debug.Print("IP - " + Globals.NIC_IP);        }

 

This allows a wait time for the ND to grab an IP, and reports an error if the IP is still invalid.

 

Good Luck,

Brandon

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 rchelicopter

rchelicopter

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Diego, Ca

Posted 25 January 2013 - 11:21 PM

Hello,

 

I have a Netduino Plus and a Plus 2, when I power up the Netduino Plus I also power up my dhcp router and it always seemed to wait for the router to obtain an IP address from it via DHCP.

With the Netduino Plus 2 when powered up it times out with a System.Net.Sockets.SocketException.

What was the netduino plus doing that the plus 2 is not, is there a way around this without going to a static address?



#2 Nevyn

Nevyn

    Advanced Member

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

Posted 26 January 2013 - 12:36 PM

Hello,

 

I have a Netduino Plus and a Plus 2, when I power up the Netduino Plus I also power up my dhcp router and it always seemed to wait for the router to obtain an IP address from it via DHCP.

With the Netduino Plus 2 when powered up it times out with a System.Net.Sockets.SocketException.

What was the netduino plus doing that the plus 2 is not, is there a way around this without going to a static address?

 

Two things immediately spring to mind:

  • Do you have the right libraries in the N+2 project
  • Timing

I'd try turning on the router and letting it start up to the point where it can give out IP addresses.  I'd then fire up the N+2 and see if the application works OK.  If it does then I'd say that the N+2 is starting up and requesting IP addresses before the router has started.

 

The N+2 runs on a faster microcontroller which is why it could be a timing problem.

 

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


#3 StefanUSMC

StefanUSMC

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts
  • LocationWisconsin, USA

Posted 26 January 2013 - 02:45 PM   Best Answer

I'd try turning on the router and letting it start up to the point where it can give out IP addresses. 

Definitely.

 

When I use DHCP, I typically include something like:

 

public static Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NetInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];public static void ObtainDHCP()        {            NetInterface.EnableDhcp();            Thread.Sleep(3000);            if (NetInterface.IPAddress == "0.0.0.0")            {                Debug.Print("Waiting on DHCP...");                Thread.Sleep(3000);            }            if (NetInterface.IPAddress == "0.0.0.0") { Debug.Print("ERROR: Unable to obtain IP");               }            Globals.NIC_IP = NetInterface.IPAddress;            Debug.Print("IP - " + Globals.NIC_IP);        }

 

This allows a wait time for the ND to grab an IP, and reports an error if the IP is still invalid.

 

Good Luck,

Brandon



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 26 January 2013 - 02:49 PM

you should do:

 

 

while(NetInterface.IPAddress == "0.0.0.0")

{ Debug.Print("Waiting on DHCP..."); Thread.Sleep(1000);

-- get your ip here }  

 

mfg  



#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 January 2013 - 03:46 PM

Hi rchelicopter, To confirm... Netduino Plus 2 will start your app as soon as it boots. Since the board and networking are faster and NETMF has been streamlining its boot sequence recently, your application may very likely start running before it obtains a network address. I recommend following Mark's, Brandon's, and NooM's recommendation: when using DHCP, pause while waiting for a network address. From there, you should be good to go. Chris




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.