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

DHCP startup problem


  • Please log in to reply
14 replies to this topic

#1 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 19 July 2012 - 07:02 AM

I have a problem to solve with the internet. I use the Netduino for datalogging. I startup the Netduino on the same time as my router with a timer. But the Netduino starts faster then my router with the result that the router don't "see" my Netduino (he is not in the DHCP table). When I pull out and pull in the AC plug of the Netduino, the Netduino/internet works oké. What can I do the best?, buy a second timer and set the Netduino startup time later, or can I solve the problem in the software. Thanks in advance. Ellen

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 July 2012 - 07:59 AM

Hi Ellen!

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?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 19 July 2012 - 08:14 AM

I have to ask why do you have a Router on a timer? They are designed to be left switched on... You can experience hardware faults on a router (certainly on cheap ones) through repeated power cycling. That said I may have just had a bad batch of routers with dodgy power supplies. Also if its for "energy saving" reasons you actually negate any benefit from the inrush current when the power brick gets power... Nak.

#4 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

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. B)
..., why must the modem/router stays on when I do not use him, more then 12 hours a day?

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 July 2012 - 09:22 AM

Nak, Dutch people are economical, frugal and also parsimonious. B)

Oh dear, I can't disagree on that ;)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

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 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 July 2012 - 09:46 AM

Thxs Stefan,

Would this work?
Thank you in advance.

Looks complicated to me. Not sure if it would work. By the way, I see you prefer Visual Basic, no problem :)

I could work out some code for you tonight. Currently not at home so no Netduino around to test something.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 19 July 2012 - 10:51 AM

Nak, Dutch people are economical, frugal and also parsimonious. B)
..., 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.



Nak.

#9 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

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:

  • 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.


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 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 22 July 2012 - 10:52 AM

Hi Ellen, I've tried to reproduce this and stumbled on some things. Attached, you'll find a project in VB that, in the end, gets a connection. There are a few things to consider though, and things I'm going to dive deeper into. Keep in mind that VB-support is still in beta (4.2 beta to be exact). Two issues I encountered: - When plugging in the cable, while the device is powered on won't do a thing - A DHCP release/renew while a debugger is attached (for example Visual Studio, or MFDeploy.exe) won't work. As soon as I released the debugger, it got it's IP address immediately. 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

Attached Files


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

Posted 26 July 2012 - 05:43 AM

Stefan thanks, I have implement your snippet into my source code. Now I am testing it, thats take a while in time. I will let you know. Ellen.

#12 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 July 2012 - 08:46 AM

I will let you know.

Okay, cool. I hope it helps. If not, we'll figure something out.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#13 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

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 Ellen

Ellen

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationRotterdam, Netherlands

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 David_G

David_G

    New Member

  • Members
  • Pip
  • 3 posts

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

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.