SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By DannyDJ
#48559
Hi! I would like to send picture to FTP server and i managed to send it but it gets very corrupted. In picture are missing segment of picture. Picture in module is saved correctly but when i try to send it, half of picture is good but another half is corrupted. For reading picture i'm using file.readlines()?

Any ideas?
By jasonharper
#48581
readlines() is completely inappropriate for use with a picture, as it breaks up the file into lines of text - even though carriage return/linefeed characters do not have any such meaning in most graphics formats. Use file.read() if you're sure the entire file will fit into RAM; otherwise, use something like file.read(4096) in a loop to read it in chunks. Also, use mode "rb" instead of "r" when opening the file - I'm not sure if that's absolutely required on the Telit modules, but it won't hurt to explicitly indicate that you're reading a binary file rather than text.
By DannyDJ
#48608
Hi! Tnx for the reply!I've try before the file.read(4096) in a loop like:

for line file.read(4096):
MDM.send(line,0)

but then data is sent "bit by bit" until it reaches the 4096 and it is to slow for my project, for 4096 size of data takes about 2 minutes to send to FTP server.I'm using always 'rb' = read binary
Pictures stored in module are about 40kb.
By jasonharper
#48613
That's not valid syntax; I assume you meant "for line in file.read(4096):", which I'd expect to be horribly slow! The read method returns a single string, not a list of strings as readlines does; iterating over a string gives you characters, not lines, so you're sending a single character at a time (and NOT looping to read additional blocks of data from the file). Try something like this:
Code: Select all
while 1:
    block = file.read(4096)
    if not block: 
        break    # EOF reached
    MDM.send(block,0)
By DannyDJ
#48618
Hi! Tnx again.I'll try your way. I'll post the results.
By DannyDJ
#49009
Finally fixed it!The problem was that while sending binary data of picture the data was lost during upload, so you have to check for the lost data and resend again binary data which was lost.
And this works for readlines() and read(size).
By gussy
#49037
What are you using to take the picture if you don't mind me asking?
By DannyDJ
#49038
I take picture from IP camera.