machine.reset is not working properly ?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
zmaier
Posts: 14
Joined: Thu May 16, 2019 12:44 pm

machine.reset is not working properly ?

Post by zmaier » Mon May 11, 2020 5:34 am

Hello,

i am using a Wemos D1 Mini and i have troubles using machine.reset()

Here is the code of main.py :

Code: Select all

import sys
import machine
from uio import StringIO
try:
    import run.mpy
except KeyboardInterrupt:
    sys.exit()
except Exception as e:
    s=StringIO(); sys.print_exception(e, s)  
    x=s.getvalue()
    payload="system exception=\"{1}\"".format(e)
    temp=open("error.txt","w")
    temp.write(payload)
    temp.write(x)
    temp.close()
    machine.reset()
My intention is, if a error occurs in run.mpy the error should be logged in the file error.txt and the Wemos should restart.
The Problem now, the error is logged correct, but the esp is not restarting.
I got the micropyhton-shell, it seems, that the boot.py and main.py is not excecuted?

Doing Strg+D everthing is ok, donig a hardreset with the reset button, also everthing is working as expected.

Yes, i could catch the error within the run.mpy but, for debubing reasons i would like to do it that why :)
Any ideas why?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: machine.reset is not working properly ?

Post by kevinkk525 » Mon May 11, 2020 5:42 am

Well I never tried it that way.
I always catch errors in main.py and my machine.reset() has always worked reliable there. even in my watchdog implementation.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
tve
Posts: 216
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: machine.reset is not working properly ?

Post by tve » Mon May 11, 2020 7:13 am

This doesn't help you with your reset problem, but I believe you could avoid the StringIO by doing sys.print_exception(e, temp).
Also, `with open("error.txt", "w") as temp:` is a nicer way to write the file I/O...

WRT reset, is the esp8266 going through a full system reset?

Post Reply