UNIX Time
-
@jmarcelino, actually in the line:
printf("%lld %f\n", mach_rtc_get_us_since_epoch(), mach_rtc_get_us_since_epoch() / 1000000.0);I wanted to print the us value after epoch, which is internally kept as a 64 bit integer (to go beyond the 2K38 problem), hence the
%lld. Then at the same line I wanted to test that it was not an issue with converting it to a float seconds value (which proved not to be the case). -
I meant that %f in the printf is usually a double not a float
-
@dchappel, @jmarcelino, and everyone else that reads this. I hope you guys all accept my humble apology. @jmarcelino made me realize of a mistake I made while coming into this conclusions (and in the original software too).
I had forgotten that single floating point values are 32 bit (so only 23 bits represent the fraction). The results are then correct. I'll check into the reported bug and look for a way to fix it ASAP. Probably it won't be included in today's release, as I want to test it properly this time.
-
After thinking it through and discussing it with my fellow workers, the only posible solution is to go back to integers. The reason is that at present time
mp_float_tis now a C float, that only has 23 bit to represent the mantissa. This could be changed, but needs proper testing. Perhaps in the future this will change, but until then,time.time()will return an integer. -
This post is deleted! -
@abilio, how can I sync/set RTC to UNIX time?
-
Do you mean over NTP?
You can now use rtc.ntp_sync("pool.ntp.org")
Check the RTC docs: https://docs.pycom.io/chapter/firmwareapi/pycom/machine/RTC.html
-
@jmarcelino, I want to sync RTC to current time(UTC) and after that, I can use time.time() function to calculate time elapsed since Epoch and then use it as a timestamp.
-
@devang-sharma
I do not know if i understand you corectly
but you can set timezoneutime.timezone([secs])and then use
utime.localtime() -
@jmarcelino It works for me now! I had to enable NTP client using the command line in Windows. Before that, "rtc.synced()" was returning False. Thanks.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login