time.mktime() returns incorrect Unix timestamp on ESP32
Port, board and/or hardware
sysname='esp32', nodename='esp32', release='1.24.1', version='v1.24.1 on 2024-11-29', machine='Generic ESP32 module with ESP32. Unique ID b'\x94\xe6\x86\x13o$' (not sure what this is
MicroPython version
release='1.24.1', version='v1.24.1 on 2024-11-29',
When using this board and setting time using the ntp library thus ntptime.settime() this synchronizes the RTC to UTC using an NTP server, and it seems to be working correctly since time.localtime() returns (2024, 12, 28, 18, 11, 1, 5, 363) (UTC time). As I understand it, this should reset the real time clock to the current time. If I then set time.mktime(time.localtime()) which should provide the Unix time, it does not, instead is spits out 788726670 which is 1994-12-29 18:44:30 UTC. Can someone please explain this ? Is it a a bug? Bottom line, how can the realtime clock be set to a specific time?
Reproduction
from machine import RTC
import time
Manually set the RTC to a known time (e.g., 2024-01-28 15:30:00 UTC)
rtc = RTC()
rtc.datetime((2024, 1, 28, 0, 15, 30, 0, 0)) # (year, month, day, weekday, hour, minute, second, subseconds)
Get the Unix timestamp
unix_time = time.mktime(time.localtime())
print("Unix time:", unix_time)
Result: Unix time: 759771000 it should be closer to 1735413856.203176
Expected behaviour
Expected the unix time to be determined correctly. That is it should look something like this 1735413022.697727
Observed behaviour
The output is incorrect - see Expected behaviour result above
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
Bug in machine.RCT
Port, board and/or hardware
Espressif, esp32-devkitC-v4
MicroPython version
MicroPython v1.25.0 on 2025-04-15; Generic ESP32 module with SPIRAM with ESP32
import machine
rtc = machine.RTC()
rtc.init([2025, 6, 8, 0,15, 20, 25, 0])
print(rtc.datetime())
(2025, 6, 8, 6, 0, 15, 29, 909453)
I write DayOfWeek=0 and Hour=15 and i read Hour=0 and Minute=15 .
All was good with version 1.24.1
Reproduction
import machine
rtc = machine.RTC()
rtc.init([2025, 6, 8, 0,15, 20, 25, 0])
print(rtc.datetime())
(2025, 6, 8, 6, 0, 15, 29, 909453)
Expected behaviour
Observed behaviour
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree