Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firmware version check appears to be incorrect #5246

Closed
rccoleman opened this issue Jan 2, 2023 · 3 comments
Closed

Firmware version check appears to be incorrect #5246

rccoleman opened this issue Jan 2, 2023 · 3 comments

Comments

@rccoleman
Copy link

rccoleman commented Jan 2, 2023

I was trying to update my Third Reality plugin modules to a newer firmware version using a local file & index and got this odd set of logs:

Zigbee2MQTT:info  2023-01-01 21:38:53: Checking if update available for 'LR Center Lamp'
Zigbee2MQTT:debug 2023-01-01 21:38:53: Check if update available for '0x282c02bfffeb336c' (3RSP019BZ)
Zigbee2MQTT:debug 2023-01-01 21:38:53: Using endpoint '1'
Zigbee2MQTT:debug 2023-01-01 21:38:53: Received Zigbee message from 'LR Center Lamp', type 'commandQueryNextImageRequest', cluster 'genOta', data '{"fieldControl":0,"fileVersion":268513281,"imageType":54182,"manufacturerCode":4659}' from endpoint 1 with groupID 0
Zigbee2MQTT:debug 2023-01-01 21:38:53: Got OTA request '{"fieldControl":0,"manufacturerCode":4659,"imageType":54182,"fileVersion":268513281}'
Zigbee2MQTT:debug 2023-01-01 21:38:53: ZigbeeOTA: downloaded main index
Zigbee2MQTT:debug 2023-01-01 21:38:53: ZigbeeOTA: Loading override index /app/data/my_index.json
Zigbee2MQTT:debug 2023-01-01 21:38:53: ZigbeeOTA: getting local firmware file /app/data/SmartPlug_Zigbee_PROD_OTA_V29_v1.00.29.ota
Zigbee2MQTT:debug 2023-01-01 21:38:53: Is new image available for '0x282c02bfffeb336c', current '{"fieldControl":0,"manufacturerCode":4659,"imageType":54182,"fileVersion":268513281}', latest meta '{"fileVersion":268513310,"url":"SmartPlug_Zigbee_PROD_OTA_V29_v1.00.29.ota"}'
Zigbee2MQTT:debug 2023-01-01 21:38:53: Update available for '0x282c02bfffeb336c': NO
Zigbee2MQTT:info  2023-01-01 21:38:53: No update available for 'LR Center Lamp'

Version 268513310 from the new file is clearly larger than 268513281, so I poked around in the code and found this PR. isNewImageAvailable() now returns an object with available as a member, but to me it appears that it's still being treated as if it's an integer in isUpdateAvailable().

The object is returned from isNewImageAvailable() like this:

    return {
        available: Math.sign(current.fileVersion - meta.fileVersion),
        currentFileVersion: current.fileVersion,
        otaFileVersion: meta.fileVersion,
    };

But I believe that this is still expecting it to be a positive or negative integer:

    const available = await isNewImageAvailable(requestPayload, logger, device, getImageMeta);
    logger.debug(`Update available for '${device.ieeeAddr}': ${available < 0 ? 'YES' : 'NO'}`);
    if (available > 0) {
        logger.warn(`Firmware on '${device.ieeeAddr}' is newer than latest firmware online.`);
    }
    return {...available, available: available < 0};

I'm not a Javascript guy, so forgive me if I'm missing something, but it started with weird behavior and I suspect this is why.

I'm using 1.29.0-dev commit: 4e40c82 of Zigbee2MQTT.

@Koenkk
Copy link
Owner

Koenkk commented Jan 2, 2023

Well found, thanks! Fixed

Changes will be available in the dev branch in a few hours from now. (https://www.zigbee2mqtt.io/advanced/more/switch-to-dev-branch.html)

@rccoleman
Copy link
Author

There's still an issue when the user chooses the "force" option:

    if (meta.force) {                                                                                              
        return -1; // Negative number means the new firmware is 'newer' than current one                           
    }       

You'd either need to return the object with available: -1 or perhaps just set a variable to the calculation and override it with -1 if the user chooses to force an update.

@Koenkk
Copy link
Owner

Koenkk commented Jan 8, 2023

@rccoleman thanks for your sharp eyes again! fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants