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

Detect if Ethernet Cable is Connected


  • Please log in to reply
15 replies to this topic

#1 sycgolfer22

sycgolfer22

    New Member

  • Members
  • Pip
  • 1 posts

Posted 25 June 2012 - 10:31 PM

Hello All, I am currently working on a weather clock using the netduino plus. When the clock initially boots up I would like to detect if there is internet connectivity somehow and then based on that either set the time automatically from the internet or read the time from a sparkfun RealTime clock module. I already have all the code working to get the current time from an NTP server and the interfacing with the RTC module. I just need a function to check if there is internet connectivity and return a boolean value. Any ideas would be greatly appreciated!

#2 pjnowak

pjnowak

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 28 June 2012 - 06:53 PM

This would be great to know as well. I am using a a WiFly shield in my project, and would like to know if the cable is plugged in as well. If it is I would like to use the cable instead of the WiFly shield. How every I have not been able to find a way either to determine if it is plugged in or not.

#3 DrJaymz

DrJaymz

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 10 July 2012 - 09:05 AM

I am using NetworkChange.NetworkAvailabilityChanged to detect if it is available, the callback contains if it is or not connected, but there is no way I can see to determine it on startup. i.e. if I pull the cable in or out I can tell the status, but on startup I can't tell. Anyone else got a solution?

#4 rchelicopter

rchelicopter

    Member

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

Posted 10 July 2012 - 03:49 PM

Hello, I am also desperately trying to detect network disconnects on a tcp socket (half open sockets) but I have not as of yet figured out how to do it. For me I don't not need to know at startup but rather after a connection has been established. DrJaymz - could you pleas elaborate on the usage of NetworkChange.NetworkAvailabilityChanged, perhaps a sample bit of code to help me a bit. Thanks.

#5 Ballew

Ballew

    New Member

  • Members
  • Pip
  • 1 posts
  • LocationCartersville, GA

Posted 11 July 2012 - 08:51 PM

using Microsoft.SPOT.Net.NetworkInformation;

static bool isNetworkAvailable = false;

static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)         
{
             isNetworkAvailable = e.IsAvailable;
             Debug.Print(DateTime.UtcNow.ToString("u") + ": " + (isNetworkAvailable ? "CONNECTED" : "DISCONNECTED"));
}

from How to reboot netduino + from code on a socket exception
Craig Ballew

“Sometimes the questions are complicated and the answers are simple.”
~ Dr. Seuss

#6 javast

javast

    New Member

  • Members
  • Pip
  • 3 posts

Posted 09 August 2012 - 04:18 PM

Hi, for me is this not working at 4.2 RC5, the rutine NetworkChange_NetworkAvailabilityChanged is never called. Any help what to do?

#7 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 09 August 2012 - 04:35 PM

Hi,
for me is this not working at 4.2 RC5, the rutine NetworkChange_NetworkAvailabilityChanged is never called. Any help what to do?


You have connected the event handler to the relevant event?

Original post is here, you need a line like this in your main method:

	NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;

Nak.

#8 javast

javast

    New Member

  • Members
  • Pip
  • 3 posts

Posted 09 August 2012 - 06:43 PM

Hi Nak, of course - there is such line in main fuction. Thanks Jan

#9 Homey

Homey

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 03 February 2015 - 06:44 PM

I know this is old but I too would like to know if a cable is plugged in at start up.  The changed event will only fire after start up and a cable is plugged in or out.

 

Is there any solution for this obvious need in 4.3?

 

Homey



#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 February 2015 - 07:46 PM

Hi Homey,

Are you using DHCP? If so, check your NetworkInterface for an IP address.

BTW this is definitely something we can support with Netduino.IP... We're not to UDP/TCP yet in the progressive preview, but we'd love it if you have a chance to test this out in a month or two when we get there...

Chris

#11 Homey

Homey

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 03 February 2015 - 07:53 PM

Unfortunately I cant use DHCP in my application.  Sure, I would be happy to help test new stuff!  Just  let me know how and when.  I do a lot of TCP and UDP sockets on my ND+2's now.

 

Homey



#12 beastyboy

beastyboy

    Advanced Member

  • Members
  • PipPipPip
  • 194 posts
  • LocationNetherlands

Posted 03 February 2015 - 08:23 PM

Hi Homey,

 

Not sure if it is a feasible solution but why not sent a HTTP web request and check if you get a response within a certain time?

 

Surround the call with a try catch and done or is there something I am not understanding?

 

Cheers,

Beasty


Van SchOten Ict Diensten en Services
http://www.voids.nl


#13 Homey

Homey

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 03 February 2015 - 11:15 PM

in my applications the ND+2 is on a personal network with no router, etc (aka direct cable between a compy and ND+2).  I suppose I could install IIS on the compy and try the http request idea but really the right answer is to implement the "IsConnected" var in networkinterface.  That's really what im hoping the next firmware will do :)



#14 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 February 2015 - 12:26 AM

Hey Homey,

How about if we implemented this? If nothing else...as a separately-downloadable sample class?
https://msdn.microso...(v=vs.110).aspx

Chris

#15 Homey

Homey

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 04 February 2015 - 02:51 AM

Chris, that would be awesome!  Anything is better than what im doing now which is try/catching socket bind exceptions.

 

Homey



#16 bgreer5050

bgreer5050

    Member

  • Members
  • PipPip
  • 28 posts

Posted 07 August 2015 - 05:59 PM

Hi Chris.  

 

Was the 

NetworkInterface.OperationalStatus Property ever implemented in one form or another ?

 

Thanks

Bill






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.