local ota = {} -- Called when a device requests an OTA update. -- Return nil for default behavior (upgrade if local version > current version). -- Return {allow = false} to deny. -- Return {allow = true} to use local image. -- Return {allow = true, url = "http://..."} to download remote image. function ota.onOtaRequest(device, currentVersion, localVersion, localPath, mfr, imgType) log_info("ota request:") log_info("mfr : 0x" .. string.format("%04X", mfr) .. ", imgType : %x" .. string.format("%04X", imgType)) log_info("version : 0x" .. string.format("%08X", currentVersion)) return nil end -- Called before starting OTA transfer. -- Return true to proceed, false to abort. function ota.onUpdateStart(device, image) log_info("OTA start: " .. device.friendly_name) log_info("Manufacturer: 0x" .. string.format("%04X", image.manufacturer)) log_info("ImageType: 0x" .. string.format("%04X", image.imageType)) return true end -- Called after OTA completes or fails. function ota.onUpdateEnd(device, success) if success then log_info("OTA done: " .. device.friendly_name) else log_info("OTA failed: " .. device.friendly_name) end end return ota