Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adb22c2

Browse files
Bruce RainfordBruce Rainford
Bruce Rainford
authored and
Bruce Rainford
committed
Lorawan OTA: Full update case revision is not available
1 parent 3d00091 commit adb22c2

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

examples/OTA-lorawan/firmware/1.17.0/flash/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def main():
1818
LORA_FREQUENCY = 868100000
19-
LORA_NODE_DR = 0
19+
LORA_NODE_DR = 5
2020
LORA_REGION = LoRa.EU868
2121
LORA_DEVICE_CLASS = LoRa.CLASS_C
2222
LORA_ACTIVATION = LoRa.OTAA

examples/OTA-lorawan/firmware/1.17.0/flash/ota.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class LoraOTA:
2424
MSG_HEADER = b'$OTA'
2525
MSG_TAIL = b'*'
2626

27+
FULL_UPDATE = b'F'
28+
DIFF_UPDATE = b'D'
29+
NO_UPDATE = b'N'
30+
2731
UPDATE_INFO_MSG = 1
2832
UPDATE_INFO_REPLY = 2
2933

@@ -46,6 +50,7 @@ def __init__(self, lora):
4650
self.version_file = '/flash/OTA_INFO.py'
4751
self.update_version = '0.0.0'
4852
self.update_time = -1
53+
self.update_type = None
4954
self.resp_received = False
5055
self.update_in_progress = False
5156
self.operation_timeout = 10
@@ -221,13 +226,13 @@ def parse_update_info_reply(self, msg):
221226

222227
try:
223228
token_msg = msg.split(",")
224-
need_updating = int(token_msg[2])
225-
if need_updating:
226-
self.update_version = token_msg[3]
227-
self.update_time = int(token_msg[5])
229+
self.update_type = token_msg[3].encode()
230+
if self.update_type in [self.FULL_UPDATE, self.DIFF_UPDATE]:
231+
self.update_version = token_msg[2]
232+
self.update_time = int(token_msg[4])
228233

229234
if utime.time() < 1550000000:
230-
self.sync_clock(int(token_msg[4]))
235+
self.sync_clock(int(token_msg[5]))
231236

232237
except Exception as ex:
233238
print("Exception getting update information: {}".format(ex))
@@ -374,7 +379,8 @@ def apply_patches(self):
374379

375380
to_patch = ''
376381
print('Updating file: {}'.format(key))
377-
if self.file_exists('/flash/' + key):
382+
if self.update_type == self.DIFF_UPDATE and \
383+
self.file_exists('/flash/' + key):
378384
to_patch = self._read_file(key)
379385

380386
patched_text, success = self.dmp.patch_apply(self.patch_list, to_patch)
@@ -426,7 +432,7 @@ def manifest_failure(self, msg):
426432
return False
427433

428434
def process_manifest_msg(self, msg):
429-
435+
430436
if self.manifest_failure(msg):
431437
print('Manifest failure: Discarding update ...')
432438
self.reset_update_params()
@@ -443,7 +449,8 @@ def process_manifest_msg(self, msg):
443449
def process_filename_msg(self, msg):
444450
self.file_to_patch = self.get_msg_data(msg)
445451

446-
if self.file_exists('/flash/' + self.file_to_patch):
452+
if self.update_type == self.DIFF_UPDATE and \
453+
self.file_exists('/flash/' + self.file_to_patch):
447454
self.device_mainfest["update"] += 1
448455
print("Update file: {}".format(self.file_to_patch))
449456
else:

examples/OTA-lorawan/firmware/1.17.1/flash/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import utime
1616

1717
def main():
18-
print('Rebooting with new firmware version 1.17.1')
19-
18+
print('Booting with firmware version 1.17.1')
19+
2020
LORA_FREQUENCY = 868100000
21-
LORA_NODE_DR = 0
21+
LORA_NODE_DR = 5
2222
LORA_REGION = LoRa.EU868
2323
LORA_DEVICE_CLASS = LoRa.CLASS_C
2424
LORA_ACTIVATION = LoRa.OTAA

examples/OTA-lorawan/firmware/1.17.1/flash/ota.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class LoraOTA:
2424
MSG_HEADER = b'$OTA'
2525
MSG_TAIL = b'*'
2626

27+
FULL_UPDATE = b'F'
28+
DIFF_UPDATE = b'D'
29+
NO_UPDATE = b'N'
30+
2731
UPDATE_INFO_MSG = 1
2832
UPDATE_INFO_REPLY = 2
2933

@@ -46,6 +50,7 @@ def __init__(self, lora):
4650
self.version_file = '/flash/OTA_INFO.py'
4751
self.update_version = '0.0.0'
4852
self.update_time = -1
53+
self.update_type = None
4954
self.resp_received = False
5055
self.update_in_progress = False
5156
self.operation_timeout = 10
@@ -221,13 +226,13 @@ def parse_update_info_reply(self, msg):
221226

222227
try:
223228
token_msg = msg.split(",")
224-
need_updating = int(token_msg[2])
225-
if need_updating:
226-
self.update_version = token_msg[3]
227-
self.update_time = int(token_msg[5])
229+
self.update_type = token_msg[3].encode()
230+
if self.update_type in [self.FULL_UPDATE, self.DIFF_UPDATE]:
231+
self.update_version = token_msg[2]
232+
self.update_time = int(token_msg[4])
228233

229234
if utime.time() < 1550000000:
230-
self.sync_clock(int(token_msg[4]))
235+
self.sync_clock(int(token_msg[5]))
231236

232237
except Exception as ex:
233238
print("Exception getting update information: {}".format(ex))
@@ -374,7 +379,8 @@ def apply_patches(self):
374379

375380
to_patch = ''
376381
print('Updating file: {}'.format(key))
377-
if self.file_exists('/flash/' + key):
382+
if self.update_type == self.DIFF_UPDATE and \
383+
self.file_exists('/flash/' + key):
378384
to_patch = self._read_file(key)
379385

380386
patched_text, success = self.dmp.patch_apply(self.patch_list, to_patch)
@@ -426,7 +432,7 @@ def manifest_failure(self, msg):
426432
return False
427433

428434
def process_manifest_msg(self, msg):
429-
435+
430436
if self.manifest_failure(msg):
431437
print('Manifest failure: Discarding update ...')
432438
self.reset_update_params()
@@ -443,7 +449,8 @@ def process_manifest_msg(self, msg):
443449
def process_filename_msg(self, msg):
444450
self.file_to_patch = self.get_msg_data(msg)
445451

446-
if self.file_exists('/flash/' + self.file_to_patch):
452+
if self.update_type == self.DIFF_UPDATE and \
453+
self.file_exists('/flash/' + self.file_to_patch):
447454
self.device_mainfest["update"] += 1
448455
print("Update file: {}".format(self.file_to_patch))
449456
else:

0 commit comments

Comments
 (0)