How to use function RTC.setTime() inside the loop() ?

The question is about regularly correcting the RTC time on my UNO R4 WiFi with data 'from outside'.
I am not using a NTP service, I made a webpage that presents the time [as on the commercial server] in simple text format.

So while in the loop() I can repeatedly correct the RTC time (cause that is not reliable within an hour or less).
My problem is constructing the arguments for the RTC.setTime() function [from <RTC.h>]:

  RTCTime startTime(9, Month::JANUARY, 2024, 22, 00, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_INACTIVE);
  RTC.setTime(startTime);

I think I see integers, mixed with arguments of type(?) Month, DayOfWeek, SaveLight .
Not the vaguest idea how to deliver those! Tried integers, no success. And every argument is needed, or a compiling error occurs.

I hope this is formulated clear enough. Eventually also help me with How I could have figured this out myself (I must have looked in all the wrong places...)

you can access the source code to see what the types are

the constructor:

RTCTime(int _day, Month _m, int _year, int _hours, int _minutes, int _seconds, DayOfWeek _dof, SaveLight _sl);

Month is an enum:

enum class Month : uint8_t {
    JANUARY = 0,
    FEBRUARY,
    MARCH,
    APRIL,
    MAY,
    JUNE,
    JULY,
    AUGUST,
    SEPTEMBER,
    OCTOBER,
    NOVEMBER,
    DECEMBER
};

same for DayOfWeek

enum class DayOfWeek : uint8_t {
    MONDAY = 1,
    TUESDAY = 2, 
    WEDNESDAY = 3, 
    THURSDAY = 4, 
    FRIDAY = 5, 
    SATURDAY = 6, 
    SUNDAY = 0
};

same for SaveLight

enum class SaveLight : uint8_t {
    SAVING_TIME_INACTIVE = 0,
    SAVING_TIME_ACTIVE
};

Hm... I tried to find out enough about enum to be able to get on, AND I did not want to react quite late.

I tried this:

 enum mnd;
  // resulted in:   error: use of enum 'mnd' without previous declaration
mnd = Month::JANUARY;
  // resulted in:   error: 'mnd' was not declared in this scope

RTCTime startTime(9, mnd, 2024, 22, 00, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_INACTIVE);

As you can see I still stumble. I read about declaring an enum and using it in an if statement, but cannot apply something like it for arguments to a function.

I also tried a different approach (after consulting RTC.h):

RTCTime startTime(9, Month::JANUARY, 2024, 22, 00, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_INACTIVE);
if (!startTime.setMinute((int) 19)) Serial.println("Error setting Minute");
startTime.setSecond((int) 53);
startTime.setMonthOfYear((Month) 3);

RTC.setTime(startTime);
Serial.print("Seconden:  ");
Serial.println(currentTime.getSeconds());

Effect: nothing shown over 'Serial'.

So, please take me by the hand and give me an example of the proper use of these enums into a function.

Hi @soverhad
welcome to the arduino-forum.

You should really post your complete sketch.
"nothing shown over serial" sounds like a different problem.
And based on your code-snippet

you should at least see the word "Seconden:" in the serial monitor
if you really see nothing
this means either in the not shown part of your code is a logical problem
or
reason B
or
reason C
or......

Analysing what is going on can be solved ten times faster if you post your complete sketch

I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

best regards Stefan

I understand. Had to do a lot of cleaning, because I have the habit of commenting out everything that I tried and that did not succeed yet... A lot of clutter!

Now most is cleaned up. My code:

/*
  *** Repeating WiFi Web Client ***
  This sketch connects to a a web server and makes a request
  using a WiFi equipped Arduino board.   
  [by NN, Tom Igoe, Federico Vanzati   23-04-12 - 13-01-14 ]
  Find the full UNO R4 WiFi Network documentation here:
  https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#wi-fi-web-client-repeating
*/

#include "WiFiS3.h"
#include "secrets.h" 
int keyIndex = 0;
int status = WL_IDLE_STATUS;


#include "Base4_4Col.h"
#include "RTC.h"

