Safely remove Wemos D1 mini

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
blckpstv
Posts: 28
Joined: Thu Dec 15, 2016 9:11 pm
Location: Belgium

Safely remove Wemos D1 mini

Post by blckpstv » Sat Jan 21, 2017 9:27 pm

Hey I'm pretty sure It something stupid that I oversaw in reading & rereading the docs.

But I'm trying to upload my main.py and I'm doing this via webrepl. I've confirmed this when I os.listdir().

So I reboot and the file is going and main.py could not be read. What I read is that I should safely remove the esp8266 that it keeps the file. How do I do this in terminal on a mac. I've found no command for safely removing a serial device. Except 'umount device name' but that give me and error that it isn't there.

Or do I have to this in micropython console?

blckpstv
Posts: 28
Joined: Thu Dec 15, 2016 9:11 pm
Location: Belgium

Re: Safely remove Wemos D1 mini

Post by blckpstv » Wed Jan 25, 2017 12:01 pm

blckpstv wrote:Hey I'm pretty sure It something stupid that I oversaw in reading & rereading the docs.

But I'm trying to upload my main.py and I'm doing this via webrepl. I've confirmed this when I os.listdir().

So I reboot and the file is going and main.py could not be read. What I read is that I should safely remove the esp8266 that it keeps the file. How do I do this in terminal on a mac. I've found no command for safely removing a serial device. Except 'umount device name' but that give me and error that it isn't there.

Or do I have to this in micropython console?
Nobody or is it such a dumb question? ^^

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Safely remove Wemos D1 mini

Post by deshipu » Wed Jan 25, 2017 2:21 pm

The ESP8266 boards can't act a USB storage -- they only have the serial console. That means you don't need (in fact, can't) "safely remove" them. However, disconnecting their power while they are performing file operations on their internal file system can still result in file corruption -- so don't disconnect it while the file is transferring.

There is no "main.py" on the board by default, so that warning is normal, unless you uploaded a "main.py" file and that can't be read -- that would mean there is something wrong.

blckpstv
Posts: 28
Joined: Thu Dec 15, 2016 9:11 pm
Location: Belgium

Re: Safely remove Wemos D1 mini

Post by blckpstv » Wed Jan 25, 2017 10:00 pm

deshipu wrote:The ESP8266 boards can't act a USB storage -- they only have the serial console. That means you don't need (in fact, can't) "safely remove" them. However, disconnecting their power while they are performing file operations on their internal file system can still result in file corruption -- so don't disconnect it while the file is transferring.

There is no "main.py" on the board by default, so that warning is normal, unless you uploaded a "main.py" file and that can't be read -- that would mean there is something wrong.
Ok dumb question :)
One last to follow up on, when importing dht.py and running >>> run dht.py or python dht.py
I get errors

Code: Select all

dht.py
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'py'
Can I only run main.py?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Safely remove Wemos D1 mini

Post by deshipu » Wed Jan 25, 2017 10:24 pm

The prompt you are getting from the board is already the Python interpreter. You don't have to start it by writing "python" -- there is no operating system and no system prompt. In order to run "dht.py" you need to do "import dht" or "execfile("dht.py")". The "main.py" file gets executed automatically at start, so you will probably want to use that once you finish your code.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Safely remove Wemos D1 mini

Post by pythoncoder » Thu Jan 26, 2017 7:56 am

In general the best way to develop with MicroPython is as follows. If your application is called dht.py you can run it by issuing

Code: Select all

import dht
There's a case, however, for not having it run automatically on import: it can make debugging easier if you don't. So I usually define a function which can have any name, but let's call it main(). Then, after making any change to dht.py on the target, you issue ctrl-D to reset the board followed by

Code: Select all

import dht
dht.main()
The reason I prefer this is because after doing the import you can change global variables. Or your main() function might have arguments you want to alter at runtime.
Once you're happy with the application, to make it auto-run just add the above lines to main.py. If you find you've made a mistake, commenting out those two lines in main.py gets you back to debugging.
Peter Hinch
Index to my micropython libraries.

Post Reply