NTP Server and Static IP

Discussion to talk about software related topics only.
SeeCwriter
Posts: 608
Joined: Mon May 12, 2008 10:55 am

NTP Server and Static IP

Post by SeeCwriter »

Most of our customers using static IP addresses for the products they use. It was reported to me that when using DHCP, setting time from the NTP server pool works, but when using static IP it does not. Other than an IP, netmask, and router, is there some other setting required to use the SetTimeNTPFromPool)_ function?
User avatar
TomNB
Posts: 541
Joined: Tue May 10, 2016 8:22 am

Re: NTP Server and Static IP

Post by TomNB »

Definitely. You need valid static gateway and DNS settings as well.
SeeCwriter
Posts: 608
Joined: Mon May 12, 2008 10:55 am

Re: NTP Server and Static IP

Post by SeeCwriter »

The router/gateway IP is set. And I thought the NTP server DNS names were

Code: Select all

const char *NTP_POOL_Servers[] =
{
   "0.pool.ntp.org",
   "1.pool.ntp.org",
   "2.pool.ntp.org",
   "\0"
};
What else is needed?
User avatar
TomNB
Posts: 541
Joined: Tue May 10, 2016 8:22 am

Re: NTP Server and Static IP

Post by TomNB »

If you have valid settings for IP, Mask, Gateway, and DNS, then it would be the same as DHCP. What are those four settings for DHCP vs. your static settings?
SeeCwriter
Posts: 608
Joined: Mon May 12, 2008 10:55 am

Re: NTP Server and Static IP

Post by SeeCwriter »

The mask & gateway are the same. But the IP is different. Some IP addresses on our network reserved for static so they are not given out by the DHCP server. Our customers prefer static ip addresses. And there are 2 DNS server IPs available on our network, which seems odd but doesn't matter.

In our unit there are a set of network parameters that are in non-volatile memory for static ip configuration. On boot-up the computer checks the DHCP setting, and if set for DHCP it goes with that, and if it's static the computer loads the static configuration. And while running a command can be sent to the computer to change from DHCP to static and vice versa. That all works. But now that we added DNS IP to the configuration, when we switch from DHCP to static the DNS IP does not take effect. We have to reboot the unit to get DNS to work. Is there something else to do?

Code: Select all

  InterfaceBlock *ib  = GetInterFaceBlock(CONFIG_IF_ID_ETHERNET);

  EnableDHCP( false, 0 );
  SS->use_dhcp  = FALSE; 
  ib->netIP         = SS->ip_address; 
  ib->netIpMask = SS->ip_mask;
  ib->netIpGate = SS->ip_gateway;
  ib->netDNS    = SS->ip_dns; 


void EnableDHCP(BOOL enable, int wait_seconds)
  {
  static int ethernet = GetFirstInterface();
  static DhcpObject *dhcp_client = new DhcpObject(ethernet);

  if (enable) dhcp_client->StartDHCP();
  else        dhcp_client->StopDHCP();

    if (enable && wait_seconds)
    {
         OSSemPend(&dhcp_client->NotifySem, wait_seconds*TICKS_PER_SECOND); 
    }
  }

User avatar
TomNB
Posts: 541
Joined: Tue May 10, 2016 8:22 am

Re: NTP Server and Static IP

Post by TomNB »

When you switch from dhcp to static are you:
1. Stopping the dhcp client
2. Assigning all the static settings to the runtime system variables?

That is why I was asking previously for the specific information on addresses. If you print them out after you make the switch do they match the static settings?
SeeCwriter
Posts: 608
Joined: Mon May 12, 2008 10:55 am

Re: NTP Server and Static IP

Post by SeeCwriter »

All the parameters are the same except for the IP address. But I don't understand why it matters. What if they were all different, but valid? As the code in my previous post shows, the DHCP client is being stopped and the static network parameters set.
User avatar
TomNB
Posts: 541
Joined: Tue May 10, 2016 8:22 am

Re: NTP Server and Static IP

Post by TomNB »

What about item 2? I don't see that in your code. If you don't want to print out the runtime IP settings and tell me what they are I can't help much more. Lets try a different angle: take a look at the ChangeIP example and compare it to your code. You can also run it unmodified to verify you can change between static and dynamic. There is also a section in the programmers guide that explains how it works.
SeeCwriter
Posts: 608
Joined: Mon May 12, 2008 10:55 am

Re: NTP Server and Static IP

Post by SeeCwriter »

Here is item 2:

Code: Select all

InterfaceBlock *ib  = GetInterFaceBlock(CONFIG_IF_ID_ETHERNET);

  EnableDHCP( false, 0 );   // Disable DHCP
  SS->use_dhcp  = FALSE; 
  ib->netIP         = SS->ip_address; // Set Static IP...
  ib->netIpMask = SS->ip_mask;
  ib->netIpGate = SS->ip_gateway;
  ib->netDNS    = SS->ip_dns; 

Yes, we can switch between static and dhcp. It's just the the DNS IP doesn't work when switching to static ip without doing a reboot.
User avatar
TomNB
Posts: 541
Joined: Tue May 10, 2016 8:22 am

Re: NTP Server and Static IP

Post by TomNB »

If all 4 IP values are correct, I can't think of any reason it would not work. Since it works after reboot my guess is somehow the runtime values are not set properly. The next step would be to get a wireshark capture of the attempt to use DNS that fails.
Post Reply