diff --git a/src/otaconf/gateway-node/autoexec.be b/src/otaconf/gateway-node/autoexec.be index 06b8d7b0afbe2fb1ad2786dae379f472c477d00a..1d47cd3748ab216994efbfd448a1e29a7e221660 100644 --- a/src/otaconf/gateway-node/autoexec.be +++ b/src/otaconf/gateway-node/autoexec.be @@ -118,14 +118,11 @@ def _send_file_chunk() _configuration_files.remove(0) _send_file_chunk() + return end - print('test') - var mac = _devices_to_receive_file[uuid][0] - print('anus') - if _file_in_process == nil if !path.exists(uuid) tasmota.log('OTA: file: ' + uuid + ' not found - skip', 2) @@ -133,6 +130,7 @@ def _send_file_chunk() _configuration_files.remove(0) _send_file_chunk() + return end tasmota.log('OTA: opening file: ' + uuid, 2) @@ -141,12 +139,14 @@ def _send_file_chunk() _file_send_retries = 3 _current_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) var payload = uuid + string.format("%03i", _current_chunk_id) + _current_chunk print('send payload: ' + payload) + print(size(payload)) + print(mesh.MAX_LEN) mesh.send(mac, payload) else @@ -169,7 +169,7 @@ def _send_file_chunk() tasmota.log('OTA: retries exceeded: ' + str(_current_chunk_id) + ' to: ' + mac, 2) end 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 _file_in_process.close() @@ -191,7 +191,7 @@ def _send_file_chunk() 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 _execute_commands() end @@ -207,13 +207,13 @@ def _initiate_file_transfer() tasmota.log('OTA: processing file: ' + uuid, 2) 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 num_chunks = 1 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 end @@ -235,7 +235,7 @@ def _initiate_file_transfer() 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 _execute_commands() end diff --git a/src/otaconf/sensor-node/autoexec.be b/src/otaconf/sensor-node/autoexec.be index 12c128ac4fc952db6b0979042051bc25f07b017f..a47e85d628491ac711273a3865aca1d6ead32cf1 100644 --- a/src/otaconf/sensor-node/autoexec.be +++ b/src/otaconf/sensor-node/autoexec.be @@ -24,7 +24,10 @@ def _check_file_transfer_finished(uuid) if path.exists(merged_file_name) path.remove(merged_file_name) end + + print('opening file ' + merged_file_name) + print(path.listdir('/')) var merged_file = open(merged_file_name, 'a') for file_name : files @@ -32,11 +35,14 @@ def _check_file_transfer_finished(uuid) var part_file = open(file_name, 'r') merged_file.write(part_file.read()) part_file.close() - path.remove(file_name) + # path.remove(file_name) end end merged_file.close() + + print(path.listdir('/')) + print('written file ' + merged_file_name) _files_in_process.remove(uuid) end end @@ -44,6 +50,9 @@ end def _store_chunk(payload) var uuid = payload[0..11] var chunk_id = payload[12..14] + + print('storing chunk ' + chunk_id) + var file = open(uuid + '_' + chunk_id + '.part', 'w') file.write(payload[15..mesh.MAX_LEN])