Simple way to check dependencies

Hi,
I am pretty new to coding and I am working on a project based on the Lilygo T-Watch 2021 board (ESP 32 Dev Module).
I am trying to study one of the example codes provided on the official Lilygo GitHub page (RTC) but I am having a hard time understanding some parts of it. This is the code, which compliles without errors but doesn't sync the time with the ntp server.

#include <Arduino.h>
#include <TWatch_hal.h>
#include <WiFi.h>
//"TWatch_config.h" needs to be configured in the library for the first time
// This routine needs to annotate the LVGL GUI

TWatchClass *twatch = nullptr;
TFT_eSPI *tft = nullptr;
PCF8563_Class *rtc = nullptr;
/*****************Time synchronization parameters********************/
/* A Constant variable in C++ is a variable whose value does not change during the execution of the program - const  */

const char *ntpServer1 = "pool.ntp.org";  // const char * makes your string immutable and the pointer location still can flexibly change
const char *ntpServer2 = "ntp1.aliyun.com";
const long gmtOffset_sec = 60 * 60 * 8;  // dovvrebbero essere 8 ore in secondi
const int daylightOffset_sec = 0;

const char *ssid = "Telecom-14113461"; // "your 2.4G wifi ssid";
const char *pass = "fzZeVMDCG13wTDewRcr1G3r5";  // "your password";

void SyncTime(void *param) {
  struct tm timeinfo; // Structure is a user-defined data type created to store different types of values under a single variable.
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  // Synchronize RTC time
  while (!getLocalTime(&timeinfo)) {
    // init and get the time
    configTime(gmtOffset_sec, daylightOffset_sec, ntpServer2, ntpServer1);
    Serial.println("Failed to obtain time , try again");
  }
  twatch->rtc_set_time(timeinfo.tm_year + 1900, timeinfo.tm_mon, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
  // disconnect WiFi as it's no longer needed
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}

void setup() {
  twatch = TWatchClass::getWatch(); /* Scope Resolution Operator written as two colons :: and is used to access the instance variables and instance methods using their class name in different situations. */ 

  tft = twatch->tft_get_instance();
  rtc = twatch->rtc_get_instance();

  Serial.begin(9600);

  Serial.println("RTC Demo");

  twatch->hal_auto_update(true, 0);

  tft->fillScreen(TFT_BLACK);
  twatch->backlight_set_value(255);
  tft->setTextFont(2);
  tft->setTextColor(TFT_WHITE, TFT_BLACK);
  tft->drawString("T-Watch RTC Test", 62, 90);
  tft->drawString("Press BTN1 to synchronize time", 20, 108);
  twatch->button_bind_event(TWATCH_BTN_1, BUTTON_CLICK, SyncTime); // -> arrow operator pointer name -> veriable name

  twatch->rtc_set_time(2022, 2, 19, 10, 56, 30);
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(rtc->formatDateTime(PCF_TIMEFORMAT_YYYY_MM_DD_H_M_S));
  tft->drawString(rtc->formatDateTime(PCF_TIMEFORMAT_YYYY_MM_DD), 90, 126);
  tft->drawString(rtc->formatDateTime(PCF_TIMEFORMAT_HMS), 95, 144);
  delay(1000);
}

I can't understand the following:

  1. when I push button 1 the serial console prints a series of dots, indicating that it's trying to connect to my wifi (ssid and pw are correct) but without succeding. So I expect the code to print the message "Failed to obtain time , try again", but that message never gets printed.
  2. looking for the bug I am trying to understand where all the pieces of code come from to see if some dependencies are missing. For example the code includes <Arduino.h> and <Wifi.h> but I cannot find these files anywhere in my libraries folder.
  3. I am trying to understand what words in the code are c++ default commands/keywords, what are defined in other code files (only the #included ones I guess or others too?), and what were defined in this specific piece of code.

Any simple method to do this king of troubleshooting, or advise in general?
Thanks in advance!
Angelo

Welcome to the forum

Which version of the Arduino IDE are you using ?

With version 2.x you can right click on a function or variable definition and see where it was defined

1 Like

Since @angelo904 mentioned not being able to find header files, I'll add to this that you can also right click on the filename in an #include directive and then select "Go to definition" from the context menu to open that file in an Arduino IDE editor tab.

1 Like

@UKHeliBob thanks for your answer I am away from my pc at the moment but I am pretty sure it is the latest version. I installed no more than 2 weeks ago and always updated it when prompted.
But I’ll write the exact version later

@UKHeliBob and @ptillisch thanks a lot! This was a little breakthrough for me! Using the "go to definition" action I could discover the location of all the included files and also the source of several functions, which are files inside my "users/Appdata... " path. Now I am only wondering why some of these files are explicitely called in my code with #include directives and some others are not, but are still used...

The built in Arduino specific functions are in libraries that are included automatically when you compile a sketch

This is done to make it easier for newcomers to get their sketches up and running without the need to go into the complications of #including libraries

1 Like

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