MicropyGPS: Failed to write file
-
Hi!
I'm trying to get a GPS receiver up and running with my LoPy and I have gotten a simple test program to run to make sure that the micropyGPS module works, but when I am trying to integrate the module into my larger project the file fails to upload. I'm sure it has something to do with the file size being rather large, but I'm pretty new and I haven't been able to figure out how to get around this issue.
I think the solution would be to freeze the module, but I have found all tutorials on how to do this to be a bit confusing. Can anyone help me out with this?
Thanks!
-
@paloma You can configure Filezilla in a way, that double-click on a file in the LoPy pane will open that file in your Favorite editor. Storing that file will transfer it back to the LoPy. For REPL, you might also use other tools like screen, picocom, putty, .., which support VT100 code sequences, in case you need them.
-
@robert-hh I had to move everything to a completely different network, but it works now! My set up is a little clumsy, but I'm able to develop new code again. Thank you and @crumble so much for your help!!
Right now what I'm doing is connecting to WiFi via the atom repl and then opening filezilla. I then use FTP to transfer the new files over and manually restart the board to run the new main.py. It's a little clumsy having to switch back and forth and reconnect to WiFi on each go, but I can probably add the WiFi code to the main.py that I'm working from so that it doesn't lose connection on reboot.
I learned a ton about micropython and the lopy through having this problem, so I'm not miffed about having to deal with it.
-
@paloma The windows command line ftp will not work with the Lopy, since it does not support passive mode. But you should at öeast be able to connect. Only commands like ls or all file transfers will not work.
As @crumble said, there may be a problem with the network settings in the router.
The link for setting FileZilla is here: https://docs.pycom.io/getting-started/programming/ftp
-
@robert-hh I had to move to a windows machine, so I'm using the command prompt and I get the same output as before. Connection timed out.
@crumble I'm not sure how to check if I can reach another FTP server. I'll try to look into firewall issues to see what I can figure out.
-
Check if you can reach another FTP server. If not, ask your admins to open the firewall for FTP (whole range).
Your client must be in pasive mode and shall allow only 1 connection.
Search mode of the docu is f* up :(
finds the sentence, displays the extract, but link does not work. How can one shout RTFM, if the FM doesn't work? Wait. Print the doc and read it carefully ;) pycom mentioned somewhere how to configure your FTP client.
-
@paloma You may start with command line ftp, which avoids the setting djungle of Filezilla. Just run:
ftp -p <your_ip_address>
It should ask you for name (micro) and password (python).
then you can:
cd /flash
ls
-
@robert-hh It took me a little while to get this up and running because I had to switch to my laptop (desktop only has a wired connection to a different network). I connected my Lopy4 to the same wireless network as my laptop and ran the program and received an IP (yay!). I printed wlan.ifconfig() and received 4 addresses. I then looked at the page you linked and determined that the first item would be the IP address. Unfortunately when I use filezilla with this new IP address I get the same problems (boo!). Not sure where to go from here.
-
@paloma To access via FTP, you have to be on the same network. I do not know how your PC if configured, but most likely not for 192.168.4.x. If you want to use LoPy in your home network, then it is better to operate it in STA mode and let it connect to you local access point. Follow the instructions here under the heading:
Connection to a Router
. https://docs.pycom.io/tutorials-and-examples/all/wlan. If you know your SSID, you can simplify that to:from network import WLAN wlan = WLAN(mode=WLAN.STA) wlan.connect('my_ssid', auth=(network.WLAN.WPA2, 'mywifikey'), timeout=5000) while not wlan.isconnected(): machine.idle() # save power while waiting print('WLAN connection succeeded!') print('network config:', wlan.ifconfig())
The last line will tell you the IP address of your device, which you then can use to connect with ftp and/or telnet.
-
@robert-hh Thanks for getting back to me! I'm very new to micropython and ubuntu, so this has been a learning experience for sure!
I'm working on trying to connect to the Lopy using FTP, but so far I can't connect to the board. I tried using the default FTP client in a terminal, but I get the error, "connect: Connection timed out."
When I try to connect through Filezilla, I get the same issue. "Connection timed out after 20 seconds of inactivity"
My settings are as follows:in the site manager:
General Tab:
Host: 192.168.4.1 (I verified in Atom that this is the correct address)
Protocol: FTP
Encryption: plain FTP (insecure)
user: micro
password:pythonTransfer Settings Tab:
Transfer mode: Passive
Maximum number of connections: 1Any ideas what else I need to change?
-
@paloma Try using simple robust tools like ftp (Filezilla) for file upload and putty or telnet for the terminal. The Pymakr suite, even if it may be convenient, adds another level of complexity and problems.
-
@crumble I received my LoPy4s and now I have a different, but similar error.
The first upload worked fine and I was able to load all files through pymakr. I changed some code and tried to upload again and I got the following:
[1/1] Writing file to main.py (9kb)
Failed to write file, trying again...
Failed to write file, trying again...
Failed to write file: incorrect padding
Upload done, resetting boardThen it seems like the file has been uploaded, but I get errors in weird places that shouldn't be giving me errors. Code that didn't change at all from the first import like this line:
bme = bme280.BME280(i2c = i2c)
triggers this error:
AttributeError: 'module' object has no attribute 'BME280'
And this line:
print("BME280 initialized...")
gives me the error:
SyntaxError: invalid syntax.
Please note that these errors occur after trying to upload the same file, so it's triggering different nonsensical errors.
I did some searching around and a few people said this could also be a memory issue, but I'm just stunned that my 5 relatively simple files are causing this huge of an error. Any ideas?
-
@crumble Thanks so much for this information! I should have some LoPy 4s arriving this morning so I'll try to see if they can handle the imports and if not, I'll poke around with the resources you linked and see if I can make something work.
-
compiling on the LoPy fragments the RAM. You can see this with
import micropython micropython.mem_info(1)
This can cause a lot of problems. So you have to ensure that large memory chuncks has be handled first. So you have to compile the file in the order of their size and allocate huge buffers first.
You can rid of the compiling process by using a cross compiler and upload only the bytecode. So your memory is not that fragmented on startup. This is much easier than using frozen modules. Additionally the files are a bit smaller.
Yout have to install python with this cross compiler on your development machine and than py_cross
Compile the to module_name.mpy and upload only the *.mpy file and not the *.py.
This is a really beginner friendly task ;)
Using frozen modules will be better. You can store often used strings in flash as well, when you compile the whole firmware. But using precompiled modules is a good start.
Please keep in mind, that the micropython implementation on the LoPy creates a new object for each float operation. I don't get why they implemeted this bs. If you are using huge objects this means that you have to to keep float operations out of your loops and call the gc after each block of float operations. Your GPS stuff may use them a lot.
It would be nice, if someone collects all the performance information related to the pycom implementation. And it would be nice of pycom if they mark methods which use heap. Actually they suggest for huge tasks method like
with a_lock: do_something()
and not the basic stuff which needs no heap. IMHO a bad idea on such small machines. Most of the time this lack of information drives you crazy. Knowing these simple things let the *py become again neat little machines.
-
I assume that you use an old LoPy. I suggest that you switch to a 4MB version.
You have to optimize your code for the memory footprint. Either you have to keep your lib small and forget the string methods, or configure the GPS too send only needed sentences with a pause inbetween. I don't suggest the config solution. I failed today ;)
-
update:
My problem consists of not having enough flash memory to load the micropyGPS module. I was hoping to be able to boot from an SD card and store my modules there, but it seems (from various threads on this forum) that that wasn't possible as of 2 years ago. Is that still the case?
I'd prefer to have everything just stored in flash, but I'm getting all sorts of problems with that. The current problem is a Memory error [MemoryError: memory allocation failed, allocating 128 bytes]. I have also gotten Guru Meditation Errors which sound lovely, but in reality are confusing and troubling. With all of this trouble I decided to try to just run the code from the SD card which I've heard is possible on the pyboard and should be possible on the lopy if called from the main.py in flash. To test this I moved all of my code to a microSD card and ran commands from this thread (https://forum.pycom.io/topic/701/lopy-doesn-t-boot-from-sd-card/2) directly from the pymakr package in atom.
Anyway, I'm trying to run my 'main.py' from the SD card using the REPL in Atom using the following commands:
from machine import SD
sd = SD()
os.mount(sd, '/sd')
execfile('/sd/main.py')and when I do this it seems to try and run the file, but I get an import error [ImportError: cannot import name MicropyGPS] from the line [from micropyGPS import MicropyGPS]
This line of code worked in an example, so I'm not sure why it wont work now. Any ideas?