I thought this would be simple but I am having major troubles. All I want to do is update the RTC with the WiFi and then print the time and date to an LCD screen using u8g2.
I don’t know if I am taking the correct approach. I just wanted to keep it simple. Disregarding the WiFi stuff as I have got that sorted out, the main problem is printing the time and date to the screen. I’m not interested in printing it to serial, which I have done.
Whenever I try and call a function from the RTC library it just says it wasn’t declared in this scope. When I try and use dtostrf to convert a value to a string, it says something about it being a double. I don’t understand and I was only copying someone else using dtostrf in the first place.
#include <U8g2lib.h>
#include "WiFiS3.h"
#include "arduino_secrets.h"
#include "RTC.h"
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;
#define GMTOffset_hour 10 // # hours difference to GMT
#define DayLightSaving 1
int status = WL_IDLE_STATUS;
char temp_string[6];
U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=E*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
String GetRTC()
{
RTCTime currentTime;
RTC.getTime(currentTime);
return String(currentTime);
}
void setup()
{
u8g2.begin();
RTC.begin();
Serial.begin(115200);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed.");
// don't continue
while (true);
}
printWifiStatus();
}
void loop()
{
unsigned long EpochTime;
EpochTime = WiFi.getTime();
u8g2.firstPage();
do
{
u8g2.setFont(u8g2_font_lastapprenticebold_te);
u8g2.drawRFrame(0, 0, 128, 20, 7);
u8g2.drawStr(6, 15, "Time");
WHAT DO I PUT HERE TO PRINT TO THE TIME AND DATE TO THE LCD??
}
while( u8g2.nextPage() );
delay(1000);
}
void UpdateRTC(time_t EpochTime)
{
auto timeZoneOffsetHours = GMTOffset_hour + DayLightSaving;
auto unixTime = EpochTime + (timeZoneOffsetHours * 3600);
Serial.print("Unix time = ");
Serial.println(unixTime);
RTCTime timeToSet = RTCTime(unixTime);
RTC.setTime(timeToSet);
// Retrieve the date and time from the RTC and print them
RTCTime currentTime;
RTC.getTime(currentTime);
Serial.println("The RTC was just set to: " + String(currentTime));
// Print out date (DD/MM//YYYY)
Serial.print(currentTime.getDayOfMonth());
Serial.print("/");
Serial.print(Month2int(currentTime.getMonth()));
Serial.print("/");
Serial.print(currentTime.getYear());
Serial.print(" - ");
// Print time (HH/MM/SS)
Serial.print(currentTime.getHour());
Serial.print(":");
Serial.print(currentTime.getMinutes());
Serial.print(":");
if (currentTime.getSeconds() < 10)
{
Serial.print('0');
}
Serial.println(currentTime.getSeconds());
}
void printWifiStatus()
{
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Can someone please help call the time and date to the LCD screen? I am completely out of ideas and it was out of my league to begin with.