main.py does not appear to working after boot

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
Frida
Posts: 45
Joined: Sat Jan 30, 2016 2:20 pm
Location: Middelfart, Denmark

Re: main.py does not appear to working after boot

Post by Frida » Fri Jul 12, 2019 2:03 pm

Roberthh wrote:
Fri Jul 12, 2019 12:31 pm
It may depend from the terminal emulator. Picocom switches by default the modem control lined in a way that is seen by the esressif kind if bott loader enabling as reset. You can disable that with calling options
I use GtkTerm to communicate with.
The same is true when I supply the circuits from a USB power supply as well.
Yes Frida is my watchdog!

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Sat Jul 13, 2019 7:49 pm

I moved everything from main.py to boot.py and it seems to be working after a reboot now; however now I don't seem to be able to connect to the ESP32 with rshell. I suspect its because of the never ending while loop (in boot.py). Can anyone confirm this?

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

Re: main.py does not appear to working after boot

Post by Roberthh » Sat Jul 13, 2019 7:56 pm

REPL starts after both boot.py and main.py have finished. An endless loop in boot.py or main.py prevents REPL.

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Sun Jul 14, 2019 1:15 pm

So in the case where I want to continuously monitor something, in this case a temperature; how do I accomplish that? Do I call a function from main that initiates an never ending loop? Do I use the scheduler module instead? What would be the best practice?

Also based on my experience, in this specific instance, it did not seem like any of the code in main was being executed, I am basing this on the steps I took putting all of the code into boot.py. Before I got all of the code into boot.py (I was moving it a few pieces at a time); after each power cycle, I would enter the REPL and run dir(), and it was only returning the items in boot.py. Thanks, for all your input.

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

Re: main.py does not appear to working after boot

Post by Roberthh » Sun Jul 14, 2019 1:29 pm

The way the firmware is coded (main.c, function mp_task()) , first boot.py is called, and then main.py, if the mode is PYEXEC_MODE_FRIENDLY_REPL. The behavior you have seen does not meet that coding, unless boot.py does not finish or the device is set to raw mode (Ctrl.A).
You may start code from main.py, but that would also not get you a REPL prompt, as long as it is running. You can start a thread in main.py with you program, which will run in parallel to the REPL. But if the device is planned to run unattended, this is seems not to be needed.

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Sun Jul 14, 2019 1:46 pm

I only need the repl during testing and troubleshooting. It will run unattended

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Sun Jul 14, 2019 5:42 pm

Moving items between boot.py and main.py leads me to conclude that main.py is not being executed. How can I look under the hood and figure this out? How do I check PYEXEC_MODE_FRIENDLY_REPL mode? How do I determine if raw mode (Ctrl.A) is set? should I try to call main.py explicitly?

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

Re: main.py does not appear to working after boot

Post by Roberthh » Sun Jul 14, 2019 6:59 pm

If xou see the normal REPL prompt >>> then the device is in the friendly mode.

smith.randallscott
Posts: 32
Joined: Mon May 13, 2019 12:42 pm

Re: main.py does not appear to working after boot

Post by smith.randallscott » Sun Jul 14, 2019 7:18 pm

I do see the normal >>>. Is there any other reason main.py wouldn't be called? So far I have set a variable at the last line of boot.py and I see this variable when I run dir() from the REPL, I also set a variable on the first line of main.py and I do not see this when I run dir()

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

Re: main.py does not appear to working after boot

Post by Roberthh » Sun Jul 14, 2019 7:57 pm

- How did you create and modify main.py on the device?
- DO you use rhsell as terminal for REPL ro a different program like picocom or putty?

Post Reply