DHCP startup problem
#1
Posted 19 July 2012 - 07:02 AM
#2
Posted 19 July 2012 - 07:59 AM
With this code you could let your Netduino do an IP release/renew:
using Microsoft.SPOT.Net.NetworkInformation; NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); interfaces[0].ReleaseDhcpLease(); interfaces[0].RenewDhcpLease();
With a bit more work, you could check if the interface has an IP. If not, wait a second, renew, check again.
Does that help?
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#3
Posted 19 July 2012 - 08:14 AM
#4
Posted 19 July 2012 - 09:18 AM
I have to ask why do you have a Router on a timer?
They are designed to be left switched on...
Nak.
Nak, Dutch people are economical, frugal and also parsimonious.
..., why must the modem/router stays on when I do not use him, more then 12 hours a day?
#5
Posted 19 July 2012 - 09:22 AM
Oh dear, I can't disagree on thatNak, Dutch people are economical, frugal and also parsimonious.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#6
Posted 19 July 2012 - 09:36 AM
With a bit more work, you could check if the interface has an IP. If not, wait a second, renew, check again.
Thxs Stefan,
Would this work?
Thank you in advance.
Try dim connection As Socket = Connect(strHost, 5000) If connection Is Nothing then Else 'do something' End if Catch Ex As Exception End Try
Private Function Connect(ByVal host As String, ByVal timeout As Integer) As Socket ' look up hosts domain name to find IP address(es) ' Dim hostEntry As IPHostEntry = Dns.GetHostEntry(host) ' extract a returned address ' Dim hostAddress As IPAddress = hostEntry.AddressList(0) Dim remoteEndPoint As New IPEndPoint(hostAddress, 80) Dim connection = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) connection.Connect(remoteEndPoint) connection.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, True) connection.SendTimeout = timeout Return connection End Function
#7
Posted 19 July 2012 - 09:46 AM
Looks complicated to me. Not sure if it would work. By the way, I see you prefer Visual Basic, no problemThxs Stefan,
Would this work?
Thank you in advance.
I could work out some code for you tonight. Currently not at home so no Netduino around to test something.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#8
Posted 19 July 2012 - 10:51 AM
Nak, Dutch people are economical, frugal and also parsimonious.
..., why must the modem/router stays on when I do not use him, more then 12 hours a day?
Heh cant argue with that i guess, well here is something you could try (my vb is quite rusty so probably wont work, but should give you an idea), essentially the sub will block until the router has powered up and connected to the net (which can take a few minutes here in the UK, unsure about the Dutch Telecom's infrastructure seem to remember it being pretty good when i spent some time over there a few years ago...)
Private Sub HasNetAccess() While(Dns.GetHostEntry("www.google.com") Is Nothing) Thread.Sleep(10000) 'Sleep for 10 secs then try and connect again End While Dim interfaces = NetworkInterface.GetAllNetworkInterfaces() As NetworkInterface interfaces(0).ReleaseDhcpLease(); interfaces(0).RenewDhcpLease(); End Sub
Although this probably wont work as it requires a DHCP allocated IP address for the initial DNS lookup, are static IP's totally out of the question for your application? As the only reliable methods i can think of to obtain IP's are:
- Leave the router on, then you can have an expectation of having a DHCP server availible
- Use a second timer plug and delay it for 5 to 10 mins to allow router to boot and get online.
- Use a static IP on your netduino.
Nak.
#9
Posted 22 July 2012 - 08:32 AM
Although this probably wont work as it requires a DHCP allocated IP address for the initial DNS lookup, are static IP's totally out of the question for your application? As the only reliable methods i can think of to obtain IP's are:
Nak.
- Leave the router on, then you can have an expectation of having a DHCP server availible
- Use a second timer plug and delay it for 5 to 10 mins to allow router to boot and get online.
- Use a static IP on your netduino.
I have set the Netduino with a static IP as you proposed.
Startup Modem/router at the same time as the Netduino with the timer.
I had programmed a 3 minute software delay in the Netduino before sending to the internet.
The modem was ready but NO, socket error.
Netduino out and in the AC, (the router is still on) and it's works fine.
Strange is not it?
#10
Posted 22 July 2012 - 10:52 AM
Attached Files
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#11
Posted 26 July 2012 - 05:43 AM
#12
Posted 26 July 2012 - 08:46 AM
Okay, cool. I hope it helps. If not, we'll figure something out.I will let you know.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#13
Posted 30 July 2012 - 06:17 AM
Okay, cool. I hope it helps. If not, we'll figure something out.
Hi Stefan,
Now every day the Netduino starts as it should be without any errors.
Thank you for share the programm code.
Ellen
#14
Posted 12 August 2012 - 06:48 PM
Hi Stefan,
Now every day the Netduino starts as it should be without any errors now errors again.
Thank you for share the programm code.
Ellen
UPDATE.... BUG REPORT maybe?
After a few days without internet startup errors, now again.
So I went to have a closer look about this problem.
The bottom line is when the Netduino is running before the router is powered up, there is no way to establising the connection without reseting the Netduino.
This Netduino reboot should not to be a problem if I can write to the SD Card but I do not have a small 1 or 2 gieg card, larger is not supported in 4.2 untill now.
Workeround with writing to sd.....
Startup Netduino
If internet....
If file existe("alreadyBooted")
delete file
endif
end if
If not internet ....
If file existe("alreadyBooted")
...no second reboot.
...internet can not be restored ... already tried.
Else
write dummy file to sd card filecreate("alreadyBooted")
reboot
endif
This is to prevent a forever reboot.
It is wonderfull when we have a static memory of 1 byte.
#15
Posted 06 October 2012 - 05:07 AM
Still, I think the attached code would work for you. What it does:
- Every second it'll check if it has an IP address
- After 5 seconds it'll do a ip release/renew
- After 10 seconds it'll do a full reboot
Hi,
Just a thought about that Module1.vb code, which in my case wouldn't solve my problem ....
The problem is if the router resets while the ND+ is running, and a different IP address assigned. Let's say ND+ has an IP of 192.168.1.1 and is ticking along fine. The router resets and assigns 192.168.1.2 (and this is shown in the router DHCP table). Trouble is ND+ thinks its IP is still 192.168.1.1, and is unable to connect, but the DHCP renew code doesn't do anything.
I've tried similar code in C# but even when I explicitly force the renew ...
NetworkInformation.NetworkInterface NI = NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; NI.EnableDhcp(); Thread.Sleep(2000); WriteEventLog("About to release and renew DHCP lease (first attempt). IP Address = " + NI.IPAddress); NI.ReleaseDhcpLease(); NI.RenewDhcpLease(); Thread.Sleep(2000); WriteEventLog("DHCP renewed (first attempt). IP Address = " + NI.IPAddress);it continues to returns an IP of 0.0.0.0
Using firmware Netduino_v4.1.1_beta1_CW.NETMF.OneWire-1.0.5.0
cheers
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users