[Solved] WiFi.localIP and NTP Server

Hi All,
I’ve been trying to get my Arduino Uno WiFi Rev2 to speak with an NTP server. I am having a little trouble and wondered if anyone else has seen this before. I have tried to connect two ways to an NTP server.

  1. I used my phone as a hotspot and connected to a time.nist.gov NTP server. Everything worked as expected as seen in the attached Gov time server.jpg.

  2. I set a static IP, Subnet, and Gateway and logged into my network. There is a Linux NTP server on this network that others are using. The sketch will login to my network but it gives the Gateway I assigned when it gets to the WiFi.localIP print line. I think I remember reading an article a while ago about something like this but cannot find it now. The sketch will not receive any NTP packets and appears to hang right after Starting connection to server as you can see in the My Network.jpg. So is it assigning the correct IP address or is it really trying to use the Gateway IP as the IP address and that’s why I cannot receive any packets back?

Appreciate the help!

sketch_feb13a.ino (5.04 KB)

My network.jpg

Gov time server.jpg

I found an old post from SurferTim (http://forum.arduino.cc/index.php?topic=292723.) outlining that unlike Ethernet shields the WiFi.config() function does not assign the other network settings with defaults (like gateway and subnet) if you do not specify them. You must specify the dns server, gateway, and subnet in order to access the internet. Since I am not resolving domain names, I needed to use the gateway as the DNS server as you can see in the sketch and list here below.

WiFi.config(ip, gateway, gateway, subnet);

Working_NTP_and_Static_IP_code.ino (5.88 KB)