After setting 'system time' on UNO WiFi Rev2 does it automatically update?

After using time.h's getTime() function and using set_system_time()
I expected system time to automatically update.
Either I did not set it correctly or fail to understand the interaction between getTime() and set_system_time().
When I read 'tnow' it does not increment but is static.
Is it necessary to use getTime() every void loop() cycle to monitor
the epoch time value?

#include <SPI.h>
#include <WiFiNINA.h>
#include <time.h>
#include "arduino_secrets.h"


int reconnects = 0;  // how many times you've reconnected to the network
int lastSecond;      // last second value, for watching passing seconds
unsigned long startTime;
unsigned long epoch;
unsigned long UNIX_epoch;
unsigned long secs_Since_Midnight;

boolean time_set_Flag = false;


void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  while (!Serial)
    ;
  connectToNetwork();
}

void loop() {
  /*
  if (WiFi.status() != WL_CONNECTED) {   // if you disconnected from the network, reconnect:
    digitalWrite(LED_BUILTIN, LOW);
    connectToNetwork();
  }
  */
  if (time_set_Flag == false) {
    UNIX_epoch = WiFi.getTime();
    // set_system_time( (time_t) UNIX_epoch );
    set_system_time(UNIX_epoch);
    time_set_Flag = true;
    Serial.println();
    Serial.print("System Time has been set!");
    Serial.println();
  }
  time_t tnow;
  // struct tm lt;
  time(&tnow);
  Serial.print("System time:  ");
  Serial.println(tnow);


  secs_Since_Midnight = (UNIX_epoch - 21600) % 86400;
  Serial.println();
  Serial.print("void loop : UNIX_epoch time =  ");
  Serial.println(UNIX_epoch);
  delay(2000);
  Serial.println();
  Serial.print(" void loop: Seconds since midnight: ");
  Serial.println(secs_Since_Midnight);
  delay(2000);

  if (secs_Since_Midnight >= 55800) {
    Serial.println();
    Serial.println("............secs_Since_Midnight value triggered!!!");
    delay(2000);
  }
  //  if (secs_Since_Midnight => 86398) {
  // reset eqipment runtime counter:
  //   blr_daily_run_Millis = 0;
  //   blr_on_stop_millis   = 0;
  //   blr_daily_run_hrs    = 0;
  //   latest_on_cycle      = 0;
}

void connectToNetwork() {
  // try to connect to the network:
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("Attempting to connect to: " + String(SECRET_SSID));
    //Connect to WPA / WPA2 network:
    WiFi.begin(SECRET_SSID, SECRET_PASS);
    delay(2000);
  }
  Serial.println("connected to: " + String(SECRET_SSID));
  // You're connected, turn on the LED:
  digitalWrite(LED_BUILTIN, HIGH);
  // set the time from the network:
  //  unsigned long epoch;
  //  unsigned long secs_Since_Midnight;
  do {
    Serial.println("Attempting to get network time");
    epoch = WiFi.getTime();
    delay(10000);
  } while (epoch == 0);

  startTime = epoch;

  secs_Since_Midnight = (epoch - 21600) % 86400;  // 86400: seconds in each day; 21600: minus 6 hours [CST]
  Serial.println();
  Serial.print(" First retreival of Seconds since midnight: ");
  Serial.println(secs_Since_Midnight);

  // increment the reconnect count:
  reconnects++;
  Serial.println();
  Serial.print(" First retreival of network time is: ");
  Serial.println(startTime);
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
  Serial.print("  Signal Strength: ");
  Serial.println(WiFi.RSSI());
}

link to code:

It is not uncommon for me to be confused.....lol
I just unzipped/ installed the TimeLib library file from:

It was added into the IDE 2.0 /libraries folder and sits next to the 'Time' folder
labeled as folder 'Time-Master'. But the contents looks identical file wise.
The compiler is finding the TimeLib.h file now but I was curious why the folders look the same.

Because that is the same library as the Time library from the IDE's library manager.

The usual convention is to name the .h file after the library. The Time library originally used Time.h, but this caused a conflict with the standard c++ time.h library file when using a computer with an operating system that is not case-sensitive (does not distinguish between upper-case and lower-case letters in file names). As a consequence, the include file was changed to Timelib.h.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.