#include <RTClib.h>
#include <string.h>
RTC_DS1307 rtc;
String GetDateTime();
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
if (!rtc.begin()) { //Se o RTC nao for inicializado, faz
Serial.println("RTC NAO INICIALIZADO"); //Imprime o texto
while (1); //Trava o programa
}
Serial.println("Obtendo data");
String data = GetDateTime();
Serial.println(data);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
String GetDateTime(){
DateTime now = rtc.now();
int tahun = now.year();
int bulan = now.month();
int tanggal = now.day();
int jam = now.hour();
int menit = now.minute();
int detik = now.second();
char datestring[50];
snprintf_P(datestring,
50,
PSTR("%02u-%02u-%02uT%02u:%02u:%02u.000Z"),
now.year(),
now.month(),
now.day(),
now.hour(),
now.minute(),
now.second() );
String date = String(datestring);
return date;
}