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

Can I tell whether the Ethernet cable is connected?


  • Please log in to reply
6 replies to this topic

#1 Tal Tikotzki

Tal Tikotzki

    Member

  • Members
  • PipPip
  • 10 posts

Posted 13 January 2013 - 03:20 PM

How can I tell if the Ethernet cable is connected?

 

T

 

 



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 January 2013 - 03:26 PM

Hi Tal,

Assuming that you're using Netduino Plus 2...

The NetworkInterface class will give you the current IP address. If you're using DHCP, that will effectively let you know if you have an acquired address.

There's also the NetworkAvailabilityChanged event.

Of course, the green 'ACT' LED lights up solid when an Ethernet cable is connected. But I think you were looking for the code answer :)

Chris

#3 Tal Tikotzki

Tal Tikotzki

    Member

  • Members
  • PipPip
  • 10 posts

Posted 13 January 2013 - 06:30 PM

Hi Chris,

  Thanks!

  I'm using a static address and not the DHCP.

  I'll give the event a chance, however, Is there a way to poll on the network availability?

 

T



#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 January 2013 - 09:23 PM

Hi Tal,
Hi Chris,   Thanks!   I'm using a static address and not the DHCP.   I'll give the event a chance, however, Is there a way to poll on the network availability?
You could try pinging your gateway IP at boot to see if you're already connected. This could be a useful feature for a future release of NETMF. Chris

#5 Tal Tikotzki

Tal Tikotzki

    Member

  • Members
  • PipPip
  • 10 posts

Posted 19 January 2013 - 09:59 AM

Hi Chris,

   How can you perform the ping you suggested?

 

Tal



#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 January 2013 - 12:00 PM

Hi Tal,
   How can you perform the ping you suggested?
I haven't tested this one, but here's a ping sample from two years ago. There was a bug in NETMF which was blocking pings...so the user wrote a ping repro sample.

http://netmf.codeple...m/workitem/1126

Chris

#7 Tal Tikotzki

Tal Tikotzki

    Member

  • Members
  • PipPip
  • 10 posts

Posted 19 January 2013 - 01:34 PM

Thanks Chris,

 

  The networkAvailabilityChange event is fired only if there is a change after the network established. So when starting (power up, reset etc.) I did not receive any notification, neither when the network was connected nor was it disconnected when Netduino powered-up..

 

For that reason I looked for a method to safely poll on the network status when the Netduino started.

 

I tried to open a listening socket on a port that I wasn't planning to use:

 
            using (var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))            {                try                {                    var bindingAddress = new IPEndPoint(IPAddress.Any, 9001);                    listenSocket.Bind(bindingAddress);                    listenSocket.Listen(1);                    netOkay = listenSocket.Poll(500, SelectMode.SelectError);                }                catch (Exception)                {                    netOkay = false;                }
listenSocket.Close();

}

 

 

This is not the nicest code, but since it is being called only once, after power-up, it seems good enough.

 

 

Tal

 

Edited by Tal Tikotzki, 20 January 2013 - 09:37 AM.





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.