download boot.py and main.py by ftp
-
Trying to find example of downloading file by ftp? Is ftp a builtin library? Anyway example of how to download a file by ftp? Basically want to download a program logic by ftp and reboot to activate the new logic.
-
-
@misterlisty ftplib.mpy should work on a Lopy, give that you use the latest firmware and the mpy file was created with the proper mpy-cross program. You have to remove or rename ftplib.py from the file system, otherwise the .py file is used.
-
@robert-hh can i use ftplib.mpy will lopy recognise this? when i use the ftplib.py from the esp dir i get allocation memeory...this mean i have to bytefreeze it?
-
@misterlisty Once you have a local clone of that repository, you can run "git pull" to update that. However, Pycom is not very consistent in it's repository handling. So I had to delete and re-clone the repositories a few times. But that is also not a big deal.
-
@robert-hh thanks, one more questions, how to keep up with updates done by pycom, i assume i do a GET of github and merge the chaages?
-
@misterlisty Frozen bytecode is a mechanism to store compiled python code in the flash memory. During execution, it will not use RAM for the code and static strings, only for the dynamic data it deals with. If you want to use that, you have to create your own firmware images. That is not really complicated, just the initial step seems a little bit complicated. The git repository is at: https://github.com/pycom/pycom-micropython-sigfox, the tailored esp-if is at https://github.com/pycom/pycom-esp-idf. The readme.md there gives you instructions on how to setup the build environment. Once you have set it up, you can copy the files to be placed in flash into the directory pycom-micropython-sigfox/esp23/frozen and start a build run. That all works best on unix, worst on Windows.
There is an intermediate solution of precompiling your python script on your PC and load the compiled version to the devices file system. The code will still be loaded to RAM, but not RAM is required for compiling. That helps if your run out of memory at the import statement. For that, you need the cross-compiler, which is also part of the github package, and would also required to setup the build environment. As a conveniene offer, I have pre-built verions of the cross compiler mpy-cross in my own repository at https://github.com/robert-hh/Shared-Stuff. The files mpy-cross-pycom.exe and mpy-cross-pycom-linux are the once suitable for the pycom products.
-
If you have a fresh Lopy, ftp is enabled by default. You will have a wifi network named lopy-wlan-xxxx
If you connect to the wifi network (password is www.pycom.io) you can use a ftp program like Filezilla and transfer files in both directions.
Server 192.168.4.1
User: micro
Pass: python
-
@robert-hh thanks whatis frozen bytecode? seems like something i need to know!
-
@misterlisty In ther esp8266 subdir of that repository there is a smaller version of ftplib. You may also put ftplib into frozen bytecode, or write you own little tool to download main.py and boot.py.
-
from ftplib import *
File "main.py", line 13, in <module>
MemoryError: memory allocation failed, allocating 662 bytesI'm using the ftplib from github as suggested, i just want to be able to update the boot and main files remotely..is this how other people are doing OTA? At the moment, i'm only updating the script files
-
@misterlisty Th eftp server is built in. For an ftp client, there is a library here: https://github.com/SpotlightKid/micropython-ftplib
I tried that on LoPy and it works. There is an example using this ftplib in the OTA discussion: https://forum.pycom.io/topic/518/ota-or-not-ota-that-is-the-question/74
I used that to download the firmware image.