05-04-2018, 06:15 AM
Regarding the last test here is the function in the state it is now.
As you can see I had set the Log.ReplaceCRLF property to false:
I have made a copy of the logfile and using the HxD hex editor I have cut away all data preceding the start of the file transfer (where the magic byte E9 is located) and following the arrival of the last byte in the file.
Then I have used WinMerge to compare the original bin file with the edited version of the logfile.
What I find is 9 instances where the following byte pattern has been inserted, making up for the additional 81 bytes:
In plain text: "<CRLF>Sent : " (not including the quotes)
This pattern is found in the file at the following addresses:
$7F4D
$FF56
$17F5F
$1FF68
$27F71
$2FF7A
$37F83
$3FF8C
$47F95
Notice that these addresses are exactly $8009 (32777 decimal) bytes apart!
The inserted bytes are 9 so it seems like after every $8000 bytes sent the extra stuff is inserted.
The first packet insertion point is not at address $8000 but that is probably because I have edited out the leading part of the file when I tried to make the log the same as the source file.
In fact when I look at the unedited log I see more of these insertions leading up to the first one inside the file body.
Now the question is:
Are these items actually sent or are they artifacts of the TIdLogFile logging?
If they are actually sent then the file transfer is of course not going to work....
If I could find a way to export the file body content from a Wireshark logfile, then it would be possible to compare the data there. But I am totally lost in Wireshark due to the number of commands and options etc.
Just being able to export exactly the bytes sent by the PC to the IoT device would make it possible to then use a hex editor to find the start of the file transfer and verify if there is a difference between the FireFox and Indy transfers.
As you can see I had set the Log.ReplaceCRLF property to false:
Code:
function TConfigCommHandler.UploadFirmware(FileName: string; URL: string): boolean;
var
HTTP: TIdHTTP;
Src: TIdMultipartFormDataStream;
Log: TIdLogFile;
begin
Result := false;
if not FileExists(FileName) then exit;
HTTP := TIdHTTP.Create;
Log := TIdLogFile.Create;
try
Src := TIdMultipartFormDataStream.Create;
try
Src.AddFile('update', FileName);
Log.Filename := 'D:\Engineering\Projects\Subversion\PC\WiFiConfig\Docs\WiFi.log';
Log.LogTime := false;
Log.ReplaceCRLF := false;
Log.Active := true;
try
HTTP.Request.BasicAuthentication := true;
HTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0';
HTTP.Request.Username := FUserName;
HTTP.Request.Password := FPassword;
HTTP.AllowCookies := true; //Added to try make the swrver accept update
HTTP.Intercept := Log;
HTTP.Request.Referer := URL;
HTTP.Post(URL, Src); //Send the update file
Result := true;
except
on E: Exception do
FLastError := 'Exception: ' + E.Message;
end;
finally
Src.Free;;
end;
finally
Log.Active := false;
Log.Free;
HTTP.Free;
end;
end;
I have made a copy of the logfile and using the HxD hex editor I have cut away all data preceding the start of the file transfer (where the magic byte E9 is located) and following the arrival of the last byte in the file.
Then I have used WinMerge to compare the original bin file with the edited version of the logfile.
What I find is 9 instances where the following byte pattern has been inserted, making up for the additional 81 bytes:
Code:
0D 0A 53 65 6E 74 20 3A 20
This pattern is found in the file at the following addresses:
$7F4D
$FF56
$17F5F
$1FF68
$27F71
$2FF7A
$37F83
$3FF8C
$47F95
Notice that these addresses are exactly $8009 (32777 decimal) bytes apart!
The inserted bytes are 9 so it seems like after every $8000 bytes sent the extra stuff is inserted.
The first packet insertion point is not at address $8000 but that is probably because I have edited out the leading part of the file when I tried to make the log the same as the source file.
In fact when I look at the unedited log I see more of these insertions leading up to the first one inside the file body.
Now the question is:
Are these items actually sent or are they artifacts of the TIdLogFile logging?
If they are actually sent then the file transfer is of course not going to work....
If I could find a way to export the file body content from a Wireshark logfile, then it would be possible to compare the data there. But I am totally lost in Wireshark due to the number of commands and options etc.
Just being able to export exactly the bytes sent by the PC to the IoT device would make it possible to then use a hex editor to find the start of the file transfer and verify if there is a difference between the FireFox and Indy transfers.