#define DGH_line 9
#define DGM_line 10

#define DG_01 0
#define DG_02 1
#define DG_03 2
#define DG_04 3
#define DG_08 4
#define DG_12 5
#define DG_16 6
#define DG_32 7
#define DG_48 8

#include "Arduino_LED_Matrix.h"


/* ============================================== */
WiFiClient client;                                 // Initialize the WiFi client library

char server[] = "hygrometer.wissisch.nl";          // server address

unsigned long lastConnectionTime = 0;              // last time you connected to the server, in milliseconds
const unsigned long inquireInterval = 10L * 1000L; // delay between updates, in milliseconds

String findTimeLine = "";
bool fillTimeLine = true;
bool verbose = false;

/* ============================================== */
ArduinoLEDMatrix matrix;                           // Initialize the LED Matrix

unsigned long lastShownHours = 0;
unsigned long lastShownMinutes = 0;
const unsigned long showTimeInterval = 10L * 1000L;

int secNow;
uint32_t showNow[3];
uint8_t frame[8][12];

/* -------------------------------------------------------------------------- */
void setup() {
/* -------------------------------------------------------------------------- */ 
enum mnd = Month::JANUARY;    // to find out if I can get 'enum' use right

  //Initialize serial and wait for port to open:
  Serial.begin(9600);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    // delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();

  RTC.begin();

  // manually sets the RTC with an explicit date & time, for example to set
  // January 21, 2021 at 3am you would call:
  // rtc.adjust(DateTime(2021, 1, 21, 3, 0, 0));
        //  CAN'T get that to work...

//  RTCTime startTime(9, Month::JANUARY, 2024, 22, 00, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_INACTIVE);
// the above is working, but it is fixed: I don't know how to feed it different times using variables
// Then I would do THAT inside  loop()

RTCTime startTime(9, mnd, 2024, 22, 00, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_INACTIVE);   
// the above is  to find out if I can get 'enum' use right

if (!startTime.setMinute((int) 19)) Serial.println("Error setting Minute");
startTime.setSecond((int) 53);
startTime.setMonthOfYear((Month) 3);
RTC.setTime(startTime);
/*    FOUND:
    bool setMonthOfYear(Month m); // month from 1 (January) to 12 (December) 
    bool setYear(int year); // the year 1989 or 2022 
    bool setHour(int hour); // from 0 (midnight) to 23 
    bool setMinute(int minute); // from 0 to 59 
*/

   RTCTime currentTime;
  Serial.print("Seconden:  ");
  Serial.println(currentTime.getSeconds());

/* ============================================== */
  matrix.begin();

  uint8_t frame[8][12] = {
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  };

  RTC.begin();

}

/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_request() {
/* -------------------------------------------------------------------------- */  
  uint32_t received_data_num = 0;

  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    buildTimeLine(c);    // distills the Date and Time for correcting the R4's RealTimeClock
    /* print data to serial port */
    if (verbose) Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if(received_data_num % 80 == 0) { 
      
    }
    
  }  
}

/* -------------------------------------------------------------------------- */
void buildTimeLine(char nu){
/* -------------------------------------------------------------------------- */
  if (fillTimeLine) findTimeLine += (String)nu;
  if(findTimeLine.substring(findTimeLine.length() - 7) == "<body>\n") findTimeLine = "";        // strip info before
  if(findTimeLine.substring(findTimeLine.length() - 6) ==  "ACTIVE")  fillTimeLine = false;     // ignore info after
}



// Mix of Getting the correct time   and   Showing the Base4 depicted Hours and Minutes 
/* -------------------------------------------------------------------------- */
void loop() {
/* -------------------------------------------------------------------------- */  
  RTCTime currentTime;

  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  read_request();
  
  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > inquireInterval) {
    httpRequest();
    Serial.println(">>>" + findTimeLine + "<<<");
  //  RTC.setDateTime(__DATE__, __TIME__);
    findTimeLine = "next Go...";
    fillTimeLine = true;
  }
