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 Ethernet problem

Problem Netduino plus 2 Ethernet

  • Please log in to reply
4 replies to this topic

#1 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 22 July 2013 - 10:03 AM

[font="calibri, sans-serif;"]Hey, [/font]

 

[font="calibri, sans-serif;"]I got some big issues with the netduino when Im unplugging the network cable (To simulate network failure) and after a while (1-2 minutes sometimes more sometimes less) plugging in the network cable again it still wont connect to the server. [/font]

[font="calibri, sans-serif;"]I have attached 2 files Debug info.txt and Netduino Info.txt. [/font]

 

Attached File  Netduino Info.txt   1.43KB   20 downloads[font="calibri, sans-serif;"] contains all the information about the netduino, firmware and such stuff.[/font]

 

Attached File  Debug Info.txt   14.54KB   8 downloads [font="calibri, sans-serif;"] contains information about the program that runs on the netduino and what it is trying to do. The line Network: False and Network: True is when I unplug the network cable, and plug it in again. You can see that after it write Network: True It keeps retrying and get exception with the socket connection.[/font]

 

 

private void Connect()    {	    connectThread = null;	    connectThread = new Thread(() =>	    {		    try		    {			    Print("Creating socket");			    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); <-- This is where it fails???			    Print("Socket created");			    socket.ReceiveTimeout = 10000;			    socket.SendTimeout = 10000;			    //IPAddress ipAddress = HostnameToIPAdress(ServerHostname);			    //if (ipAddress == null)			    IPAddress ipAddress = IPAddress.Parse(ServerIP);			    EndPoint endpoint = new IPEndPoint(ipAddress, ServerPort);			    socket.Connect(endpoint);			    IsConnected = true;			    this.socket = socket;		    }		    catch (Exception e)		    {			    Print("Exception: " + e.ToString());			    IsConnected = false;		    }	    });	    connectThread.Start();	    int timeout = 0;	    while (connectThread.ThreadState != ThreadState.Stopped && connectThread.ThreadState != ThreadState.Aborted)  	  {		    if (timeout > 10)		    {			    Print("Timeout! ABORT!");			    connectThread.Abort();			    IsConnected = false;			    throw new TimeoutException();		    }		    Thread.Sleep(1000);	    }	    connectThread = null;    }

[font="calibri, sans-serif;"]I created everything in a thread for being sure it would n[/font][font="calibri, sans-serif;"]ever hang, its my own little timeout function.[/font]

[font="calibri, sans-serif;"]As you can see in the log it start failing at this line[/font][font="calibri, sans-serif;"] [/font][color=#2b91af;][font="calibri, sans-serif;"]Socket[/color][/font][font="calibri, sans-serif;"] socket = [color=#0000FF;]new[/color][/font] [color=#2b91af;]Socket[/color]([color=#2b91af;]AddressFamily[/color].InterNetwork, [color=#2b91af;]SocketType[/color].Stream, [color=#2b91af;]ProtocolType[/color].Tcp); [font="calibri, sans-serif;"]and I have no idea how to fix that? I have tried nearly everything, also using the global variable instead of a local, but no difference.? You can see in the log that it stop printing [/font] [color=#a31515;]Socket created[/color][font="calibri, sans-serif;"] but just throw an exception [/font]

 

[font="calibri, sans-serif;"]Log (View the file for more detailed log information):[/font]

[font="calibri, sans-serif;"]A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll[/font]

[font="calibri, sans-serif;"]06/01/2011 00:06:01 : Exception: System.Net.Sockets.SocketException[/font]

[font="calibri, sans-serif;"]The thread '<No Name>' (0x23) has exited with code 0 (0x0).[/font]

[font="calibri, sans-serif;"]06/01/2011 00:06:01 : Reconnect failure[/font]

[font="calibri, sans-serif;"]06/01/2011 00:06:11 : Creating socket[/font]

[font="calibri, sans-serif;"]A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll[/font]

[font="calibri, sans-serif;"]06/01/2011 00:06:12 : Exception: System.Net.Sockets.SocketException[/font]

[font="calibri, sans-serif;"]The thread '<No Name>' (0x24) has exited with code 0 (0x0).[/font]

 

[font="calibri, sans-serif;"]I hope you guys can help me solving the problem, because it seems like Im not the only one seeing this problem. I have been reading a lot about Ethernet problems on the forum, where people have created a watchdog to restart the netduino. But I dont think that its the right way to do it, I want this bug to get fixed instead of creating some code to work around the problem, and Im sure that it will help a lot of people [/font][font="wingdings;"] :)[/font]

 

[font="calibri, sans-serif;"]I can say that the same code is running on Windows and Linux with mono where it is working perfectly. [/font]

 

[font="calibri, sans-serif;"]Best regards [/font]

[font="calibri, sans-serif;"]Jesper [/font][font="wingdings;"] :)[/font]



#2 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 22 July 2013 - 10:18 AM

I think it is the same as the lockup i have found:

 

http://forums.netdui...s-with-a-video/



#3 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 22 July 2013 - 10:21 AM

Have you tried wrapping your socket in a using block, to ensure it gets disposed on error?

You could also add a finally block after your catch to manually call Dispose() on the socket

 

Also unplugging network cables isnt a very good test of network connectivity problems in my opinion as disconnecting the media is entirely different to intermittent connectivity to a server.  If you look at the OSI Model (http://en.wikipedia.org/wiki/OSI_model) you are trying to simulate a layer 5,6 or 7 issue by unplugging layer 1.  Generally the only time a network would fail like a unplugged cable is if someone unplugs the cable or if you have a power failure, in which case (unless you are running on batteries) your ND will probably be power cycled as well...

 

 

The way i have tested for things like that in the past is to have the server's firewall block requests, or have the software black hole random requests, so the socket is left hanging etc.

 

Nak.



#4 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 22 July 2013 - 10:50 AM

JoopC, Yes it seems to be the same, but Im not sure i understand how you fixed your problem :)

 

Nakchak, thats correct, its not the same like disconnection the router or blocking the traffic with a firewall, but it doesnt change anything at all. The same happen, so its just easier to unplug the cable to simulate it. (And it should still work) :)

I cant wrap it inside a using block, it would be possible to use the socket after the using block ends, it has to stay open all the time. Thats the reason why it is set to a global variable at the end.

There doesnt exist any "Dispose()" on the socket class in the micro framework.?

 

But again i cant see what that would help, because it fails creating a local socket that isnt even connected or anything, only the parameters are set?



#5 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 22 July 2013 - 11:13 AM

JoopC, btw. i have also found out that there are no Connection Timeout on  "Dns.GetHostEntry("api.pachube.com")" and the "Socket.Connect()" - So what you are facing is the timeout problem, (seems like it), because it stops printing out your debug information, but i could be wrong.

 

The only way i can find to fix the problem is to create a watchdog that need to be triggered after "new Socket(..)" - But thats not a solution, its just a work around and the problem will still exist







Also tagged with one or more of these keywords: Problem, Netduino plus 2, Ethernet

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.