Skip to content

Script Upgrade Example

Introduction

Script upgrade of QuecThing generally refers to the process of replacing the original QuecPython script with the new script. In this mode, you need to package the QuecPython scripts into a compressed package in .tar.gz format and upload it to Developer Center, and the device obtained the firmware package from Developer Center for an OTA upgrade.

FunctionDescription
Qth.otaRequest()Requests OTA upgrade plans from Developer Center.
Qth.setAppVer()Sets the App (QuecPython script) version Information.

Note: See OTA Upgrade API and Product Configuration API for details.

Procedure

1. Log in to Developer Center

Log in to Developer Center. If you don't have an account, click Register Now to register.

2. Create a Product

Creating a product is the first step in product development. A product is an abstract description of a class of devices defined by Developer Center. A product is used to manage devices of the same category. For example, if you have an aromatherapy diffuser with LTE networking capability and you need to connect the aromatherapy diffuser to Developer Center to monitor it, you can define it as a product "Smart Aromatherapy Diffuser".

3. OTA Upgrade Operations

a. Create a Version Package

Package the new QuecPython script into a compressed package in .tar.gz format.

Note: Tip: You can use the 7-Zip tool for Windows and the tar command for Linux.

For example, this is the new script file.

bash
.
└── example.py

Execute the tar command to package the script file and generate the upgrade package ota.tar.gz.

bash
tar zcvf ota.tar.gz ./example.py

b. Add a Version Package

img
  • Version Package Name: Version package name.
  • Component Type: Select "MCU firmware".
  • Version Package Type: Full Package or Delta Package.
    • Delta Package is for upgrading the specified original version, i.e., for minor feature upgrading or bug fixing.
    • Full Package is not for a specified source version, and all devices can be upgraded.
  • Source Version: Version of the source firmware package. This item is displayed if "Delta Package" is selected, but not for the "Full Package". (Developer Center determines whether the version number in the device information reported when the device connects to Developer Center is consistent with this parameter. If it is consistent, Developer Center issues the upgrade information.)
  • Target Version: New version number of the firmware package. (Once the device is upgraded, it needs to report the upgraded version number to Developer Center. Developer Center will check whether the version number reported by the device is consistent with this parameter. If it is consistent, the upgrade is successful.)
  • Upload File: The script file format should be .tar.gz.
  • Remarks: Information describing the uploaded firmware version.

c. Verify Firmware Package (Optional)

Firmware verification is for ensuring the security and availability of the firmware to be mass upgraded to minimize the upgrade risk in case of unexpected losses. Before mass upgrading devices, you may verify a single device’s firmware and perform the OTA upgrade.

i. Select the version package to be verified and click "Verify Firmware".

img

ii. Select the device to be verified, enter the component identifier to be verified and then submit the verification.

img

iii. Click "Details" of the version package to view the "Verification Details".

img

d. Create an Upgrade Plan

An upgrade plan should be created or selected from existing plans before a device upgrade. The plan contains device(s) to be upgraded, upgrade time, components configurations and etc.

img

i. Fill in Basic Information

img
  • Plan Name: Plan name.

  • Product to Be Upgraded: The product that needs upgrading.

  • Set Blacklist and Whitelist: All devices under the product will be upgraded if no whitelist or blacklist is set. The blacklist has a higher priority than the whitelist if both the whitelist and blacklist are set.

    • Whitelist: Only the device(s) in the whitelist can be upgraded.
    • Blacklist: The device(s) in the blacklist cannot be upgraded.
  • Time Zone: A required parameter. Developer Center will only push the upgrade plan during the push period in this time zone.

  • Push Period: An optional parameter. The period of Developer Center automatically pushing the upgrade plan.

  • Upgrade Mode:

    • Silent Upgrade: Upgrade is automatically completed by the application, without requiring any user confirmation. The device will be upgraded and restarted in the new version once it is opened again.

    • Manual Upgrade: You need to enter the "Device Control" page, check and confirm the firmware upgrade on the "Device Details" page.

ii. Formulate Upgrade Strategy