/*
  if (millis() - lastShownHours > showTimeInterval) {
    showMatrixHours(currentTime.getHour());
    Serial.println("Hours:   " + currentTime.getHour());
  }

  if (millis() - lastShownHours > showTimeInterval + 4000) {  
    showMatrixMinutes(currentTime.getMinutes());
 //   Serial.println("Minutes: " + currentTime.getMinutes());
  }
*/
}
//    TODO:
// zet gelijk, 4 sec de uren, 6 sec de minuten zichtbaar, 
// graag elke 5 sec een stap van de wandelende stip...


// this method makes a HTTP connection to the server:
/* -------------------------------------------------------------------------- */
void httpRequest() {
/* -------------------------------------------------------------------------- */  
  // close any connection before send a new request.
  // This will free the socket on the NINA module
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    if (verbose) Serial.println("connecting...");
    // send the HTTP GET request:
    client.println("GET /timeline.php HTTP/1.1");
    client.println("Host: hygrometer.wissisch.nl");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
    // note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

/* -------------------------------------------------------------------------- */
void printWifiStatus() {
/* -------------------------------------------------------------------------- */  
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

// Here follow the functions for the Clock functionality
/* ========================================================================== */

/* -------------------------------------------------------------------------- */
void clearMatrix(){
/* -------------------------------------------------------------------------- */
  uint32_t showNow[3] = {
		0x0,
		0x0,
		0x0
	};
  matrix.loadFrame(showNow);
}

/* -------------------------------------------------------------------------- */
void showMatrixHours(int numb){    // respectively number of Hours or Minutes, 
                                            // and Which is it of those two
/* -------------------------------------------------------------------------- */
  int frameNr;
  // Empty matrix with Hours-marker:
      showNow[0] = Base4_4Col[DGH_line][0];
      showNow[1] = Base4_4Col[DGH_line][1];
      showNow[2] = Base4_4Col[DGH_line][2];

      while (numb > 0){
        if (numb >= 16){
          showNow[0] |= Base4_4Col[DG_16][0];
          showNow[1] |= Base4_4Col[DG_16][1];
          showNow[2] |= Base4_4Col[DG_16][2];
          numb -= 16;
        }
        if (numb >= 12){
          showNow[0] |= Base4_4Col[DG_12][0];
          showNow[1] |= Base4_4Col[DG_12][1];
          showNow[2] |= Base4_4Col[DG_12][2];
          numb -= 12;
        }
        if (numb >= 8){
          showNow[0] |= Base4_4Col[DG_08][0];
          showNow[1] |= Base4_4Col[DG_08][1];
          showNow[2] |= Base4_4Col[DG_08][2];
          numb -= 8;
        }
        if (numb >= 4){
          showNow[0] |= Base4_4Col[DG_04][0];
          showNow[1] |= Base4_4Col[DG_04][1];
          showNow[2] |= Base4_4Col[DG_04][2];
          numb -= 4;
        }
        if (numb >= 3){
          showNow[0] |= Base4_4Col[DG_03][0];
          showNow[1] |= Base4_4Col[DG_03][1];
          showNow[2] |= Base4_4Col[DG_03][2];
          numb -= 3;
        }
        if (numb >= 2){
          showNow[0] |= Base4_4Col[DG_02][0];
          showNow[1] |= Base4_4Col[DG_02][1];
          showNow[2] |= Base4_4Col[DG_02][2];
          numb -= 2;
        }
        if (numb >= 1){
          showNow[0] |= Base4_4Col[DG_01][0];
          showNow[1] |= Base4_4Col[DG_01][1];
          showNow[2] |= Base4_4Col[DG_01][2];
          numb -= 1;
        }
      }
      matrix.loadFrame(showNow);
} 
    
/* -------------------------------------------------------------------------- */
void showMatrixMinutes(int numb){
/* -------------------------------------------------------------------------- */
  // Empty matrix with Minutes-marker:
      showNow[0] = Base4_4Col[DGM_line][0];
      showNow[1] = Base4_4Col[DGM_line][1];
      showNow[2] = Base4_4Col[DGM_line][2];

      while (numb > 0){
        if (numb >= 48){
          showNow[0] |= Base4_4Col[DG_48][0];
          showNow[1] |= Base4_4Col[DG_48][1];
          showNow[2] |= Base4_4Col[DG_48][2];
          numb -= 48;
        }
        if (numb >= 32){
          showNow[0] |= Base4_4Col[DG_32][0];
          showNow[1] |= Base4_4Col[DG_32][1];
          showNow[2] |= Base4_4Col[DG_32][2];
          numb -= 32;
        }
        if (numb >= 16){
          showNow[0] |= Base4_4Col[DG_16][0];
          showNow[1] |= Base4_4Col[DG_16][1];
          showNow[2] |= Base4_4Col[DG_16][2];
          numb -= 16;
        }
        if (numb >= 12){
          showNow[0] |= Base4_4Col[DG_12][0];
          showNow[1] |= Base4_4Col[DG_12][1];
          showNow[2] |= Base4_4Col[DG_12][2];
          numb -= 12;
        }
        if (numb >= 8){
          showNow[0] |= Base4_4Col[DG_08][0];
          showNow[1] |= Base4_4Col[DG_08][1];
          showNow[2] |= Base4_4Col[DG_08][2];
          numb -= 8;
        }
        if (numb >= 4){
          showNow[0] |= Base4_4Col[DG_04][0];
          showNow[1] |= Base4_4Col[DG_04][1];
          showNow[2] |= Base4_4Col[DG_04][2];
          numb -= 4;
        }
        if (numb >= 3){
          showNow[0] |= Base4_4Col[DG_03][0];
          showNow[1] |= Base4_4Col[DG_03][1];
          showNow[2] |= Base4_4Col[DG_03][2];
          numb -= 3;
        }
        if (numb >= 2){
          showNow[0] |= Base4_4Col[DG_02][0];
          showNow[1] |= Base4_4Col[DG_02][1];
          showNow[2] |= Base4_4Col[DG_02][2];
          numb -= 2;
        }
        if (numb >= 1){
          showNow[0] |= Base4_4Col[DG_01][0];
          showNow[1] |= Base4_4Col[DG_01][1];
          showNow[2] |= Base4_4Col[DG_01][2];
          numb -= 1;
        }
      }
  matrix.loadFrame(showNow);
    // note the time that the connection was made:
    lastConnectionTime = millis();
}

I improved my code. Concerning this question, I am satisfied with the way things function now. Thanks for setting me on the right track!

Solution:

/*
  *** Repeating WiFi Web Client ***
  This sketch connects to a a web server and makes a request
  using a WiFi equipped Arduino board.   
  [by NN, Tom Igoe, Federico Vanzati   23-04-12 - 13-01-14 ]
  Find the full UNO R4 WiFi Network documentation here:
  https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#wi-fi-web-client-repeating
*/

bool verbose = false;
bool debugzz = false;


// for getting the date and time by WiFi communication:
#include "WiFiS3.h"
#include "secrets.h" 
#include "RTC.h"
int keyIndex = 0;
int status = WL_IDLE_STATUS;

// for depicting the time
#include "Base4_4Col.h"

#define DGH_line 9
#define DGM_line 10

#define DG_01 0
#define DG_02 1
#define DG_03 2
#define DG_04 3
#define DG_08 4
#define DG_12 5
#define DG_16 6
#define DG_32 7
#define DG_48 8

#include "Arduino_LED_Matrix.h"

/* ============================================== */
WiFiClient client;                                 // Initialize the WiFi client library

char server[] = "hygrometer.wissisch.nl";          // server address

unsigned long lastConnectionTime = 0;              // last time you connected to the server, in milliseconds
const unsigned long inquireInterval = 10L * 1000L; // delay between updates, in milliseconds

String findTimeLine = "Init GO...";
bool fillTimeLine = true;
RTCTime currentTime;

/* ============================================== */
ArduinoLEDMatrix matrix;                           // Initialize the LED Matrix

unsigned long lastShownHours = 0;
unsigned long lastShownMinutes = 0;
const unsigned long showTimeInterval = 10L * 1000L;

int secNow;
uint32_t showNow[3];
uint8_t frame[8][12];

/* ===================================================================== */
void setup() {
/* ===================================================================== */ 
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) ;
  delay(1000);
  // if (debugzz) Serial.println("_______A setup");

  RTC.begin();
  matrix.begin();
  showMatrixHours(16);

  while (!ConnectToWifi()) ;
  while (!GetServerTime()) ;

  SetRealerTime(findTimeLine);
  // if (debugzz) Serial.println("_______b setup");
  checkDateTime();

  findTimeLine = "First GO...";
  fillTimeLine = true;

  uint8_t frame[8][12] = {
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  };

  // if (debugzz) Serial.println("_______V setup : " + findTimeLine + "^^ooooooooo");
  // if (debugzz) Serial.println("");
  // if (debugzz) Serial.println("");
}



/* ===================================================================== */
void loop() {
/* ===================================================================== */  

  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  
  // if the number of 'inquireInterval' seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > inquireInterval) {
    // if (debugzz) Serial.println("_______b loop");

    while (!GetServerTime()) ;

    SetRealerTime(findTimeLine);
    // checkDateTime();

    findTimeLine = "next GO...";
    fillTimeLine = true;

    // if (debugzz) Serial.println("_______c loop");
  }

  delay(200);
/*
  if (millis() - lastShownHours > showTimeInterval) {  */
    showMatrixHours(currentTime.getHour());
    // Serial.print("Hours:   " + (String)currentTime.getHour() + "   ");
    delay(4000);  /*
  }

  if (millis() - lastShownHours > showTimeInterval + 4000) {   */ 
    showMatrixMinutes(currentTime.getMinutes());
    // Serial.println("Minutes: " + (String)currentTime.getMinutes());   
    delay(6000);   /*
  }
*/

    // if (debugzz) Serial.println("_______V loop");
}
/* ===================================================================== */  


