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 3 Wifi connectivity failure mode handling

Netduino3 Wifi

  • Please log in to reply
4 replies to this topic

#1 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 20 September 2015 - 08:47 AM

Hi all,

 

As part of an Azure Event Hub field gateway project I'm working on I was doing some testing and noticed I could reliably lock the device/network stack up.

 

I was checking how my AMQP Net Lite code reacted when network connectivity was lost, Initially I though it was my code (as it was unlikely to be an AMQP Net Lite issue) but now I think it might be something in the IP stack. 

 

To try and isolate the problem I built a small application which does an HTTP request as this was the simplest repro I could come up with

 

 

My Netduino 3 Wifi reliably connects to the Wireless Access Point in my office, then waits for an IP address and starts making http requests.

 

If I pull the LAN cable out of the back of the WAP the requests fail as expected

 

HTTP Status:200 :  OK
HTTP Status:200 :  OK
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
...
 
Then when I plug the cable back in, the HTTP requests start working again
 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
HTTP Status:200 :  OK
HTTP Status:200 :  OK 
...
 
 
So far so good, but if I power down the WAP the requests fail as expected and the WLAN connectivity LED on the N3 goes yellow. 
 
HTTP Status:200 :  OK
HTTP Status:200 :  OK
HTTP Status:200 :  OK
 NetworkChange_NetworkAvailabilityChanged False
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
...
 
 
If I power the WAP back up, after a while the WLAN connectivity LED on the N3 goes Green. There is a network connectivity change notification but when the next HTTP request is initiated the devices hangs
 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 NetworkChange_NetworkAvailabilityChanged True
 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
 
The code is attached for those who want to follow along at home
 
Any suggestions as to why and how I can work around this?
 
@KiwiBryn
blog.devmobile.co.nz
 
 
public static void Main()
      {
         // Wait for Network address if DHCP
         NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
         if (networkInterface.IsDhcpEnabled)
         {
            Debug.Print(" Waiting for DHCP IP address");
 
            while (NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress == IPAddress.Any.ToString())
            {
               Debug.Print(" .");
               Thread.Sleep(250);
            }
         }
 
         // Display network config for debugging
         Debug.Print("Network configuration");
         Debug.Print(" Network interface type : " + networkInterface.NetworkInterfaceType.ToString());
         Debug.Print(" MAC Address : " + BytesToHexString(networkInterface.PhysicalAddress));
         Debug.Print(" DHCP enabled : " + networkInterface.IsDhcpEnabled.ToString());
         Debug.Print(" Dynamic DNS enabled : " + networkInterface.IsDynamicDnsEnabled.ToString());
         Debug.Print(" IP Address : " + networkInterface.IPAddress.ToString());
         Debug.Print(" Subnet Mask : " + networkInterface.SubnetMask.ToString());
         Debug.Print(" Gateway : " + networkInterface.GatewayAddress.ToString());
 
         foreach (string dnsAddress in networkInterface.DnsAddresses)
         {
            Debug.Print(" DNS Server : " + dnsAddress.ToString());
         }
 
         NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
         NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
 
 
         while (true)
         {
            try
            {
               //WebProxy proxy = new WebProxy("10.0.0.37", 8888);
 
               using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.bing.com"))
               {
                  //request.Proxy = proxy; 
                  request.Method = "GET";
                  request.ContentType = "text/html; charset=utf-8";
                  request.KeepAlive = false;
 
                  using (var response = (HttpWebResponse)request.GetResponse())
                  {
                     Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
                  }
               }
            }
            catch (Exception ex)
            {
               Debug.Print(ex.Message);
            }
 
            Thread.Sleep(1000);
         }
      }
 
 
 
      static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
      {
         Debug.Print(" NetworkChange_NetworkAvailabilityChanged " + e.IsAvailable);
      }
 
 
 
      static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
      {
         NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
 
         Debug.Print("NetworkChange_NetworkAddressChanged " + networkInterface.IPAddress);
      }
 
 
 
 

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 20 September 2015 - 05:27 PM

Hi KiwiDev,

Interesting. The new network stacks should be resilient against this sort of thing. My main concern normally is that code needs to wait to get an IP address again after the network reconnects...but it sounds like this might be a different issue.

When you say "There is a network connectivity change notification but when the next HTTP request is initiated the devices hangs", are you experiencing a blocking call which never returns? Do you know what function is blocking? Or are you seeing a communication failure exception (as indicated in the debug output)?

If you're seeing an actual hang in the network stack, can you please create an issue at the Netduino.IP (for Wi-Fi) repo and we'll load the debug software build and step into the code to see what's going on?

Also--if this is an urgent bugfix request, please let us know that too so we can up-prioritize this...

Thank you KiwiDev,

Chris

#3 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 20 September 2015 - 07:50 PM

Hi Chris,

 

Added a couple of Debug.Print statements

 

 using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.bing.com"))
{
   //request.Proxy = proxy; 
   request.Method = "GET";
   request.ContentType = "text/html; charset=utf-8";
   request.KeepAlive = false;
 
   Debug.Print("request.GetResponse() Before");
   using (var response = (HttpWebResponse)request.GetResponse())
   {
      Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
   }
   Debug.Print("request.GetResponse() After");
}

 

 

First I unplug the cable

 

request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
HTTP Status:200 :  OK
 
Cable plugged back in and requests resumed.
 
 
Then I turn off the router
 
request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
HTTP Status:200 :  OK
request.GetResponse() After
request.GetResponse() Before
 NetworkChange_NetworkAvailabilityChanged False
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 NetworkChange_NetworkAvailabilityChanged True
 
request.GetResponse() Before
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Netduino.IP.LinkLayers.CC3100
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
 
request.GetResponse() Before
 
From the logging it looks like it hangs up in the var response = (HttpWebResponse)request.GetResponse()) on the second request after connectivity restored.
 
 
I'll do some more digging and create an issue this evening when I get home from work
 
@KiwiBryn
blog.devmobile.co.nz


#4 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 21 September 2015 - 08:49 AM

Hi Chris

 

I grabbed the source from Github and re-compiled my application with it.

 

After several restarts I found that the application is hanging on the first call to

 

var response = (HttpWebResponse)request.GetResponse())
 

after the NetworkAvailabilityChanged notification indicates the network is back

 

Debugging down in the stack the lockup appears to be in 

 

private InputNetworkStreamWrapper EstablishConnection(Uri proxyServer, Uri targetServer)

 

around line 1366 where it calls

 

hostEntry = Dns.GetHostEntry(proxyServer.Host);

 

The debugger complains that the code & binary don't match when I go further in

 

I noticed that when I put this line in 

Debug.Print("IPAddress " + NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);

 

Just before the 

 

 using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.bing.com"))

 

The code then stopped in a similar way on the first call after the network connectivity restored notification

 

 

Regards

 

@KiwiBryn

blog.devmobile.co.nz



#5 ukkiwisurfer

ukkiwisurfer

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationLondon

Posted 24 October 2015 - 12:45 PM

Hi Chris,

 

Is there any progress on this issue? 

 

Thanks,

Jason.







Also tagged with one or more of these keywords: Netduino3, Wifi

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.