How to update LTE modem firmware on RouterOS using Python RouterOS-api

Note: if you just want to upgrade the LTE modem firmware using the RouterOS terminal or SSH, see MikroTik: How to update LTE modem firmware from the terminal

Important:: For most modems, the firmware upgrade requires an active LTE data connection and hence requires the correct SIM PIN to be set. See How to set LTE SIM PIN on RouterOS using Python RouterOS-api for details.

try:
    output = api.get_resource('/interface/lte').call('firmware-upgrade', {
        'id': lte_interface['id'],
        'upgrade': 'yes' # unconditional upgrade!
    })
except routeros_api.exceptions.RouterOsApiCommunicationError as e:
    error_message = str(e)
    if 'Firmware is already up to date' in error_message:
        print("LTE modem firmware is already up-to-date")
    else:
        raise e

Example output (if firmware has been updated)

Note the command takes 3..5 minutes to finish (time for the modem to download & install the firmware and then restart).

[{'status': 'connecting', '.section': '0'},
 {'status': 'connecting', '.section': '1'},
 {'status': 'downloading: 10%', '.section': '2'},
 {'status': 'downloading: 15%', '.section': '3'},
 {'status': 'downloading: 20%', '.section': '4'},
 {'status': 'downloading: 25%', '.section': '5'},
 {'status': 'downloading: 30%', '.section': '6'},
 {'status': 'downloading: 38%', '.section': '7'},
 {'status': 'downloading: 41%', '.section': '8'},
 {'status': 'downloading: 47%', '.section': '9'},
 {'status': 'downloading: 55%', '.section': '10'},
 {'status': 'downloading: 61%', '.section': '11'},
 {'status': 'downloading: 66%', '.section': '12'},
 {'status': 'downloading: 71%', '.section': '13'},
 {'status': 'downloading: 78%', '.section': '14'},
 {'status': 'downloading: 83%', '.section': '15'},
 {'status': 'downloading: 88%', '.section': '16'},
 {'status': 'downloading: 94%', '.section': '17'},
 {'status': 'downloading: 96%', '.section': '18'},
 {'status': 'downloading: 97%', '.section': '19'},
 {'status': 'downloading: 97%', '.section': '20'},
 {'status': 'Preparing to update', '.section': '21'},
 {'status': 'Preparing to update', '.section': '22'},
 {'status': 'Preparing to update', '.section': '23'},
 {'status': 'Preparing to update', '.section': '24'},
 {'status': 'Preparing to update', '.section': '25'},
 {'status': 'Preparing to update', '.section': '26'},
 {'status': 'Preparing to update', '.section': '27'},
 {'status': 'installing firmware: 10%', '.section': '28'},
 {'status': 'installing firmware: 10%', '.section': '29'},
 {'status': 'installing firmware: 20%', '.section': '30'},
 {'status': 'installing firmware: 20%', '.section': '31'},
 {'status': 'installing firmware: 20%', '.section': '32'},
 {'status': 'installing firmware: 20%', '.section': '33'},
 {'status': 'installing firmware: 20%', '.section': '34'},
 {'status': 'installing firmware: 20%', '.section': '35'},
 {'status': 'installing firmware: 20%', '.section': '36'},
 {'status': 'installing firmware: 20%', '.section': '37'},
 {'status': 'installing firmware: 20%', '.section': '38'},
 {'status': 'installing firmware: 20%', '.section': '39'},
 {'status': 'installing firmware: 20%', '.section': '40'},
 {'status': 'installing firmware: 20%', '.section': '41'},
 {'status': 'installing firmware: 20%', '.section': '42'},
 {'status': 'installing firmware: 20%', '.section': '43'},
 {'status': 'installing firmware: 20%', '.section': '44'},
 {'status': 'installing firmware: 20%', '.section': '45'},
 {'status': 'installing firmware: 20%', '.section': '46'},
 {'status': 'installing firmware: 20%', '.section': '47'},
 {'status': 'installing firmware: 20%', '.section': '48'},
 {'status': 'installing firmware: 20%', '.section': '49'},
 {'status': 'installing firmware: 20%', '.section': '50'},
 {'status': 'installing firmware: 20%', '.section': '51'},
 {'status': 'installing firmware: 20%', '.section': '52'},
 {'status': 'installing firmware: 20%', '.section': '53'},
 {'status': 'installing firmware: 20%', '.section': '54'},
 {'status': 'installing firmware: 20%', '.section': '55'},
 {'status': 'installing firmware: 20%', '.section': '56'},
 {'status': 'installing firmware: 20%', '.section': '57'},
 {'status': 'installing firmware: 20%', '.section': '58'},
 {'status': 'installing firmware: 20%', '.section': '59'},
 {'status': 'installing firmware: 20%', '.section': '60'},
 {'status': 'installing firmware: 20%', '.section': '61'},
 {'status': 'installing firmware: 20%', '.section': '62'},
 {'status': 'installing firmware: 20%', '.section': '63'},
 {'status': 'installing firmware: 20%', '.section': '64'},
 {'status': 'installing firmware: 30%', '.section': '65'},
 {'status': 'installing firmware: 30%', '.section': '66'},
 {'status': 'installing firmware: 30%', '.section': '67'},
 {'status': 'installing firmware: 30%', '.section': '68'},
 {'status': 'installing firmware: 30%', '.section': '69'},
 {'status': 'installing firmware: 30%', '.section': '70'},
 {'status': 'installing firmware: 30%', '.section': '71'},
 {'status': 'installing firmware: 30%', '.section': '72'},
 {'status': 'installing firmware: 30%', '.section': '73'},
 {'status': 'installing firmware: 30%', '.section': '74'},
 {'status': 'installing firmware: 30%', '.section': '75'},
 {'status': 'installing firmware: 30%', '.section': '76'},
 {'status': 'installing firmware: 30%', '.section': '77'},
 {'status': 'installing firmware: 30%', '.section': '78'},
 {'status': 'installing firmware: 30%', '.section': '79'},
 {'status': 'installing firmware: 30%', '.section': '80'},
 {'status': 'installing firmware: 30%', '.section': '81'},
 {'status': 'installing firmware: 30%', '.section': '82'},
 {'status': 'installing firmware: 30%', '.section': '83'},
 {'status': 'installing firmware: 30%', '.section': '84'},
 {'status': 'installing firmware: 30%', '.section': '85'},
 {'status': 'installing firmware: 30%', '.section': '86'},
 {'status': 'installing firmware: 30%', '.section': '87'},
 {'status': 'installing firmware: 30%', '.section': '88'},
 {'status': 'installing firmware: 30%', '.section': '89'},
 {'status': 'installing firmware: 30%', '.section': '90'},
 {'status': 'installing firmware: 30%', '.section': '91'},
 {'status': 'installing firmware: 30%', '.section': '92'},
 {'status': 'installing firmware: 30%', '.section': '93'},
 {'status': 'installing firmware: 30%', '.section': '94'},
 {'status': 'installing firmware: 30%', '.section': '95'},
 {'status': 'installing firmware: 30%', '.section': '96'},
 {'status': 'installing firmware: 30%', '.section': '97'},
 {'status': 'installing firmware: 30%', '.section': '98'},
 {'status': 'installing firmware: 30%', '.section': '99'},
 {'status': 'installing firmware: 30%', '.section': '100'},
 {'status': 'installing firmware: 30%', '.section': '101'},
 {'status': 'installing firmware: 40%', '.section': '102'},
 {'status': 'installing firmware: 40%', '.section': '103'},
 {'status': 'installing firmware: 40%', '.section': '104'},
 {'status': 'installing firmware: 40%', '.section': '105'},
 {'status': 'installing firmware: 40%', '.section': '106'},
 {'status': 'installing firmware: 40%', '.section': '107'},
 {'status': 'installing firmware: 40%', '.section': '108'},
 {'status': 'installing firmware: 40%', '.section': '109'},
 {'status': 'installing firmware: 40%', '.section': '110'},
 {'status': 'installing firmware: 40%', '.section': '111'},
 {'status': 'installing firmware: 40%', '.section': '112'},
 {'status': 'installing firmware: 40%', '.section': '113'},
 {'status': 'installing firmware: 40%', '.section': '114'},
 {'status': 'installing firmware: 40%', '.section': '115'},
 {'status': 'installing firmware: 40%', '.section': '116'},
 {'status': 'installing firmware: 40%', '.section': '117'},
 {'status': 'installing firmware: 40%', '.section': '118'},
 {'status': 'installing firmware: 40%', '.section': '119'},
 {'status': 'installing firmware: 40%', '.section': '120'},
 {'status': 'installing firmware: 40%', '.section': '121'},
 {'status': 'installing firmware: 40%', '.section': '122'},
 {'status': 'installing firmware: 40%', '.section': '123'},
 {'status': 'installing firmware: 40%', '.section': '124'},
 {'status': 'installing firmware: 40%', '.section': '125'},
 {'status': 'installing firmware: 40%', '.section': '126'},
 {'status': 'installing firmware: 40%', '.section': '127'},
 {'status': 'installing firmware: 40%', '.section': '128'},
 {'status': 'installing firmware: 40%', '.section': '129'},
 {'status': 'installing firmware: 40%', '.section': '130'},
 {'status': 'installing firmware: 40%', '.section': '131'},
 {'status': 'installing firmware: 40%', '.section': '132'},
 {'status': 'installing firmware: 40%', '.section': '133'},
 {'status': 'installing firmware: 40%', '.section': '134'},
 {'status': 'installing firmware: 40%', '.section': '135'},
 {'status': 'installing firmware: 40%', '.section': '136'},
 {'status': 'installing firmware: 50%', '.section': '137'},
 {'status': 'installing firmware: 50%', '.section': '138'},
 {'status': 'installing firmware: 50%', '.section': '139'},
 {'status': 'installing firmware: 50%', '.section': '140'},
 {'status': 'installing firmware: 50%', '.section': '141'},
 {'status': 'installing firmware: 50%', '.section': '142'},
 {'status': 'installing firmware: 50%', '.section': '143'},
 {'status': 'installing firmware: 50%', '.section': '144'},
 {'status': 'installing firmware: 50%', '.section': '145'},
 {'status': 'installing firmware: 50%', '.section': '146'},
 {'status': 'installing firmware: 50%', '.section': '147'},
 {'status': 'installing firmware: 50%', '.section': '148'},
 {'status': 'installing firmware: 50%', '.section': '149'},
 {'status': 'installing firmware: 50%', '.section': '150'},
 {'status': 'installing firmware: 50%', '.section': '151'},
 {'status': 'installing firmware: 50%', '.section': '152'},
 {'status': 'installing firmware: 50%', '.section': '153'},
 {'status': 'installing firmware: 50%', '.section': '154'},
 {'status': 'installing firmware: 50%', '.section': '155'},
 {'status': 'installing firmware: 50%', '.section': '156'},
 {'status': 'installing firmware: 50%', '.section': '157'},
 {'status': 'installing firmware: 50%', '.section': '158'},
 {'status': 'installing firmware: 50%', '.section': '159'},
 {'status': 'installing firmware: 50%', '.section': '160'},
 {'status': 'installing firmware: 50%', '.section': '161'},
 {'status': 'installing firmware: 50%', '.section': '162'},
 {'status': 'installing firmware: 50%', '.section': '163'},
 {'status': 'installing firmware: 50%', '.section': '164'},
 {'status': 'installing firmware: 50%', '.section': '165'},
 {'status': 'installing firmware: 60%', '.section': '166'},
 {'status': 'installing firmware: 60%', '.section': '167'},
 {'status': 'installing firmware: 60%', '.section': '168'},
 {'status': 'installing firmware: 60%', '.section': '169'},
 {'status': 'installing firmware: 60%', '.section': '170'},
 {'status': 'installing firmware: 60%', '.section': '171'},
 {'status': 'installing firmware: 60%', '.section': '172'},
 {'status': 'installing firmware: 60%', '.section': '173'},
 {'status': 'installing firmware: 60%', '.section': '174'},
 {'status': 'installing firmware: 60%', '.section': '175'},
 {'status': 'installing firmware: 60%', '.section': '176'},
 {'status': 'installing firmware: 60%', '.section': '177'},
 {'status': 'installing firmware: 60%', '.section': '178'},
 {'status': 'installing firmware: 60%', '.section': '179'},
 {'status': 'installing firmware: 60%', '.section': '180'},
 {'status': 'installing firmware: 60%', '.section': '181'},
 {'status': 'installing firmware: 60%', '.section': '182'},
 {'status': 'installing firmware: 60%', '.section': '183'},
 {'status': 'installing firmware: 70%', '.section': '184'},
 {'status': 'installing firmware: 70%', '.section': '185'},
 {'status': 'installing firmware: 70%', '.section': '186'},
 {'status': 'installing firmware: 70%', '.section': '187'},
 {'status': 'installing firmware: 70%', '.section': '188'},
 {'status': 'installing firmware: 70%', '.section': '189'},
 {'status': 'installing firmware: 70%', '.section': '190'},
 {'status': 'installing firmware: 70%', '.section': '191'},
 {'status': 'installing firmware: 70%', '.section': '192'},
 {'status': 'installing firmware: 70%', '.section': '193'},
 {'status': 'installing firmware: 70%', '.section': '194'},
 {'status': 'installing firmware: 70%', '.section': '195'},
 {'status': 'installing firmware: 70%', '.section': '196'},
 {'status': 'installing firmware: 70%', '.section': '197'},
 {'status': 'installing firmware: 70%', '.section': '198'},
 {'status': 'installing firmware: 80%', '.section': '199'},
 {'status': 'installing firmware: 80%', '.section': '200'},
 {'status': 'installing firmware: 80%', '.section': '201'},
 {'status': 'installing firmware: 80%', '.section': '202'},
 {'status': 'installing firmware: 80%', '.section': '203'},
 {'status': 'installing firmware: 80%', '.section': '204'},
 {'status': 'installing firmware: 80%', '.section': '205'},
 {'status': 'installing firmware: 80%', '.section': '206'},
 {'status': 'installing firmware: 80%', '.section': '207'},
 {'status': 'installing firmware: 80%', '.section': '208'},
 {'status': 'installing firmware: 80%', '.section': '209'},
 {'status': 'installing firmware: 80%', '.section': '210'},
 {'status': 'installing firmware: 80%', '.section': '211'},
 {'status': 'installing firmware: 80%', '.section': '212'},
 {'status': 'installing firmware: 80%', '.section': '213'},
 {'status': 'installing firmware: 80%', '.section': '214'},
 {'status': 'installing firmware: 80%', '.section': '215'},
 {'status': 'installing firmware: 80%', '.section': '216'},
 {'status': 'installing firmware: 80%', '.section': '217'},
 {'status': 'installing firmware: 80%', '.section': '218'},
 {'status': 'installing firmware: 80%', '.section': '219'},
 {'status': 'installing firmware: 80%', '.section': '220'},
 {'status': 'installing firmware: 80%', '.section': '221'},
 {'status': 'installing firmware: 80%', '.section': '222'},
 {'status': 'installing firmware: 80%', '.section': '223'},
 {'status': 'installing firmware: 80%', '.section': '224'},
 {'status': 'installing firmware: 80%', '.section': '225'},
 {'status': 'installing firmware: 90%', '.section': '226'},
 {'status': 'installing firmware: 90%', '.section': '227'},
 {'status': 'firmware installed', '.section': '228'}]