/* --------------------------------------------------------------------- */
bool ConnectToWifi(){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A ConnectToWifi");

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // check firmware version (just warn):
  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    if (verbose) {
      Serial.print("Attempting to connect to SSID: ");
      Serial.println(ssid);
    }
    status = WiFi.begin(ssid, pass);
    //wait 10 seconds for connection:
    delay(10000);
  }
  
  // you're connected now
  printWifiStatus();
  // if (debugzz) Serial.println("_______V ConnectToWifi");
  return true;
}

/* --------------------------------------------------------------------- */
bool GetServerTime(){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A GetServerTime");

  if (findTimeLine.substring(0,4) == "Init" || findTimeLine.substring(0,5) == "First") delay(2000);


  do {
    httpRequest();
    delay(1200);
  } while (!TalkToServer()) ;

  if (findTimeLine.length() == 31) {
    return true;
  } else {
    return false;
  }

  // if (debugzz) Serial.println("_______V GetServerTime");
}

/* --------------------------------------------------------------------- */
void httpRequest() {
/* --------------------------------------------------------------------- */  
// this method makes a HTTP connection to the server:
  //if (debugzz) Serial.println("_______A httpRequest");

  // close any connection before send a new request.
  // This will free the socket on the NINA module
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    //if (verbose) Serial.println("connecting...");
    // send the HTTP GET request:
    client.println("GET /timeline.php HTTP/1.1");
    client.println("Host: hygrometer.wissisch.nl");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
    // note the time that the connection was made:
    lastConnectionTime = millis();
    //if (debugzz) Serial.println("_______b httpRequest");
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    //if (debugzz) Serial.println("_______c httpRequest");
  }
  if (debugzz) Serial.println("-");
}

