RCT resets after connecting to MQTT on AnyCLoud_MQTT_Client

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
mvpablo
Level 2
Level 2
10 sign-ins 5 replies posted 5 questions asked

Hi. 

I'm using Modustoolbox to run the example AnyCloud_MQTT_Client with AWS on the board CY8CPROTO-062-4343W.

I modified the example just to update the RTC to be able to add a timestamp to the MQTT json messages that are sent to the cloud. 

If I update the RTC before the MQTT connection is done,  then, once the app connects to the MQTT broker the RTC goes to EPOCH 1970-01-01 00:00:00. Dunno if this means that the RTC is reseted. 

If I wait until the app connects to MQTT  and then I  update the RTC then it works fine and the RTC keeps providing updated time.  

Any idea why this is happening? or what am I missing here?

I'm using the code snippes in [1] to update the RTC 

thanks
 
 
/*Sample code-Update the current time and date to the RTC peripheral */
result = cyhal_rtc_write(&my_rtc, &new_date_time);
 

[1] https://infineon.github.io/psoc6hal/html/group__group__hal__rtc.html

 

0 Likes
1 Solution

Hello @mvpablo ,

Some developments on this. Since the RTC is being used internally, you need to set the instance right after initialization i.e. cy_set_rtc_instance must be called right aftercyhal_rtc_init and this should fix the issue. 

This has been documented as part of the Time Support Details section in the clib-support library, you can find its readme here

Regards,
Dheeraj

View solution in original post

0 Likes
2 Replies
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello @mvpablo ,

I'm able to reproduce this error. I checked why this might be happening. Basically, when mqtt_connect is called, it tries to establish a secure TLS connection with the broker. For this, the RTC is being used internally and this is why your values gets reset. You can dig through to find the sequence, but basically, there is this API get_current_time() in the secure_sockets library (see cy_tls.c) which calls the time() function which is part of clib-support library (see cy_time.c) which uses RTC APIs which is causing this issue. 

I have forwarded this issue to the software team for evaluation. Please update the RTC after the MQTT connection is done for now. I will let you know once the fix is available.

Regards,
Dheeraj

0 Likes

Hello @mvpablo ,

Some developments on this. Since the RTC is being used internally, you need to set the instance right after initialization i.e. cy_set_rtc_instance must be called right aftercyhal_rtc_init and this should fix the issue. 

This has been documented as part of the Time Support Details section in the clib-support library, you can find its readme here

Regards,
Dheeraj

0 Likes