Skip to content

FOTA Upgrade Example

Introduction

FOTA upgrade of QuecThing generally refers to the process of writing new firmware into the Quectel module to replace the original firmware. In all upgrade modes, you need to upload the new firmware package to Developer Center, and the device obtains the firmware package from Developer Center to realize the OTA upgrade. The device itself can update features accordingly. This section explains how to perform a FOTA upgrade in QuecOpen solution.

FunctionDescription
Qth_otaRequest()Requests OTA upgrade plans.
Qth_configSetModuleVer()Sets module's version number.
Qth_configGetModuleVer()Gets the module's version number.

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 Wi-Fi 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. Add a Version Package

img
  • Version Package Name: Version package name.
  • Component Type: Module firmware or MCU firmware.
    • Module firmware upgrade (FOTA): Write the new firmware to the Quectel module.
    • MCU firmware upgrade (SOTA): Download the new software package to the external MCU through the Quectel module.
  • 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 file format should be .bin/.zip/.rar/.pack/.mini_1/.mini_2/.py/.tar/.tar.gz/.s19/.bin_1/.bin_2. Up to 5 files are supported and a single file size cannot exceed 100 MB.
  • Remarks: Information describing the uploaded firmware version.

b. 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

c. 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. Complete 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.

d. 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.

c
/* Initialize QuecThing SDK. */
Qth_devInit();
/* Set module's version number. */
Qth_configSetModuleVer("v1.0.0");
/* Register event callback functions. */
Qth_eventCb_t event_cb = {0};
Qth_otaEventCb_t otaCb = {0};
otaCb.planCb = otaPlanCb;
otaCb.downloadCb = otaDownloadCb;
otaCb.resultCb = otaResultCb;
event_cb.otaEventCb = otaCb;
Qth_configSetEventCb(event_cb);
/* Initiates the connection to Developer Center. */
Qth_devStart();

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

e. 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
    c
    /* 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 Qth_otaPlanCb_f 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 return TRUE to accept the upgrade, or return FALSE to reject the upgrade.

  • 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:

    c
    qbool otaPlanCb(Qth_otaPlan_t *planList, quint16_t count)
    {
        quint16_t i;
        for (i = 0; i < count; i++)
        {
            Quos_logPrintf(APPS_OPEN, LL_DBG, "identity:%s,type:%d,srcVer:%s,dstVer:%s,minBattery:%d,minFlash:%d,minSignal:%d",
                            planList[i].identity, (qint32_t)planList[i].type, planList[i].srcVer, planList[i].dstVer, (qint32_t)planList[i].minBattery, (qint32_t)planList[i].minFlash, (qint32_t)planList[i].minSignal);
        }
        return TRUE;
    }

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 download in progress (The downloading result will be sent through the callback function every 10% download)

    c
    void otaDownloadCb(char *identity, quint8_t percent)
    {
        Quos_logPrintf(APPS_OPEN, LL_DBG, "identity:%s, percent:%d", identity, percent);
    }
  • Firmware upgrade result

    c
    void otaResultCb(char *identity, qbool result)
    {
        Quos_logPrintf(APPS_OPEN, LL_DBG, "identity:%s, result:%d", identity, 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