/* --------------------------------------------------------------------- */
bool TalkToServer(){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A TalkToServer");

    readRequest();
    //if (verbose) Serial.println("INFO: " + findTimeLine);  // date and time info

    if (findTimeLine.length() != 31) return false;

    // if (debugzz) Serial.println("_______V TalkToServer");
    return true;
}

/* --------------------------------------------------------------------- */
void readRequest() {
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A readRequest");
  uint32_t received_data_num = 0;

  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    buildTimeLine(c);    // distills the Date and Time for correcting the R4's RealTimeClock
    /* print data to serial port */
    if (verbose) Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if(received_data_num % 80 == 0) { 
      
    }
    
  }
  // if (debugzz) Serial.println("_______V readRequest");
}

/* --------------------------------------------------------------------- */
void buildTimeLine(char nu){
/* --------------------------------------------------------------------- */
  if (fillTimeLine) findTimeLine += (String)nu;
  if(findTimeLine.substring(findTimeLine.length() - 7) == "<body>\n") findTimeLine = "";        // strip info before
  if(findTimeLine.substring(findTimeLine.length() - 5) ==  "[END]") { 
    fillTimeLine = false;      // ignore info after
//    // if (debugzz) Serial.println("_______b buildTimeLine");
  }
}

/* --------------------------------------------------------------------- */
void SetRealerTime(String fTL){     // fTL is like  "2027-11-26 19:42:37, 5, 1 [END]"
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A SetRealerTime : " + fTL);

  int jaar, maand, dag, uur, minuut, seconde, w_dag, licht_b;

  jaar    = (int)fTL.substring(0,4).toInt();
  // // if (debugzz) Serial.println("_______b SetRealerTime : " + (String)jaar + "<");
  maand   = (int)fTL.substring(5,7).toInt();
  dag     = (int)fTL.substring(8,10).toInt();
  uur     = (int)fTL.substring(11,13).toInt();
  minuut  = (int)fTL.substring(14,16).toInt();
  seconde = (int)fTL.substring(17,19).toInt();
  w_dag   = (int)fTL.substring(21,22).toInt();
  licht_b = (int)fTL.substring(24,25).toInt(); 

  RTCTime startTime(dag, deliverMonth(maand), jaar, uur, minuut, seconde, deliverDoW(w_dag), deliverLightS(licht_b));
  RTC.setTime(startTime); 

  // if (debugzz) Serial.println("_______V SetRealerTime");
}

