Closed maxgerhardt closed 3 years ago
Thank for the bug report.
The fix will be as follows and will be introduced in the next release
bool rtc_set_datetime(DateTime dt)
{
datetime_t tm;
tm.year = dt.year();
tm.month = dt.month();
tm.day = dt.day();
tm.hour = dt.hour();
tm.min = dt.minute();
tm.sec = dt.second();
tm.dotw = dt.dayOfTheWeek();
#if RTC_DEBUG
Serial.print("Year = "); Serial.print(tm.year);
Serial.print(", Mo = "); Serial.print(tm.month);
Serial.print(", day = "); Serial.print(tm.day);
Serial.print(", hour = "); Serial.print(tm.hour);
Serial.print(", min = "); Serial.print(tm.min);
Serial.print(", sec = "); Serial.println(tm.sec);
#endif
return (rtc_set_datetime(&tm));
}
The Terminal output with the new bug fix
Start RP2040_RTC_Time_WiFiNINA on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
RP2040_RTC v1.0.6
Timezone_Generic v1.7.1
Connecting to WPA SSID: HueNet1
You're connected to the network, IP = 192.168.2.87
Packet received
Seconds since Jan 1 1900 = 3844779246
Unix time = 1635790446
The UTC time is 18:14:06
============================
18:14:07 Mon 01 Nov 2021 UTC
14:14:07 Mon 01 Nov 2021 EDT
============================
18:15:07 Mon 01 Nov 2021 UTC
14:15:07 Mon 01 Nov 2021 EDT
============================
18:16:07 Mon 01 Nov 2021 UTC
14:16:07 Mon 01 Nov 2021 EDT
============================
18:17:07 Mon 01 Nov 2021 UTC
14:17:07 Mon 01 Nov 2021 EDT
Could you please check and verify if there any more issue with PIO.
Thanks and regards
Hi @maxgerhardt
The new RP2040_RTC releases v1.0.7 has just been published.
Your contribution has been noted in Contributions and Thanks
Describe the bug
This library does
https://github.com/khoih-prog/RP2040_RTC/blob/f7650a1890b2e67d4bd76f927a5cd784fe1ff440/src/DateTime_Generic.h#L456-L477
to convert a
DateTime
intodatetime_t
as needed by the Pico SDK'srtc_set_datetime
function. However, the library fails to initialize thetm.dotw
(day-of-the-week) member, and as such the field will have a random value from the stack.Calling into
rtc_set_datetime
with such a datastructure leads to the validation function failingSince
if (!(t->dotw >= 0 && t->dotw <= 6)) return false;
triggers. (Since variable is allocated on the stack it has an initial random value, 0-255, only by chance if the value is 0-6 it passes this check)Hence, the example Time with NiNa (https://github.com/khoih-prog/RP2040_RTC/tree/main/examples/Time/RP2040_RTC_Time_WiFiNINA) module that uses this codepath fails randomly.
And thus the example does not run correctly.
Steps to Reproduce
Use the https://github.com/khoih-prog/RP2040_RTC/tree/main/examples/Time/RP2040_RTC_Time_WiFiNINA example with the
platformio.ini
Expected behavior
The library converts to
datetime_t
correctly without leaving any datamember uninitialized.Actual behavior
Library does not initialize the
.dotw
member causing a probabilistic failure ofrtc_set_datetime()
.Debug and AT-command log (if applicable)
None appliciable.
Screenshots
None appliciable.
Information
Please ensure to specify the following:
RP2040
Core Version: Arduino-mbed RP2040 v2.5.2RP2040
Board type: NANO_RP2040_CONNECTAdditional context
Discussed in the PlatformIO forum thread.