SpotlightKid / micropython-ftplib

An FTP client library for MicroPython.
34 stars 17 forks source link

files larger than 5kb cause esp32 to freeze #14

Closed Ruben0595 closed 11 months ago

Ruben0595 commented 1 year ago

When uploading a file larger than ~5kb, my ESP32 freezes. I tried collecting garbage to reduce memory usage, but this did not help. smaller files usually upload fine.

SpotlightKid commented 1 year ago

Code, please.

Ruben0595 commented 1 year ago

sure!

The code is uploading files when it is connected to the internet (not in the code below) and delete files older than a day.

I masked my ftp servers info and got rid of the gc.collect() mentioned above, since it did not help. block size is a bit arbitrarily trying to get stuff working, by filling in random numbers, but used to be 2048. thanks a lot for helping.

today = str(time.localtime()[0])[2:]+ '-' + str(time.localtime()[1]) + '-' + str(time.localtime()[2])
filepath_today = 'database/' + today + '.csv'
ftp = FTP_TLS('webMASKED.MASKED.nl')    #masked informatin, since it is not a public test server
ftp.login(ship_info.mmsi + ship_info.name + '@MASKED', ship_info.ftp_pwd) #inlog name and pwd are from ship_info file
#ftp.retrlines('LIST')

for filename in os.listdir('database'): #for loop iterates over saved files, each with a date.
    try:
        data = 'database/'+filename
        print('uploading ' + filename)

        tim0.init(period=600000, mode=Timer.ONE_SHOT, callback=time_out)    #start interrupt timer, so it gets out of a freeze
        upload_fail = True      #used in further code to let user know if file upload failed
        upload(ftp, data, blocksize = 512)  #upload
        upload_fail = False #upload succeed
        tim0.deinit() #de init timer

        filer.log(filename +' uploaded') #log that a file has been uploaded

        if filename != today+'.csv':    #delete the uploaded file if it is older than a day
            print('data removed ' +filename)
            os.remove(data)
            filer.log(filename +' deleted')

    except Exception as e:
        print(e)
        filer.log('file upload failed ' + str(e))
        upload_fail = True
SpotlightKid commented 1 year ago

Where does it fail in the upload function? (I guess that's the one from ftpupload.py?) Any traceback? Or error messages? Have you tried to set ftp.set_debuglevel(1)?

Ruben0595 commented 1 year ago

it is indeed the upload function from ftpupload.py, which calls storbinary function from ftplib.py. it seems to be just frozen somewhere in the while loop of the storbinary function, which does not have a traceback. when I terminate it, the error: [Errno 113] ECONNABORTED, but this is probably because of terminating it. when trying to set ftp.set_debuglevel(1), error: AttributeError: 'FTP_TLS' object has no attribute 'set_debuglevel'

SpotlightKid commented 1 year ago

Ah, ok, you are using the esp variant. Which doesn't have the debugging commands. I can only suggest inserting strategic print commands into FTP.ntransfercmd to find out what's going on.

Ruben0595 commented 1 year ago

all of the sudden it started working fine, Will just use it and if the problem rises again I will raise the issue again. thanks a lot for helping!!

Ruben0595 commented 1 year ago

I still have issues with sending the files. it just crashes the entire esp every once in a while.

SpotlightKid commented 1 year ago

Thanks for the heads up. But I'm afraid without further debugging on your part I won't be able to get to the bottom of this.

I can only re-iterate what I said before:

I can only suggest inserting strategic print commands into FTP.ntransfercmd to find out what's going on.

Ruben0595 commented 1 year ago

first of all: thanks a lot, your contributions are truly invaluable. I'm trying to recreate the problem, but it seems to work perfectly fine.. it's a bad thing that it works now haha. I'll catch up with you if I can recreate the problem.