Monitor Internet Connectivity
#1
Posted 14 June 2011 - 07:21 AM
#2
Posted 15 June 2011 - 11:18 AM
#3
Posted 15 June 2011 - 12:25 PM
Are you handling?Also, I noticed that the Netduino Plus hangs up and reboots when I unplug/plug an Ethernet cable or switch off the router. Is this normal behavior? I have updated to the latest beta firmware by the way, if that's important to know.
NetworkChange_NetworkAvailabilityChanged
Please let me know if you work it out!Alternatively, how do I send a Ping command with the Netduino?
#4
Posted 15 June 2011 - 01:05 PM
Are you handling?
NetworkChange_NetworkAvailabilityChanged
That I wasn't doing! I didn't know I had to. I thought it was all automatic. Thanks for the heads up.
Please let me know if you work it out!
Sure thing. I hope I do find how to do that though.
#5
Posted 21 June 2011 - 03:51 PM
try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Timeout = 5000; Debug.Print("Accessing preset URL: " + uri); // This is where the world ends... well at least for this app! using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Debug.Print("Waiting for response..."); Debug.Print(response.ContentLength.ToString()); Debug.Print(response.ContentType); Debug.Print("Status code: " + response.StatusCode.ToString()); if (response.StatusCode == HttpStatusCode.OK) { Debug.Print("Internet connection is available"); isConnectedToInternet = true; internetConnectedLed.Write(true); break; } else { Debug.Print("Status code: " + response.StatusCode.ToString() + " received."); isConnectedToInternet = false; internetConnectedLed.Write(false); } } } catch { Debug.Print("Resolving URL failed. The network or Internet connection is down."); isConnectedToInternet = false; internetConnectedLed.Write(false); }
The freezing is quite random. Sometimes it will run for around an hour or so. Sometimes it will take a few minutes. The randomness makes it hard for me to pinpoint the problem. I'm more or less a beginner with .NETMF and C#. Any tips on how I could optimize the above code or an alternative over it?
I also noticed that the Netduino seems to switch back to a static IP randomly when the N+ is set to use DHCP with MFDeploy. It could have reset itself when it crashed. Anyone have an idea what could cause it? I'm using 4.2.0 Beta 1 firmware by the way.
#6
Posted 21 June 2011 - 09:52 PM
Hmm, very interesting. If you have a sample app which reproduces this consistently, we'd love to test this out. I belieave that there are some networking bugfixes in the .NET 4.2 codebase...hopefully they haven't accidentally introduced any glitches Either way, we'd love to look into this.I also noticed that the Netduino seems to switch back to a static IP randomly when the N+ is set to use DHCP with MFDeploy. It could have reset itself when it crashed. Anyone have an idea what could cause it? I'm using 4.2.0 Beta 1 firmware by the way.
Chris
#7
Posted 22 June 2011 - 07:01 AM
Hi devilfisch,
Hmm, very interesting. If you have a sample app which reproduces this consistently, we'd love to test this out. I belieave that there are some networking bugfixes in the .NET 4.2 codebase...hopefully they haven't accidentally introduced any glitches Either way, we'd love to look into this.
Chris
Yes, there could be a glitch somewhere on the networking code as I noticed that sometimes the EnableDHCP method doesn't work which forces me to restart my Netduino Plus. It normally works after the restart. I could tell even without using Debug as I have wired an LED to tell me if it has a valid DHCP address.
The freezing of the code I posted above seem to trigger the problem but it takes time and is very random and usually happens after a forced restart (pulling of the USB cable) following a freeze. The above code also freezes when it tries to access a local IP address that isn't in the Netduino's subnet which happens when the N+ fails to grab a DHCP address but I think this is more of an effect than a cause. Although I said "freeze", the N+ does seem to respond to other events like the InterruptPort that I wrote for the onboard switch so it's very likely that the problem has something to do with just the networking side of the N+.
I'll try reflashing it again with firmware 4.2.0 and older to see if the results are the same to pinpoint if this is a firmware problem or it could have been introduced by a slightly corrupted flashing. I'll let you know immediately what I find.
#8
Posted 22 June 2011 - 07:33 AM
#9
Posted 22 June 2011 - 07:53 AM
Quite possible that the wrong tinybooter could give a headacheBy the way, when I flashed my N+ I wasn't able to flash TinyBooterDecompressor as I didn't notice the file when I flashed the new 4.2.0 firmware. Could this be what's causing me headaches? I just saw the file now after I downloaded the archive again.
At the moment I don't have a 32-bit Windows installation to flash the bootloader. I could install Windows XP via VirtualBox but would SAM-BA work with VBox?
I haven't tried SAM-BA in a virtual environment, but I flashed my netduinos on Win7x64 without any problems.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#10
Posted 22 June 2011 - 08:11 AM
Quite possible that the wrong tinybooter could give a headache
I haven't tried SAM-BA in a virtual environment, but I flashed my netduinos on Win7x64 without any problems.
Thanks Stefan. Just installed SAM-BA on my Win7x64 system. Will do the reflash after the requested restart. I'm crossing my fingers that this fixes my problem.
#11
Posted 22 June 2011 - 08:31 AM
#12
Posted 22 June 2011 - 09:03 AM
LOL!I just erased my N+ but I can't use SAM-BA because of missing drivers. How did you get SAM-BA to work on Win7x64 Stefan?
Edit:
Oh! Don't mind anymore. Someone asked me to fix a computer which is running XP. I'll just use that. What luck!
Windows Update provided me of a proper driver. Requires a legitime version of Windows with the latest service pack though. But WinXP is a solution as well I suppose
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#13
Posted 22 June 2011 - 09:11 AM
LOL!
Windows Update provided me of a proper driver. Requires a legitime version of Windows with the latest service pack though. But WinXP is a solution as well I suppose
I see. I should have waited but I cancelled the installation from Windows Update since it was taking forever and I was thinking that the driver could be in the ATMEL folder. Silly me. I'll just do that next time.
Anyway, I've flashed the bootloader and the firmware. Will test my code and hopefully it will be glitch free now.
#14
Posted 22 June 2011 - 03:33 PM
A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
I was expecting that this was the case but I couldn't see it on the output before. The wrong bootloader might have been the cause for that.
The OutOfMemoryException was thrown when the N+ reached the following code after running it several times:
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
My code is probably quite inefficient - I'm a beginner after all - or there's a memory leak on GetResponse(). I printed out the memory usage before running GetResponse() and noticed a pattern. At first memory is around 16000 then rises to 17000 or 19000. From then on it starts dropping rapidly deducting more than 2000 on every iteration until memory dwindles to nothingness inevitably inducing major head trauma to me... well, ignore the last part... I've been losing hair (not literally, or course ) this past few days because of this code so I was trying to amuse myself. Hehehe!
Additionally, to better isolate the problem I completely removed the try/catch statement from my code to see if getting the GetResponse() out would equal to no problems. As expected the freezing disappeared and I confirmed that the try/catch statement containing my HTTP web request code is the culprit.
I'm now thinking of discarding HttpWebRequest so I'm looking for better alternatives. Any suggestions? Would sockets work for this? I'm a total noob about sockets though - currently reading information about it. If you think sockets would be better please hint me.
Another idea I have was to use events instead of using (almost) infinite loops (which I thought was a bad idea but I had no knowledge how to get rid of them). Are there any timers I could use with the N+?
Would love to hear your inputs. Thanks!
#15
Posted 22 June 2011 - 03:38 PM
The ethernet code in the firmware is quite heavy. A beta with saving some memory exists, see this thread for more details:
http://forums.netdui...te-50-more-ram/
Not 4.2 yet though
Yes, there are. See also: http://msdn.microsof...ercallback.aspxAre there any timers I could use with the N+?
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#16
Posted 22 June 2011 - 05:15 PM
#17
Posted 26 June 2011 - 08:20 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users