Using the cloudtime class in the arduino cloud I can't retrieve the time and date data in the arduino code, I did the following test:
CloudTime time;
Serial.println(time.hour);
it's giving an error saying that the hour field is not an attribute of the class. Does anyone know how I can retrieve the hour and minute from this arduino cloud class?
can you be more specific ? which cloudtime class ?
I think the CloudTime type is just an unsigned int. It's not a "class" with methods.
It's probably some sort of epoch based number and you would use the usual C++ functions to extract the information in a time_t structure.
time_t epochTime = /* your epoch value */;
struct tm *timeinfo = localtime(&epochTime);
// Now timeinfo contains the broken-down time (hours, minutes, etc.)
// You can access the components like this:
int year = timeinfo->tm_year + 1900; // Year since 1900
int month = timeinfo->tm_mon + 1; // Months are zero-based
int day = timeinfo->tm_mday;
int hour = timeinfo->tm_hour;
int minute = timeinfo->tm_min;
int second = timeinfo->tm_sec;
check if something like this would make sense with epochTime not being a time_t but your CloudTime variable.
Hi Jackson, thanks for answering. I'm making a dashboard on the Arduino Cloud where I need to get the start and end time to turn on a light. However, the Timepicker widget doesn't deliver the time to the Arduino so I can do the validations. I don't know if I'm doing it right, but what I need is to turn a light on and off at the specified times.