I would like to create a timestamp for my captured images.
I wrote these helper functions to do so.
def year(datetime): return str(datetime) def month(datetime): return str('%02d' % datetime) def day(datetime): return str('%02d' % datetime) def hour(datetime): return str('%02d' % datetime) def minute(datetime): return str('%02d' % datetime) def second(datetime): return str('%02d' % datetime) def timestamp(datetime): # join date with "-" so that yyyy-mm-dd date_string = '-'.join([year(datetime), month(datetime), day(datetime)]) # join times with ":" so that HH:MM:SS time_string = ':'.join([hour(datetime), minute(datetime), second(datetime)]) # join strings so that date goes ISO format with "T" in the middle return "T".join([date_string, time_string]) def create_filename(datetime, ext=".jpg"): return timestamp(datetime) + "_capture" + ext
On my while loop, I would like to do something like
# import ... rtc = pyb.RTC() while(True): clock.tick() img = sensor.snapshot() # print(rtc.datetime()) # print(create_filename(rtc.datetime())) img.save(create_filename(rtc.datetime())
I have 2 questions:
When I try to do this, I get
OSError: The path name format is invalid. I think I was able to track this error down to the files containing “:” on their names. Is this the actual reason? I know I could use another pattern (ie., “-” or “_”), but why is this an issue? I was trying to recreate the behavior I get from datetime on python, where I would regularly do
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "_capture.jpg"
I notice the datetime is wrong, what is the way to set it up?
I’m going through the docs but I don’t fully understand my options
The current calendar time may be set using machine.RTC().datetime(tuple) function, and maintained by following means:
By a backup battery (which may be an additional, optional component for a particular board).
Using networked time protocol (requires setup by a port/user).
Set manually by a user on each power-up (many boards then maintain RTC time across hard resets, though some may require setting it again in such case).
If actual calendar time is not maintained with a system/MicroPython RTC, functions below which require reference to current absolute time may behave not as expected.
Could you point me to maintain the clock time, either through an external battery or through network protocol. For network protocol, do I need to add a network shield ?
I would have my openMV cams running
main.py and saving correctly timestamped images to the SD card, while getting power from a raspberry Pi through the USB cable. If possible, I would like to avoid setting up raspberry/openmv control, the raspberry is running other stuff and It’s just conveniently close enough to supply power to the openmv board. Otherwise, how is it possible to set up so that time is kept even though the machine is not running?
On the forums I found this question
Regarding using I2C sparkfun clocks but also saying that new version (M7 ?) will have a clock incorporated?