/* --------------------------------------------------------------------- */
Month deliverMonth(int mnd){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A deliverMonth");

  switch (mnd) {
    case  1: return Month::JANUARY;   break;
    case  2: return Month::FEBRUARY;  break;
    case  3: return Month::MARCH;     break;
    case  4: return Month::APRIL;     break;
    case  5: return Month::MAY;       break;
    case  6: return Month::JUNE;      break;
    case  7: return Month::JULY;      break;
    case  8: return Month::AUGUST;    break;
    case  9: return Month::SEPTEMBER; break;
    case 10: return Month::OCTOBER;   break;
    case 11: return Month::NOVEMBER;  break;
    case 12: return Month::DECEMBER;  break;
    default: Serial.println("Wrong month code (" + (String)mnd + ")"); return Month::JANUARY; break;
  }
  // if (debugzz) Serial.println("_______V !!! deliverMonth");
}

/* --------------------------------------------------------------------- */
DayOfWeek deliverDoW(int dow){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A deliverDoW");

  switch (dow) {
    case  0: return DayOfWeek::SUNDAY;    break;
    case  1: return DayOfWeek::MONDAY;    break;
    case  2: return DayOfWeek::TUESDAY;   break;
    case  3: return DayOfWeek::WEDNESDAY; break;
    case  4: return DayOfWeek::THURSDAY;  break;
    case  5: return DayOfWeek::FRIDAY;    break;
    case  6: return DayOfWeek::SATURDAY;  break;
    default: Serial.println("Wrong day of week code (" + (String)dow + ")"); return DayOfWeek::SUNDAY; break;
  }
  // if (debugzz) Serial.println("_______V !!! deliverDoW");
}

