Hi everyone, I am using raspberry pi pico with Arduino ide. I want to make http request to server then I want to take date and time from servers response. With this date and time, I want to update RTC. I am using this libraryexample . Here is my code ;
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <Timezone_Generic.h> // https://github.com/khoih-prog/Timezone_Generic
// Example set at 05:00:00 Fri 21 Jan 2022 UTC or 00:00:00 Fri 21 Jan 2022 EST
datetime_t currTime = { 2022, 06, 07,05, 17, 30, 36 };
//////////////////////////////////////////
char buf[32];
void setup()
{
Serial.begin(115200);
delay(200);
// Start the RTC
rtc_init();
rtc_set_datetime(DateTime);
}
void displayTime(){
// Display time from RTC
rtc_get_datetime(&currTime);
DateTime now = DateTime(currTime);
time_t utc = now.get_time_t();
sprintf(buf,"%.2d-%.2d-%.2d %.2d:%.2d:%.2d",year(utc),month(utc),day(utc),hour(utc),minute(utc),second(utc));
Serial.println(buf);
}
void loop()
{
displayTime();
}
EthernetClient client;
EthernetHttpClient httpClient(client, serverAddress, port);
String path = "/tryingtoget/time";
httpClient.get(path);
String response = httpClient.responseBody();
StaticJsonDocument<200> doc;
deserializeJson(doc, response);
String date = (const char*)doc["date"];
After this htt request code, I am parsing date to int16_t. And then I am trying to use those values inside datetime_t currTime like this ;
currTime = { i_year, i_month, i_date, i_hour, i_minute, i_second };
But I can't define currTime inside function or something. I always need to identify this currTime top of the code. So is there a way to update my RTC ?