Page 1 of 1

OSError 28

Posted: Sun Nov 06, 2016 12:03 pm
by Panzki
Hi everyone,
I have a problem with micropython on my esp8266 12e NodeMCU v2 board.
I used the exact same board for a while now without any problems. However I just started working on a new project which is a bit more complex. I need several files .py files on the board. Currently I have 3 custom .py files and their total size is 2.8kb.
After a fresh install of micropython with the esptool I can upload all my files without any problems using adafruits ampy tool. Then I restart my esp, connect to the serial port, start testing my code and eventually I change something in my code. Then when I want to upload the modified file to the esp it always fails due to OSError 28. Uploading the modified file via the webrepl doesn't work either. It creates an empty file on the esp, but also fails due to OSError 28.
I already searched around for OSError 28 and found that it means "No space left on device", which confuses me. I can't image that the storage of the chip (which is 4MB I think) is completely filled up.


Does anyone had is issue before or even knows of to fix it?

Kind regards
Panzki

Re: OSError 28

Posted: Sun Nov 06, 2016 7:44 pm
by Roberthh
You can check the free space with os.statvfs(""). The first two values of the tuple ar the block size, the 3rd the total number of blocks, the 4th the number of free blocks. If that looks strange, the file system may be corrupted, for whatever reason.
Try to erase the flash then and reload everything to the device. The flash is erased with:

Code: Select all

esptool.py erase_flash

Re: OSError 28

Posted: Mon Nov 07, 2016 11:31 am
by Panzki
Hey Roberthh,
thanks for your reply. It really looks like there are no free blocks left on the chip. :shock:
Unfortunately I can't use BB-Codes for some reason.

>>>os.statvfs("")
(4096, 4096, 869, 0, 0, 0, 0, 0, 0, 255)

I ran the os.stat() command on all of my files on the chip and got this:

>>> for f in os.listdir():
... print('File: {} stats: {}'.format(f, os.stat(f)))
File: boot.py stats: (32768, 0, 0, 0, 0, 0, 160, 2, 2, 2)
File: secrets.py stats: (32768, 0, 0, 0, 0, 0, 123, 24, 24, 24)
File: cnetwork.py stats: (32768, 0, 0, 0, 0, 0, 1062, 32, 32, 32)
File: SimpleHTTPServer.py stats: (32768, 0, 0, 0, 0, 0, 0, 12873600, 12873600, 12873600)
File: BAKmain.py stats: (32768, 0, 0, 0, 0, 0, 95, 56, 56, 56)
File: port_config.py stats: (32768, 0, 0, 0, 0, 0, 0, 22, 22, 22)

I couldn't find any documentation on how to interpret the output, but I guess the the 8th element is the size of the file. What really stands out, is the size of the SimpleHTTPServer.py file. I'm not sure if the unit is bits or bytes. However is seems like it is a lot. On my hard drive the file has a size of 1.452 bytes.

After erasing the flash and reflashing micropython all blocks a free.

>>> os.statvfs("")
(4096, 4096, 869, 868, 868, 0, 0, 0, 0, 255)

I hope this information is useful.

Greetings
Panzki

Re: OSError 28

Posted: Mon Nov 07, 2016 6:07 pm
by dhylands
Here are the docs for the os.statvfs call: https://docs.python.org/3/library/os.html#os.statvfs

I believe that MicroPython just returns a simple tuple, where CPython returns a named-tuple.

The fields returned correspond to the statvfs system call which you can find documentation for here:
https://linux.die.net/man/2/statvfs

EDIT: Added links to stat documentation as well (although MicroPython only returns a tuple and not a stat_result object)
https://docs.python.org/3/library/os.html#os.stat

Re: OSError 28

Posted: Mon Nov 07, 2016 6:17 pm
by Roberthh
The stat() call provides the size of the file as the 7th element. The last three are coded time stamps, which can be neglected. So SimpleHTTPServer.py has a size of 0, the other sizes look fine. The first value tells that it is is a file.

Re: OSError 28

Posted: Wed Nov 09, 2016 10:49 am
by Panzki
Thanks for your replies and the links to the documentation.
On a fresh installation of micropython I can upload all my files without any problems using ampy. I can start my server and it just works. The file system stats are as following:

>>> os.statvfs("")
(4096, 4096, 869, 864, 864, 0, 0, 0, 0, 255)

>>> for f in os.listdir(""):
... print("File: {} stats: {}".format(f, os.stat(f)))

File: boot.py stats: (32768, 0, 0, 0, 0, 0, 160, 0, 0, 0)
File: secrets.py stats: (32768, 0, 0, 0, 0, 0, 123, 42, 42, 42)
File: cnetwork.py stats: (32768, 0, 0, 0, 0, 0, 1062, 46, 46, 46)
File: SimpleHTTPServer.py stats: (32768, 0, 0, 0, 0, 0, 1452, 54, 54, 54)
File: main.py stats: (32768, 0, 0, 0, 0, 0, 95, 58, 58, 58)

As far as I can understand it everything looks fine, and the file size of the SimpleHTTPServer.py isn't 0.
However after changing the code of the SimpleHTTPServer.py and uploading it again it appears that the file system is broken. The os failes to open "main.py" and "boot.py" and doesn't recognize any other files besides the one I just uploaded. This is the output I get: http://pastebin.com/SdBFsEi1

When I reupload all the "corrupted" files the chips works again. I have no clue what's going on here. Maybe the ampy tool breaks something while uploading?

Greetings
Panzki