main.py does not run automatically

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
bukaida
Posts: 19
Joined: Tue Jul 07, 2020 6:30 pm

main.py does not run automatically

Post by bukaida » Tue Jul 07, 2020 6:52 pm

I have started learning micropython today. I have successfully flashed my ESP8266 with latest stable micropython firmware, configured it with my router and was able to run webrepl.html with python prompt.
Now as I was following the tutorial https://docs.micropython.org/en/latest/ ... ystem.html I saw that there should be two automatic script boot.py and main.py. os.listdir() showed me there is only one boot.py. so I created one main.py containing a simple script

Code: Select all

import os
print(os.listdir())


when I press the reset button and reconnect to webrepl, nothing happens. However when I type ->

Code: Select all

import main
it runs and list the files. What am I missing? Also nothing happens if I download boot.py from device via webrepl, put these lines in it and reload it back.

I know this is very basic but pardon my ignorance as today is my "Hello World" day to Micropython.

I am on windows 10 pro but I guess that does not matter on a browser based interface.

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

Re: main.py does not run automatically

Post by Christian Walther » Tue Jul 07, 2020 9:09 pm

My guess is that it does run, but by the time you connect again, you have missed the output already. Try working with a serial connection (which, unlike WebREPL, isn’t disconnected at reset) or adding some delay into the script so you can catch it before it’s done.

bukaida
Posts: 19
Joined: Tue Jul 07, 2020 6:30 pm

Re: main.py does not run automatically

Post by bukaida » Wed Jul 08, 2020 10:34 am

My project requires mobility. Can a serial connection be made with WiFi ? I am just beginning, so have no clear idea.

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

Re: main.py does not run automatically

Post by Christian Walther » Wed Jul 08, 2020 5:43 pm

No (unless you use some kind of external UART-to-WiFi bridge). So that leaves the second option (adding a delay). Or use something other than console output to check if your script runs, e.g. blink an LED or write to the filesystem.

bukaida
Posts: 19
Joined: Tue Jul 07, 2020 6:30 pm

Re: main.py does not run automatically

Post by bukaida » Sat Jul 11, 2020 9:52 am

Is it possible to interface with the board directly via a python program running on command prompt? The connection should be WiFi.

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

Re: main.py does not run automatically

Post by jimmo » Mon Jul 13, 2020 2:16 am

Yes, you can write a program on the micropython that receives commands over wifi from a host program running on your PC.

Here's a simple web server for MicroPython that comes with an example of controlling GPIO pins remotely. https://github.com/miguelgrinberg/microdot

For a more complete solution, maybe check out https://github.com/peterhinch/micropython-iot

bukaida
Posts: 19
Joined: Tue Jul 07, 2020 6:30 pm

Re: main.py does not run automatically

Post by bukaida » Thu Jul 16, 2020 5:13 am

Yeah Peter himself is helping me out with that in another thread :)

Post Reply