The board was rebooting several times a day in its operational mode.
I have a "development board" where I can plug in an ESP32 module, and test the code with pushbuttons to simulate expected and unexpected input, and LEDs for output. It never reboots in that board.
I was able to put a notebook computer nearby the operational unit, connected to the USB-serial port on the ESP32. I used PUTTY to log the console output. After a day, zero reboots. So having a USB cable connected somehow causes it to work better? I'll have to think about that - maybe the issue is power-related since the USB cable also supplies +5V power?
Next I'm starting to learn about micropython file systems and logging. I saw this post about logging, and this reference on the file system.
Any better examples to work from?
How can I tell what caused an ESP32 board to restart?
Re: How can I tell what caused an ESP32 board to restart?
The code example shows how to implement a ramdisk on the ESP-32.
I can add this code and write to a file and read it back successfully.
A ramdisk does not maintain contents through a boot. For my goal of logging exceptions that cause a reboot for diagnosis, I need a flash filesystem.
This article says:
Code: Select all
import os
bdev = RAMBlockDev(512, 50)
os.VfsFat.mkfs(bdev)
os.mount(bdev, '/ramdisk')
Code: Select all
with open('/ramdisk/hello.txt', 'w') as f:
f.write('This file wrote at startup')
print(open('/ramdisk/hello.txt').read())
This article says:
I have not found any details on how the "automatically" mounted file system is accessed or used, or even how to determine if it exists. How would MicroPython code on an ESP32 access that filesystem to write a small file that can persist between reboots? I'm still learning, so a simple example would be helpful.On power-on, MicroPython will attempt to detect the filesystem on the default flash and configure and mount it automatically. If no filesystem is found, MicroPython will attempt to create a FAT filesystem spanning the entire flash.
Re: How can I tell what caused an ESP32 board to restart?
timg11,
I have been fighting the same problem for the last year.
I have been fighting the same problem for the last year.
A littlefs filesystem is automatically mounted when you load in the images on the download page. What I ended up doing, so I wouldn't lose import datalogging information is every hour append the contents of /ramdisk/datalog.csv to datalog.csv (in flash). As ramdisk is limited I do the following:I have not found any details on how the "automatically" mounted file system is accessed or used, or even how to determine if it exists. How would MicroPython code on an ESP32 access that filesystem to write a small file that can persist between reboots? I'm still learning, so a simple example would be helpful.
Code: Select all
# save data
try:
with open('/ramdisk/datalog.csv', 'a') as outfile:
outfile.write(time + ',')
outfile.write(str(Battery_voltage) + ',')
outfile.write('\n')
except OSError as err:
try:
with open('errors.txt', 'a') as outfile:
my_error = err.args[0]
outfile.write('saving data failed ' + str(my_error) + '\n')
except OSError:
pass
if (minutes == '00'): # every hour append /ramdisk/datalog.csv to datalog.csv
src_file = open('/ramdisk/datalog.csv', 'r')
dest_file = open('datalog.csv', 'a')
copyfileobj(src_file, dest_file, length = 512)
src_file.close()
dest_file.close()
# remove /ramdisk/datalog.cvs
try:
uos.remove('/ramdisk/datalog.csv')
except OSError as err:
try:
with open('errors.txt', 'a') as outfile:
my_error = err.args[0]
outfile.write('removing /ramdisk/datalog.csv failed ' + str(my_error) + '\n')
except OSError:
pass
Re: How can I tell what caused an ESP32 board to restart?
Note this extracted from davef's answer. Just wanted to highlight it specifically:I have not found any details on how the "automatically" mounted file system is accessed or used, or even how to determine if it exists. How would MicroPython code on an ESP32 access that filesystem to write a small file that can persist between reboots? I'm still learning, so a simple example would be helpful.
Code: Select all
>>> with open('errors.txt', 'a') as outfile:
.... my_error = err.args[0]
.... outfile.write('saving data failed ' + str(my_error) + '\n')
check out the os module for filesystem tools like os.mkdir, os.listdir, os.rename, etc
you basically have access to a filesystem starting with a root "/" directory.
How are you loading your firmware?
If using the webrepl, you can do
Code: Select all
$ webrepl_cli.py -p password filename.py 192.168.0.10:/path/to/filename.py
You can deploy as packages and stuff too with __init__.py and everything. relative imports work! Everything works!