Code: Select all
## Simple software WDT implementation
import machine
import utime
from shutil import copyfileobj
wdt_counter = 0
def wdt_callback():
global wdt_counter
wdt_counter += 1
if (wdt_counter >= 70): # 70 seconds
epoch = utime.time()
local_time = utime.localtime(epoch)
seconds = local_time[5]
minutes = local_time[4]
hours = local_time[3]
day = local_time[2]
time = str(hours) + ':' + str(minutes) + ':' + str(seconds)
try:
with open('errors.txt', 'a') as outfile:
outfile.write(str(day) + ' ' + time + '\n')
outfile.write('had a wdt event' + '\n')
except OSError:
pass
# save sbms_datalog.csv
src_file = open('/ramdisk/sbms_datalog.csv', 'rb')
dest_file = open('sbms_datalog.csv', 'wb')
copyfileobj(src_file, dest_file, length=512)
print('Contents of src copied to dest')
src_file.close()
dest_file.close()
machine.reset()
def wdt_feed():
global wdt_counter
wdt_counter = 0
wdt_timer = machine.Timer(3) # hardware timer for ESP32
wdt_timer.init(period=1000, mode=machine.Timer.PERIODIC, callback=lambda t:wdt_callback())
## END Simple software WDT implementation
Is this expected behaviour? Any thoughts on how to save the data other than periodic saves to flash?
Thanks.