Skip to content

WiFi.getTime() function on WiFiS3 library doesn't work #206

Closed
@tigoe

Description

@tigoe

The getTime() function in the WiFiS2 library never gets the time via NTP.

Here's a test:

#include <WiFiS3.h>            // use this for the Uno R4 WiFi board
#include "arduino_secrets.h"  // put SECRET_SSID and SECRET_PASS here

// the epoch time, obtained from the network:
unsigned long epoch = 0;

void setup() {
  // initialize serial:
  Serial.begin(9600);
}

void loop() {
  // if not connected, attempt to connect:
  if (WiFi.status() != WL_CONNECTED) {
    connectToNetwork();
  }
}

void connectToNetwork() {
  Serial.print("Attempting to connect to network ");
  Serial.println(SECRET_SSID);
  // try to connect to the network:
  while (WiFi.status() != WL_CONNECTED) {
    //Connect to WPA / WPA2 network:
    WiFi.begin(SECRET_SSID, SECRET_PASS);
    delay(2000);
  }
  // print out the device's network status:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the signal strength:
  Serial.print("Signal Strength: ");
  Serial.println(WiFi.RSSI());
  // get network time:
  getNetworkTime();
}

void getNetworkTime() {
  do {
    epoch = WiFi.getTime();
    delay(2000);
    Serial.println("NTP request attempt");
  } while (epoch <= 0);
}

When you run this on the Uno R4 WiFi, it'll compile, but you'll get an endless stream of "NTP request attempt" messages.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions