BetaRavener / uPyLoader

File transfer and communication tool for MicroPython boards
MIT License
355 stars 76 forks source link

Reset button #49

Open vpatron opened 6 years ago

vpatron commented 6 years ago

Hi, can you add a reset button that sends Ctrl-C, "import machine; machine.reset()", and then uPyLoader disconnects (without causing error)?

It's just a convenience thing. I'd imagine a lot of people have their ESP code automatically run on boot and would like to reboot conveniently.

BetaRavener commented 6 years ago

Hi, I think this shouldn't be a problem to do so I'll look into it on the next occasion.

vpatron commented 6 years ago

I use a very simple workaround for now. I created a file called "machine_reset.py" with the contents below. I click on the file and click on the Execute button to reset.

import machine
machine.reset()
BetaRavener commented 6 years ago

Looking at implementing this now. Would just like to ask what's the reason for "and then uPyLoader disconnects"? I'd expect if you are resetting device, you want to continue working with it after it reboots.

vpatron commented 6 years ago

Boy, it's been a while. I think if it is serial, then yes you want it to stay connected. However, if it is WiFi connection, the machine.reset() makes the connection unresponsive anyway so you might as well close it.

Also, a warning: there is a problem with FAT file system getting corrupted when calling machine.reset(). I count to 5 or 10 after uploading a program before calling machine.reset(). So maybe this is a dangerous feature to add unless you know of a way to have MicroPython flush all files to FAT before resetting?

The reason I end up resetting a lot is because my programs are kind of big and when I upload an edit and rerun it, it says out of memory. Maybe it would be better to loop through the dir() list and delete almost everything and then call gc.collect()? I try to del a bunch of variables and then call gc.collect() and get 17k RAM free, and I still get out of memory when I run my main program, so it's just easier to call machine.reset() because I have it autorun.

Anyway, that's the background info.

BetaRavener commented 6 years ago

Ah interesting, I have been fighting with the memory problem too. So machine.reset() works for that? Cool. Another thing you might try to prevent this is to put everything in function (call it main) so you don't create global variables. When the variables from function get out of scope, they should be collected. However as I said, out of memory error still happens to me sometimes. Might be libraries or really anything.

I'll look if the files can be flushed somehow and if I was going to do this, I would place it in Menu->Action->Reset so it's not the first thing you'll click as "newbie". Also a warning message might be good idea (with that checkbox "Don't show this again").

Or if we can find other way to get memory cleared up, it would be very nice.