/* --------------------------------------------------------------------- */
SaveLight deliverLightS(int sli){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A deliverLightS");
  switch (sli) {
    case  0: return SaveLight::SAVING_TIME_INACTIVE;  break;
    case  1: return SaveLight::SAVING_TIME_ACTIVE;    break;
    default: Serial.println("Wrong save light code (" + (String)sli + ")"); return SaveLight::SAVING_TIME_INACTIVE; break;
  }
  // if (debugzz) Serial.println("_______V !!! deliverLightS");
}


/* --------------------------------------------------------------------- */
void printWifiStatus() {
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A printWifiStatus");

  if (verbose){
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(WiFi.SSID());
  
    // print your board's IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
    Serial.println(ip);

    // print the received signal strength:
    long rssi = WiFi.RSSI();
    Serial.print("signal strength (RSSI):");
    Serial.print(rssi);
    Serial.println(" dBm");
  }
  // if (debugzz) Serial.println("_______V printWifiStatus");
}



/* --------------------------------------------------------------------- */
void clearMatrix(){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A clearMatrix");

  uint32_t showNow[3] = {
		0x0,
		0x0,
		0x0
	};
  matrix.loadFrame(showNow);
  // if (debugzz) Serial.println("_______V clearMatrix");
}

/* --------------------------------------------------------------------- */
void showMatrixHours(int numb){  
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A showMatrixHours");

  // Empty matrix with Hours-marker:
  showNow[0] = Base4_4Col[DGH_line][0];
  showNow[1] = Base4_4Col[DGH_line][1];
  showNow[2] = Base4_4Col[DGH_line][2];

  while (numb > 0){
    if (numb >= 16){
      showNow[0] |= Base4_4Col[DG_16][0];
      showNow[1] |= Base4_4Col[DG_16][1];
      showNow[2] |= Base4_4Col[DG_16][2];
      numb -= 16;
    }
    if (numb >= 12){
      showNow[0] |= Base4_4Col[DG_12][0];
      showNow[1] |= Base4_4Col[DG_12][1];
      showNow[2] |= Base4_4Col[DG_12][2];
      numb -= 12;
    }
    if (numb >= 8){
      showNow[0] |= Base4_4Col[DG_08][0];
      showNow[1] |= Base4_4Col[DG_08][1];
      showNow[2] |= Base4_4Col[DG_08][2];
      numb -= 8;
    }
    if (numb >= 4){
      showNow[0] |= Base4_4Col[DG_04][0];
      showNow[1] |= Base4_4Col[DG_04][1];
      showNow[2] |= Base4_4Col[DG_04][2];
      numb -= 4;
    }
    if (numb >= 3){
      showNow[0] |= Base4_4Col[DG_03][0];
      showNow[1] |= Base4_4Col[DG_03][1];
      showNow[2] |= Base4_4Col[DG_03][2];
      numb -= 3;
    }
    if (numb >= 2){
      showNow[0] |= Base4_4Col[DG_02][0];
      showNow[1] |= Base4_4Col[DG_02][1];
      showNow[2] |= Base4_4Col[DG_02][2];
      numb -= 2;
    }
    if (numb >= 1){
      showNow[0] |= Base4_4Col[DG_01][0];
      showNow[1] |= Base4_4Col[DG_01][1];
      showNow[2] |= Base4_4Col[DG_01][2];
      numb -= 1;
    }
  }
      
  matrix.loadFrame(showNow);
  // if (debugzz) Serial.println("_______V showMatrixHours");
} 
    
