Skip to content

Commit

Permalink
Add OTA update API (#1810)
Browse files Browse the repository at this point in the history
* Add OTA updates in data
* Update dispatcher.py by add rest api for ota updates
* Add OTA updates API
  • Loading branch information
SylvainPer authored Dec 7, 2024
1 parent d83965c commit 80c60e1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Classes/OTA.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,17 @@ def notify_ota_firmware_available(self, srcnwkid, manufcode, imagetype, filevers
logging(self, "Status", " firmware type: %s" % _ota_available["imageType"])
logging(self, "Status", " URL to download: %s" % _ota_available["url"])

if srcnwkid in self.ListOfDevices:
if "OTAUpdate" not in self.ListOfDevices[srcnwkid]:
self.ListOfDevices[srcnwkid]["OTAUpdate"] = {}
if imagetype in self.ListOfDevices[srcnwkid]["OTAUpdate"]:
self.ListOfDevices[srcnwkid]["OTAUpdate"][imagetype].clear()
self.ListOfDevices[srcnwkid]["OTAUpdate"][imagetype] = {
"currentversion": str(fileversion),
"newestversion" : str(_ota_available["fileVersion"]),
"url": _ota_available["url"],
}

if folder:
logging(self, "Status", " Folder to store: %s" % folder)
else:
Expand Down
28 changes: 28 additions & 0 deletions Classes/WebServer/WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,35 @@ def rest_battery_state(self, verb, data, parameters):

_response["Data"] = json.dumps(_battEnv, sort_keys=True)
return _response

def rest_ota_firmware_available(self, verb, data, parameters):
_response = prepResponseMessage(self, setupHeadersResponse())
_response["Headers"]["Content-Type"] = "application/json; charset=utf-8"

if verb == "GET":
_fwAvail = []
for x in self.ListOfDevices:
if x == "0000":
continue

if "OTAUpdate" in self.ListOfDevices[x] and self.ListOfDevices[x]["OTAUpdate"] is not None:
for y in self.ListOfDevices[x]["OTAUpdate"]:
self.logging("Status", "AAA")
device = { 'zdevicename' : self.ListOfDevices[x]["ZDeviceName"],
'model' : self.ListOfDevices[x]["Model"],
'manufacturername' : self.ListOfDevices[x]["Manufacturer Name"],
'ieee' : self.ListOfDevices[x]["IEEE"],
'fwtype' : y,
'currentversion' : self.ListOfDevices[x]["OTAUpdate"][y]["currentversion"],
'newestversion' : self.ListOfDevices[x]["OTAUpdate"][y]["newestversion"],
'url' : self.ListOfDevices[x]["OTAUpdate"][y]["url"],
}
self.logging("Status", str(device))
_fwAvail.append(device)
self.logging("Status", str(_fwAvail))
_response["Data"] = json.dumps(_fwAvail, sort_keys=True)
return _response

def logging(self, logType, message):
self.log.logging("WebServer", logType, message)

Expand Down
1 change: 1 addition & 0 deletions Classes/WebServer/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def setup_list_rest_commands( self ):
( {"Name": "new-hrdwr", "Verbs": {"GET"}, "function": self.rest_new_hrdwr} ),
( {"Name": "nwk-stat", "Verbs": {"GET", "DELETE"}, "function": self.rest_nwk_stat} ),
( {"Name": "non-optmize-device-configuration", "Verbs": {"GET"}, "function": self.non_optmize_device_configuration} ),
( {"Name": "ota-firmware-available", "Verbs": {"GET"}, "function": self.rest_ota_firmware_available } ),
( {"Name": "ota-firmware-device-list", "Verbs": {"GET"}, "function": self.rest_ota_devices_for_manufcode } ),
( {"Name": "ota-firmware-list", "Verbs": {"GET"}, "function": self.rest_ota_firmware_list} ),
( {"Name": "ota-firmware-update", "Verbs": {"PUT"}, "function": self.rest_ota_firmware_update } ),
Expand Down

0 comments on commit 80c60e1

Please sign in to comment.