Updating main.py with infinite loop

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
matthewlai
Posts: 3
Joined: Thu Oct 24, 2019 12:34 am

Updating main.py with infinite loop

Post by matthewlai » Thu Oct 24, 2019 12:36 am

Hello!

I have just started using MicroPython on a custom PCB with ESP32-WROOM-32, and everything seems fine except... I don't know how to update the python files once I have a working main.py. As is the case in most embedded applications, my main.py has an infinite loop, and so I never get the REPL.

How do I update main.py (or access the filesystem in general) if I no longer have access to the REPL? Do I need to do a firmware flash every time I want to update the file? How are people working around this?

Thanks
Matthew

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

Re: Updating main.py with infinite loop

Post by kevinkk525 » Thu Oct 24, 2019 5:42 am

You could use rshell which stops the working loop and then uploads the file, then you disconnect and reset the device.

Or you use the webrepl to upload your main.py.

Or are you asking for a completely automated update of the main.py file?
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: Updating main.py with infinite loop

Post by Christian Walther » Thu Oct 24, 2019 11:20 am

By “no longer have access to the REPL”, do you mean that you explicitly detached the UART from stdin/out (using dupterm)? Because if not, you can just send a control-C through the UART and that will break out of your infinite loop and drop you in the REPL – same as in CPython on the desktop.

And yes, if you have it enabled, WebREPL also works for both uploading files and sending ctrl-C even while your infinite loop is running.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Updating main.py with infinite loop

Post by jimmo » Thu Oct 24, 2019 11:25 am

To elaborate on what Kevin said, sending a Ctrl-C (whether interactive or just by literally sending 0x03 to the serial console) should terminate any code that is running.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Updating main.py with infinite loop

Post by Roberthh » Thu Oct 24, 2019 7:03 pm

To elaborate on what Kevin said, sending a Ctrl-C (whether interactive or just by literally sending 0x03 to the serial console) should terminate any code that is running.
Unless the code disabled interrupt by Ctrl-C

matthewlai
Posts: 3
Joined: Thu Oct 24, 2019 12:34 am

Re: Updating main.py with infinite loop

Post by matthewlai » Sat Oct 26, 2019 1:26 pm

Thanks guys! I didn't realise uploading through WebRepl still worked even when the prompt doesn't. I thought it was just a convenience mechanism that uses the repl prompt to receive and save the file.

I also didn't realise Ctrl-C still works!

Thanks!

Post Reply