/* --------------------------------------------------------------------- */
void showMatrixMinutes(int numb){
/* --------------------------------------------------------------------- */
  // if (debugzz) Serial.println("_______A showMatrixMinutes");

  // Empty matrix with Minutes-marker:
  showNow[0] = Base4_4Col[DGM_line][0];
  showNow[1] = Base4_4Col[DGM_line][1];
  showNow[2] = Base4_4Col[DGM_line][2];

  while (numb > 0){
    if (numb >= 48){
      showNow[0] |= Base4_4Col[DG_48][0];
      showNow[1] |= Base4_4Col[DG_48][1];
      showNow[2] |= Base4_4Col[DG_48][2];
      numb -= 48;
    }
    if (numb >= 32){
      showNow[0] |= Base4_4Col[DG_32][0];
      showNow[1] |= Base4_4Col[DG_32][1];
      showNow[2] |= Base4_4Col[DG_32][2];
      numb -= 32;
    }
    if (numb >= 16){
      showNow[0] |= Base4_4Col[DG_16][0];
      showNow[1] |= Base4_4Col[DG_16][1];
      showNow[2] |= Base4_4Col[DG_16][2];
      numb -= 16;
    }
    if (numb >= 12){
      showNow[0] |= Base4_4Col[DG_12][0];
      showNow[1] |= Base4_4Col[DG_12][1];
      showNow[2] |= Base4_4Col[DG_12][2];
      numb -= 12;
    }
    if (numb >= 8){
      showNow[0] |= Base4_4Col[DG_08][0];
      showNow[1] |= Base4_4Col[DG_08][1];
      showNow[2] |= Base4_4Col[DG_08][2];
      numb -= 8;
    }
    if (numb >= 4){
      showNow[0] |= Base4_4Col[DG_04][0];
      showNow[1] |= Base4_4Col[DG_04][1];
      showNow[2] |= Base4_4Col[DG_04][2];
      numb -= 4;
    }
    if (numb >= 3){
      showNow[0] |= Base4_4Col[DG_03][0];
      showNow[1] |= Base4_4Col[DG_03][1];
      showNow[2] |= Base4_4Col[DG_03][2];
      numb -= 3;
    }
    if (numb >= 2){
      showNow[0] |= Base4_4Col[DG_02][0];
      showNow[1] |= Base4_4Col[DG_02][1];
      showNow[2] |= Base4_4Col[DG_02][2];
      numb -= 2;
    }
    if (numb >= 1){
      showNow[0] |= Base4_4Col[DG_01][0];
      showNow[1] |= Base4_4Col[DG_01][1];
      showNow[2] |= Base4_4Col[DG_01][2];
      numb -= 1;
    }
  }
  matrix.loadFrame(showNow);
    // note the time that the connection was made:
    // lastConnectionTime = millis();
  
  // if (debugzz) Serial.println("_______V showMatrixMinutes");
}

/* --------------------------------------------------------------------- */
void checkDateTime(){
/* --------------------------------------------------------------------- */
//  // if (debugzz) Serial.println("_______A checkDateTime");
//  Serial.println("_______A checkDateTime");

  RTC.getTime(currentTime);  // Get current time from RTC
  Serial.print("date time = ");
  Serial.print(currentTime.getDayOfMonth());
  Serial.print(".");
  int m = (int)currentTime.getMonth() + 1;
  Serial.print(m);
  Serial.print(".");
  Serial.print((String)currentTime.getYear() + "  ");

  Serial.print(currentTime.getHour());
  Serial.print(":");
  Serial.print(currentTime.getMinutes());
  Serial.print(":");
  Serial.println(currentTime.getSeconds());
  // if (debugzz) Serial.println("_______V checkDateTime");
//  Serial.println("_______A checkDateTime");
}

/*
Sketch uses 68332 bytes (26%) of program storage space. Maximum is 262144 bytes.
Global variables use 7468 bytes (22%) of dynamic memory, leaving 25300 bytes for local variables. Maximum is 32768 bytes.
*/

The correct date and time is delivered by my own webpage:
http://hygrometer.wissisch.nl/timeline.php?zone=Australia/Sydney
(Omitting the zone delivers the time for Amsterdam)

Use this 'service' freely (but keep an interval of at least 2 minutes, svp.)

Any comment is still appreciated!

you have long delays in the code that might (or not) come in the way of handling other stuff if needs be.

правильно.
Correct. The 10 seconds is in the setup(), copied from an example to give WiFi enough time (I experimented some time ago, will experiment again how short it can be, now that the rest is functioning).
In the loop(): The 4sec resp 6sec are for the clock display (hrs, mins). Now the program is so simple that it doesn't hurt. But I already devised a way to get rid of the delay() calls AND have the actions timed on specific RTC seconds.
Thanks.

ok - good

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