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
Best practise for setting up a device with static files
-
- Posts: 8
- Joined: Wed Jan 08, 2020 10:10 am
Re: Best practise for setting up a device with static files
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.
- 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.
Re: Best practise for setting up a device with static files
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.
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.