DHCP vs static IP [solved]

Hi Folks,

Need your help again. Modified the sample sketch to retrieve NTP time a little. Everything is fine when I use DHCP. Setting it to fixed IP, that’s what I actually want to have, the NTP won’t be retrieved. Code see below. Tried a lot of things but still don’t have a clue about the reason. The static set myIP, myDns, myGw, mySnm are identical to what I get by DHCP, however other local IPs aren’t working as well.

Any ideas?

Thanks in advance

  • Tuxuser
#include <UIPEthernet.h>
#include <UIPUdp.h>

IPAddress myIp (192, 168, 1, 105);
IPAddress myDns (192, 168, 1, 1);
IPAddress myGw (192, 168, 1, 1);
IPAddress mySnm (255, 255, 255, 0);

IPAddress timeServer (132, 163, 4, 101);
const int NTP_PACKET_SIZE = 48;
byte packetBuffer [NTP_PACKET_SIZE];


unsigned long ntpTimeStamp = 0;

EthernetUDP udp;

void setup() {

  Serial.begin(115200);
  delay (200);
  Serial.println (F("Basic NTP Server with NTP Client"));

  uint8_t myMac[6] = {0x02,0x01,0x02,0x03,0x04,0x05};

  // Not working
//  Ethernet.begin(myMac, myIp, myDns, myGw, mySnm);
  
  // Working
  Ethernet.begin(myMac);


  Serial.print("Initialize UDP: ");
  int success = udp.begin((unsigned int) 8888);
  
  Serial.println(success ? "success" : "failed");
  
  Serial.print (F("My IP: "));
  Serial.println(Ethernet.localIP());
  Serial.print (F("My DNS: "));
  Serial.println(Ethernet.dnsServerIP());
  Serial.print (F("My Gateway: "));
  Serial.println(Ethernet.gatewayIP());
  Serial.print (F("My Mask: "));
  Serial.println(Ethernet.subnetMask());
  

  int attemptNo = 0;
  while (attemptNo < 60 && ntpTimeStamp == 0) {
    Serial.print (F("NTP Attempt: "));
    Serial.print (attemptNo);
    Serial.print (F("\t"));
    getNtpTime ();
    attemptNo++;
  }
  
  for (;;);
}

Got it - had to open my eyes more widely. It's seems to be a matter of my router (Fritz!box 7390) preventing non-dhcp clients to access the internet - Rats!

Tuxuser: Got it - had to open my eyes more widely. It's seems to be a matter of my router (Fritz!box 7390) preventing non-dhcp clients to access the internet - Rats!

I don't see that in the manual. You must use the correct ip, subnet and gateway. I always recommend using an ip that is not in the range of the dhcp server. I would try this for your static ip settings.

IPAddress myIp (192, 168, 178, 2);
IPAddress myDns (192, 168, 178, 1);
IPAddress myGw (192, 168, 178, 1);
IPAddress mySnm (255, 255, 255, 0);

The dhcp server by default (according to the manual page 155) uses 192.168.178.20 to 192.168.178.200. Don't use those ip addresses. http://www.avm.de/en/service/manuals/FRITZBox/Manual_FRITZBox_Fon_WLAN_7390.pdf

Hi SurferTim

I don't have a proof until I get response from AVM but I have some evidence:

  • Regardless of inside or outside the DCHP server range it does not work.
  • An Android tablet set to manual IP shows the same effect
  • The Arduino appears as connected with the Fritzbox but the "globe icon" indicating an internet connection is not presented, means: connected with the box but not with the internet"
  • LAN connections with the Arduino are working smoothly

There must be some filtering or firewall settings inside the Fritzbox which are not well documented at all...

You should not post erroneous code. We expect the code you are posting is the code you are using. These settings will certainly not work.

IPAddress myIp (192, 168, 1, 105);
IPAddress myDns (192, 168, 1, 1);
IPAddress myGw (192, 168, 1, 1);
IPAddress mySnm (255, 255, 255, 0);

BTW, page 156 of that manual shows how to assign static ips on the localnet. Three requirements: 1) The ip must be in the localnet ip network range. 2) The ip must not be in the dhcp server range. 3) The ip must not be a duplicate.

edit: They forgot rule #4. Unless you have changed the ip of the localnet interface: 4) The gateway must be 192.168.178.1

Seems I could not make it clear:

One: [u]it is the code[/u] I'm using but with different "myIP" addresses. That's what I tried to tell in my original post.

Two: A gateway address with 192.168.178.1 (i.e. a subnet 192.168.178.0/8) does not make any sense in my case, it not my gateway address because my subnet is 192.168.1.0/8. Hoped it would be recognizable with mentioning that all setting are identical to what I get when using DHCP but obviously wasn't. Furthermore I again confirm to have checked with in- and out-of-range DHCP addresses. Yes, 192.168.1.105 is incorrect acc to the manual if DHCP is active, but e.g. 192.168.1.230 is definitely out of range of my DHCP (set to 100 to 110 only) nor a duplicate and does not work either.

[u]However, I'm not considering this forum to discuss Fritzbox related issues[/u] and therefore I will not bother with this issue here anymore. Please apologize (after hours of suspecting a code error) a post still a little too early but I'm hoping that some readers may find it valuable that this code in general works and to guide their view to other possible error sources.

Please apologize (after hours of suspecting a code error) a post still a little too early but I’m hoping that some readers may find it valuable that this code in general works and to guide their view to other possible error sources.

Other users will find it helpful.

@other users: Don’t use the OP’s network settings for a Fritzbox. Leave them (edit: the settings in the router) alone and use what I suggested. There is no need for 16 million localnet ips. The default 254 should be enough.