During the firmware upgrade, it is inevitable that the upgrade fails due to a poor upgrade environment. To avoid this situation, you need to formulate an upgrade strategy to reduce the probability of upgrade failure. Click "Custom" next to the "Upgrade Strategy" to configure the upgrade strategy in the pop-up window.

img

iii. Add Upgrade Component

The upgrade component is a collection of one or more components created by the user. It is used to select and plan the product components that need to be upgraded when you create the upgrade plan. A component identifier must be unique.

img

iv. Configure Upgrade Text

Upgrade text configuration is required in manual upgrades but can be omitted in silent upgrades. You must configure Chinese and English upgrade texts, and the texts in other languages are optional.

img

v. Activate Upgrade Plan

After completing the above steps of Add a Version Package and Create an Upgrade Plan, you can click "Activate Plan" in the lower left corner to activate the configured plan. Then Developer Center will execute the upgrade task and distribute the selected target version firmware to the target devices.

Note: The activated upgrade tasks cannot be deleted.

e. Initialize the Device and Connect It to Developer Center

To establish device management and OTA upgrade, initialize the device and connect it to Developer Center. This connection needs to be safe and stable to ensure communication between the device and Developer Center.

python
    Qth.init()
    Qth.setProductInfo('p111xt','V2VUei9ZVWt2SnpL')
    eventOtaCb={
            'otaPlan':App_otaPlanCb,
            'fotaResult':App_fotaResultCb
            }
    eventCb={
        'devEvent':App_devEventCb, 
        'recvTrans':App_cmdRecvTransCb, 
        'recvTsl':App_cmdRecvTslCb, 
        'readTsl':App_cmdReadTslCb, 
        'readTslServer':App_cmdRecvTslServerCb,
        'ota':eventOtaCb
        }
    Qth.setEventCb(eventCb)
    Qth.setAppVer('V1.0.1', App_appResultCb)
    Qth.start()

Note: The device connected to Developer Center over MQTT protocol will be automatically created on Developer Center.

f. Request an OTA Upgrade

Precondition: Before a device requests an OTA upgrade, make sure that the device is connected to Developer Center.

1)Once the upgrade plan is made and activated, the device can request an OTA upgrade by calling Qth.otaRequest().
2)The device does not need to send an OTA upgrade request to Developer Center and Develop Center verifies the upgrade plan and issues the plan to the device every 10 minutes, such as 10:00 or 10:10.

  • Sample code
    python
    # Request an OTA upgrade plan from Developer Center.
    Qth.otaRequest()

f. Check Upgrade Result

Once the device requests an OTA upgrade plan, it will automatically call the callback function otaPlanCb() and report the OTA upgrade plan information to Developer Center if the device is included in the upgrade plan. The OTA upgrade plan information includes component identifier + source version + target version + minimum power + minimum signal strength + firmware package size. If the device meets the upgrade strategy requirements specified in the plan, it will accept the upgrade by calling Qth.otaAction(1) or reject the upgrade by calling Qth.otaAction(0).

  • Issue the upgrade plan. The reported content is shown as follows (including component identifier, source version, target version, minimum power, minimum signal strength, and disk space required for OTA upgrade).

    Sample code of processing the event callback function:

  • python

def App_otaPlanCb(plans): print('otaPlan:', plans) Qth.otaAction(1) ```

g. Device Upgrade Process Feedback

A successful FOTA upgrade involves 3 steps: receive upgrade plan, download in progress and successful upgrade. Each upgrade step triggers a corresponding event reported through the callback function. The events provide feedback on the progress of the FOTA upgrade process as follows:

  • Firmware upgrade result

    python
    def App_appResultCb(comp_no, result):
        print('appResult:',comp_no, result)

After the device upgrade, it will automatically report the upgrade result when it restarts and connects to Developer Center.

4. Monitor Upgrade

Click "Upgrade Monitoring" in the upgrade plan list. In the device upgrade list, you can view the upgrade status of all devices in this plan.

img

点Click "Component Details" to view the upgrade logs as shown in the following figure.

img

img