Posted: Sun Jan 11, 2015 6:34 am Post subject: Filtering bad files
I have a number of data loggers which save their data to an SD card, and every 15 minutes, the card is read and all existing files are sent to a server using a cellular modem and a HTTP POST.
I have had a very rare instance where a faulty file is written with a length of <50 bytes or > 7000 bytes, which should never happen. I know from previous experience that it is best to leave these files untouched ( for example kill 'filename' is not reliable if 'filename' is a bad file). What i am trying to do ( and struggling) is to ignore such files in my HTTP POST loop. Changing the name of a bad file to "badfile' for example then filtering these out in my loop wouild obviously work, but again, i am reluctant to do anything with a bad file as again previous experience has suggested that it is best to leave them alone.
The folloiwng code works, but obviously if the bad file is not the last file read by the dir*.* statement, then the very last file may never be read. ver = 2.0.7.7
Any clever suggestions?
'at this point files have been written to the SD card ' and we need to POST to the server. 'msg_ID is an err flag which is cleared if the previous test condition is good 'eg TCP connection is good, or 'the telit modem search response is good.
Myfilename =Dir("*.*")'get first file Do
If Myfilename =""Then
Print #1 , ">> no files left to send" ExitDo'exit when no files left to send End If
call tcp_connect(main_server , 80)'good connection -> msgID = 0 If Msg_id <>0ThenExitDo'give up. Not able to connect call post_to_server(myfilename)' post the data Call Waitfortelitresponses_sec("GUDUPLD" , 42)
If Msg_id =0Then'good response 'delete the sent file. Chdir"\" Chdir datafolder
Kill Myfilename 'delete from sd card Print #1 , ">> Got gudupld - deleting "; Myfilename
print #1 , ">> reset hardware WD"
Elseif msg_id <>0then
Print #1 , ">> badupload from server" call write_err_message("incorr or no response frm server ") End If
Myfilename =Dir() If Myfilename =""Then Print #1 , ">> No files left to send" ExitDo'exit when no files left to send End If
filelength =filelen()'gets length of current file from prev dir() cmd
if filelength < minfilesizelng or filelength > maxfilesizelng then print #1 , ">> bad file length.. "; filelength
call write_err_message("bad file length") exitdo end if
loop'get next file 'go back to start of main loop and do all sorts of other stuff
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum