Skip to content
Snippets Groups Projects
Commit ea5f3e49 authored by Strasser, Andreas's avatar Strasser, Andreas
Browse files

fixed file transfer

parent 483b6f5d
No related branches found
No related tags found
No related merge requests found
...@@ -118,14 +118,11 @@ def _send_file_chunk() ...@@ -118,14 +118,11 @@ def _send_file_chunk()
_configuration_files.remove(0) _configuration_files.remove(0)
_send_file_chunk() _send_file_chunk()
return
end end
print('test')
var mac = _devices_to_receive_file[uuid][0] var mac = _devices_to_receive_file[uuid][0]
print('anus')
if _file_in_process == nil if _file_in_process == nil
if !path.exists(uuid) if !path.exists(uuid)
tasmota.log('OTA: file: ' + uuid + ' not found - skip', 2) tasmota.log('OTA: file: ' + uuid + ' not found - skip', 2)
...@@ -133,6 +130,7 @@ def _send_file_chunk() ...@@ -133,6 +130,7 @@ def _send_file_chunk()
_configuration_files.remove(0) _configuration_files.remove(0)
_send_file_chunk() _send_file_chunk()
return
end end
tasmota.log('OTA: opening file: ' + uuid, 2) tasmota.log('OTA: opening file: ' + uuid, 2)
...@@ -141,12 +139,14 @@ def _send_file_chunk() ...@@ -141,12 +139,14 @@ def _send_file_chunk()
_file_send_retries = 3 _file_send_retries = 3
_current_chunk_id = 0 _current_chunk_id = 0
_last_chunk_id = 0 _last_chunk_id = 0
_current_chunk = _file_in_process.read(mesh.MAX_LEN - _CHUNK_HEADER_SIZE) _current_chunk = _file_in_process.read(mesh.MAX_LEN - _CHUNK_HEADER_SIZE - 1)
tasmota.log('OTA: sending chunk: ' + str(_current_chunk_id) + ' to: ' + mac, 2) tasmota.log('OTA: sending chunk: ' + str(_current_chunk_id) + ' to: ' + mac, 2)
var payload = uuid + string.format("%03i", _current_chunk_id) + _current_chunk var payload = uuid + string.format("%03i", _current_chunk_id) + _current_chunk
print('send payload: ' + payload) print('send payload: ' + payload)
print(size(payload))
print(mesh.MAX_LEN)
mesh.send(mac, payload) mesh.send(mac, payload)
else else
...@@ -169,7 +169,7 @@ def _send_file_chunk() ...@@ -169,7 +169,7 @@ def _send_file_chunk()
tasmota.log('OTA: retries exceeded: ' + str(_current_chunk_id) + ' to: ' + mac, 2) tasmota.log('OTA: retries exceeded: ' + str(_current_chunk_id) + ' to: ' + mac, 2)
end end
else else
_current_chunk = _file_in_process.read(mesh.MAX_LEN - _CHUNK_HEADER_SIZE) _current_chunk = _file_in_process.read(mesh.MAX_LEN - _CHUNK_HEADER_SIZE - 1)
if size(_current_chunk) == 0 if size(_current_chunk) == 0
_file_in_process.close() _file_in_process.close()
...@@ -191,7 +191,7 @@ def _send_file_chunk() ...@@ -191,7 +191,7 @@ def _send_file_chunk()
end end
end end
tasmota.set_timer(2000, _send_file_chunk, _file_transfer_timer_id) tasmota.set_timer(3000, _send_file_chunk, _file_transfer_timer_id)
else else
_execute_commands() _execute_commands()
end end
...@@ -207,13 +207,13 @@ def _initiate_file_transfer() ...@@ -207,13 +207,13 @@ def _initiate_file_transfer()
tasmota.log('OTA: processing file: ' + uuid, 2) tasmota.log('OTA: processing file: ' + uuid, 2)
var f = open(uuid) var f = open(uuid)
var num_chunks = size(f) / (mesh.MAX_LEN - _CHUNK_HEADER_SIZE) var num_chunks = size(f) / (mesh.MAX_LEN - _CHUNK_HEADER_SIZE - 1)
if num_chunks == 0 && size(f) > 0 if num_chunks == 0 && size(f) > 0
num_chunks = 1 num_chunks = 1
end end
if size(f) % (mesh.MAX_LEN - _CHUNK_HEADER_SIZE) != 0 if size(f) % (mesh.MAX_LEN - _CHUNK_HEADER_SIZE - 1) != 0
num_chunks + 1 num_chunks + 1
end end
...@@ -235,7 +235,7 @@ def _initiate_file_transfer() ...@@ -235,7 +235,7 @@ def _initiate_file_transfer()
end end
end end
tasmota.set_timer(2000, _send_file_chunk, _file_transfer_timer_id) tasmota.set_timer(5000, _send_file_chunk, _file_transfer_timer_id)
else else
_execute_commands() _execute_commands()
end end
......
...@@ -25,6 +25,9 @@ def _check_file_transfer_finished(uuid) ...@@ -25,6 +25,9 @@ def _check_file_transfer_finished(uuid)
path.remove(merged_file_name) path.remove(merged_file_name)
end end
print('opening file ' + merged_file_name)
print(path.listdir('/'))
var merged_file = open(merged_file_name, 'a') var merged_file = open(merged_file_name, 'a')
for file_name : files for file_name : files
...@@ -32,11 +35,14 @@ def _check_file_transfer_finished(uuid) ...@@ -32,11 +35,14 @@ def _check_file_transfer_finished(uuid)
var part_file = open(file_name, 'r') var part_file = open(file_name, 'r')
merged_file.write(part_file.read()) merged_file.write(part_file.read())
part_file.close() part_file.close()
path.remove(file_name) # path.remove(file_name)
end end
end end
merged_file.close() merged_file.close()
print(path.listdir('/'))
print('written file ' + merged_file_name)
_files_in_process.remove(uuid) _files_in_process.remove(uuid)
end end
end end
...@@ -44,6 +50,9 @@ end ...@@ -44,6 +50,9 @@ end
def _store_chunk(payload) def _store_chunk(payload)
var uuid = payload[0..11] var uuid = payload[0..11]
var chunk_id = payload[12..14] var chunk_id = payload[12..14]
print('storing chunk ' + chunk_id)
var file = open(uuid + '_' + chunk_id + '.part', 'w') var file = open(uuid + '_' + chunk_id + '.part', 'w')
file.write(payload[15..mesh.MAX_LEN]) file.write(payload[15..mesh.MAX_LEN])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment