Best practise for setting up a device with static files

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
andydrizen
Posts: 8
Joined: Wed Jan 08, 2020 10:10 am

Best practise for setting up a device with static files

Post by andydrizen » Wed Jan 08, 2020 10:21 am

Hi,

I have a Wemos D1 Mini that broadcasts a little webserver. All of my Python files are frozen and combined with the firmware, which makes it super easy (and efficient) to setup a device. However, the HTML files need to be copied over manually, which means setting up the WebREPL temporarily to perform the copy, and then disabling it.

As I may need to setup many of these devices: is there a best practise for copying over static resources?

Many thanks,
Andy

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

Re: Best practise for setting up a device with static files

Post by jimmo » Wed Jan 08, 2020 11:36 am

See https://github.com/micropython/micropython/issues/5394 for a recent discussion on this -- but in summary:
- Making this easier is definitely a thing that's on the radar (via the manifest.py system)
- See Peter's reply on that issue for a good solution for the meantime (to convert your static file to a Python file which is then frozen)

Note that it might sound inefficient to wrap up the contents in a Python file, but because of the way the bytecode and freezing process, I'm fairly sure this process has zero overhead -- i.e. you end up with a string that points directly to the bytes in ROM.

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: Best practise for setting up a device with static files

Post by jedie » Wed Jan 08, 2020 12:04 pm

Oh, this is exact the same problem I have, too. I will take a look into the pull request and peter's solution.
Thanks for sharing this.

EDIT: Okay i have take a look to https://github.com/micropython/micropython/issues/5394 and https://github.com/peterhinch/micropython_data_to_py

But the Problem is A ESP8266 has a limit of 1MB for code he an execute, discussed here viewtopic.php?f=16&t=6677
The same thread offers a way to flash a filesystem that contains the static files. Seems with more useful, because the static files can be used as normal files, e.g.: open() vs import them ... So you can also change the content in normal way. And you can skip code in inisetup.py to format the flash.

Post Reply