Skip to content

Conversation

hwzolin
Copy link
Contributor

@hwzolin hwzolin commented Nov 4, 2022

@puddly Hello, this is the OTA code of thirdreality company. Please check it

@hwzolin hwzolin closed this Nov 4, 2022
@hwzolin hwzolin reopened this Nov 4, 2022
@dmulcahey
Copy link
Collaborator

Install precommit and run the checks. Please address the tagged lint failures

@hwzolin hwzolin closed this Nov 6, 2022
@hwzolin hwzolin reopened this Nov 6, 2022
@codecov-commenter
Copy link

Codecov Report

Base: 99.63% // Head: 99.58% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (ea2c469) compared to base (8a2c754).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1089      +/-   ##
==========================================
- Coverage   99.63%   99.58%   -0.05%     
==========================================
  Files          46       46              
  Lines        7590     7674      +84     
==========================================
+ Hits         7562     7642      +80     
- Misses         28       32       +4     
Impacted Files Coverage Δ
zigpy/appdb.py 99.35% <ø> (ø)
zigpy/appdb_schemas/__init__.py 100.00% <ø> (ø)
zigpy/application.py 98.54% <ø> (ø)
zigpy/backups.py 97.59% <ø> (ø)
zigpy/config/__init__.py 100.00% <ø> (ø)
zigpy/config/defaults.py 100.00% <ø> (ø)
zigpy/config/validators.py 82.60% <ø> (ø)
zigpy/const.py 100.00% <ø> (ø)
zigpy/device.py 99.62% <ø> (ø)
zigpy/endpoint.py 100.00% <ø> (ø)
... and 40 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@puddly
Copy link
Collaborator

puddly commented Nov 7, 2022

@3reality-support @xudo-github @hwzolin I've just tested the latest 1.00.21 firmware for the 3RTHS24BZ temperature/humidity sensor and can confirm that the increased binding table size allows for attribute reporting to be properly configured. Thank you!

I've reverse engineered the OTA image format (#1090) of all of the available images. To save you the trouble of having to implement this PR yourself, can you instead add a few more keys to your JSON:

 {
   "modelId": "3RSB22BZ",
   "url": "https://tr-zha.s3.amazonaws.com/firmwares/SmartButton_Zigbee_PROD_OTA_V21_1.00.21.ota",
   "version": "1.00.21",
+  "imageType": 54184,
+  "manufacturerId": 4659,
+  "fileVersion": 33
 }

These three fields are contained within the Zigbee OTA file header. You can extract them yourself from the parsed header:

$ pip install git+https://github.com/zigpy/zigpy-cli.git
$ pip install --upgrade git+https://github.com/zigpy/zigpy.git  # need latest version for OTA format decoder
$ zigpy ota info SmartButton_Zigbee_PROD_OTA_V21_1.00.21.ota
Parsing SmartButton_Zigbee_PROD_OTA_V21_1.00.21.ota
Header: OTAImageHeader(upgrade_file_id=200208670, header_version=256, header_length=56, field_control=<FieldControl.0: 0>, manufacturer_id=4659, image_type=54184, file_version=33, stack_version=2, header_string='Telink OTA Sample Usage', image_size=126738, *device_specific_file=False, *hardware_versions_present=False, *key=ImageKey(manufacturer_id=4659, image_type=54184), *security_credential_version_present=False)
Number of subelements: 1
Validation result: ValidationResult.UNKNOWN

Let me know when this is done and I can make a PR to add Third Reality OTA support to zigpy.

@hwzolin
Copy link
Contributor Author

hwzolin commented Nov 8, 2022

@puddly Hello, your suggestion has been dealt with, please check if it meets the requirements.

@puddly
Copy link
Collaborator

puddly commented Nov 8, 2022

Thank you. There is one problem with the firmware images themselves.

When a device asks for a firmware image, it sends the following query:

Ota:QueryNextImageCommand(field_control=<FieldControl.0: 0>, manufacturer_code=4659, image_type=54182, current_file_version=268513281)

The device's current sw_build_id is v1.00.19. According to the JSON in your OTA server, the following image is compatible and has a higher version:

{
    "modelId": "3RSP019BZ",
    "url": "https://tr-zha.s3.amazonaws.com/firmwares/SmartPlug_Zigbee_PROD_OTA_V20_v1.00.20.ota",
    "version": "1.00.20",
    "imageType": 54182,
    "manufacturerId": 4659,
    "fileVersion": 32
}

However, the new OTA file's file_version is 32, while the current device's version is 268513281 (0x10013001). Since the current version is bigger than the file version, the OTA upgrade will not be performed, since it will be considered a downgrade.

Can you make the OTA image file versions (not just what is in the JSON) increasing?

@hwzolin
Copy link
Contributor Author

hwzolin commented Nov 8, 2022

@puddly Can you please tell me how you got the current device version 268513281 (0x10013001)?

@puddly
Copy link
Collaborator

puddly commented Nov 8, 2022

This is what the device is sending when it begins an OTA upgrade. You send it an OTA "image notify" command, it sends back a "query next image" command, which contains this version number.

Your devices do not support reading this attribute, the only way it can be queried is when the device itself sends it during an OTA transaction:

image

@puddly
Copy link
Collaborator

puddly commented Nov 8, 2022

Closing in favor of #1096.

@puddly puddly closed this Nov 8, 2022
Hedda added a commit to Hedda/zigbee-herdsman-converters that referenced this pull request Nov 11, 2022
Add URL for Third Reality (3reality) OTA provider to OTA_URLs.md 

https://tr-zha.s3.amazonaws.com/firmware.json

FYI; Third Reality (3reality) OTA provider support and custom image format parser was recently added to zigpy library:

zigpy/zigpy#1096

zigpy/zigpy#1090

zigpy/zigpy#1089


Official website and Facebook group for reference:

https://www.3reality.com/

https://www.facebook.com/ThirdReality.offical/
Koenkk pushed a commit to Koenkk/zigbee-herdsman-converters that referenced this pull request Nov 11, 2022
Add URL for Third Reality (3reality) OTA provider to OTA_URLs.md 

https://tr-zha.s3.amazonaws.com/firmware.json

FYI; Third Reality (3reality) OTA provider support and custom image format parser was recently added to zigpy library:

zigpy/zigpy#1096

zigpy/zigpy#1090

zigpy/zigpy#1089


Official website and Facebook group for reference:

https://www.3reality.com/

https://www.facebook.com/ThirdReality.offical/
@hwzolin
Copy link
Contributor Author

hwzolin commented Nov 28, 2022

@puddly Excuse me, can I update the third reality device on ZHA now?

@puddly
Copy link
Collaborator

puddly commented Nov 28, 2022

home-assistant/core#82509 did not make it in time for 2022.11.4. Once 2022.11.5 comes out, you can by enabling the OTA provider:

zha:
  zigpy_config:
    ota_config:
      thirdreality_provider: true

And then notify a device of the new image. Progress will be in the debug log.

@hwzolin
Copy link
Contributor Author

hwzolin commented Nov 28, 2022

home-assistant/core#82509 did not make it in time for 2022.11.4. Once 2022.11.5 comes out, you can by enabling the OTA provider:

zha:
  zigpy_config:
    ota_config:
      thirdreality_provider: true

And then notify a device of the new image. Progress will be in the debug log.

@puddly Ok, I see, thanks.

@TheJulianJES
Copy link
Contributor

TheJulianJES commented Nov 28, 2022

Not sure if it's important now, since 2022.12.0b0 is just around the corner, but home-assistant/core#82509 is not in the 2022.11.5 milestone.

(but the ThirdReality OTA changes will definitely be available when 2022.12b0 drops)

@puddly
Copy link
Collaborator

puddly commented Nov 28, 2022

@TheJulianJES Thanks! I've added it to the 2022.11.5 milestone.

@hwzolin
Copy link
Contributor Author

hwzolin commented Dec 1, 2022

@puddly Hi, I have upgraded HA to version 11.5, but when I was on an OTA device, I still prompted that no OTA image is available. Am I misconfiguring?

The following pictures are my configuration content, please take a look:
image_notify
Developer Tools
configuration yaml

The chart below is the result of OTA:
update_result

@puddly
Copy link
Collaborator

puddly commented Dec 1, 2022

The format of the OTA JSON changed and thus the parser for it in 2022.11.5 is not working. You should see an error initializing the OTA provider.

I fixed it a few hours ago #1119 and it is in the current beta https://github.com/home-assistant/core/releases/tag/2022.12.0b0

@hwzolin
Copy link
Contributor Author

hwzolin commented Dec 8, 2022

The format of the OTA JSON changed and thus the parser for it in 2022.11.5 is not working. You should see an error initializing the OTA provider.

I fixed it a few hours ago #1119 and it is in the current beta https://github.com/home-assistant/core/releases/tag/2022.12.0b0

@puddly
Hello, I have upgraded HA to 2022.12.0. But my OTA for the humidity and temperature sensor still prompts "No OTA image is available".
I'm confused, what's wrong with the configuration? Could you please tell me all the details of your configuration?
OTA_LOG

@puddly
Copy link
Collaborator

puddly commented Dec 8, 2022

Ah, my mistake! The ota_config key should instead be ota:

zha:
  zigpy_config:
    ota:
      thirdreality_provider: true

Here is a log of the temperature sensor updating:

2022-12-07 21:42:52.736 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA query_next_image handler for 'Third Reality, Inc 3RTHS24BZ': field_control=FieldControl.0, manufacturer_id=4659, image_type=54185, current_file_version=21, hardware_version=None, model='3RTHS24BZ'
2022-12-07 21:42:52.744 DEBUG (MainThread) [zigpy.ota.provider] Downloading https://tr-zha.s3.amazonaws.com/firmwares/TRTL_ThermalSensor_PROD_OTA_V21_1.00.21.ota for ImageKey(manufacturer_id=4659, image_type=54185)
2022-12-07 21:42:53.093 DEBUG (MainThread) [zigpy.ota.provider] Finished downloading from https://tr-zha.s3.amazonaws.com/firmwares/TRTL_ThermalSensor_PROD_OTA_V21_1.00.21.ota for ImageKey(manufacturer_id=4659, image_type=54185) ver 1.00.21
2022-12-07 21:42:53.095 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA image version: 33, size: 124946. Update needed: True
2022-12-07 21:43:07.778 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA query_next_image handler for 'Third Reality, Inc 3RTHS24BZ': field_control=FieldControl.0, manufacturer_id=4659, image_type=54185, current_file_version=21, hardware_version=None, model='3RTHS24BZ'
...
2022-12-07 21:43:42.310 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.0
2022-12-07 21:43:42.529 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.1
2022-12-07 21:43:42.780 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.1
2022-12-07 21:43:43.032 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.1
2022-12-07 21:43:43.273 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.2
2022-12-07 21:43:43.531 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.2

@hwzolin
Copy link
Contributor Author

hwzolin commented Dec 9, 2022

Ah, my mistake! The ota_config key should instead be ota:

zha:
  zigpy_config:
    ota:
      thirdreality_provider: true

Here is a log of the temperature sensor updating:

2022-12-07 21:42:52.736 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA query_next_image handler for 'Third Reality, Inc 3RTHS24BZ': field_control=FieldControl.0, manufacturer_id=4659, image_type=54185, current_file_version=21, hardware_version=None, model='3RTHS24BZ'
2022-12-07 21:42:52.744 DEBUG (MainThread) [zigpy.ota.provider] Downloading https://tr-zha.s3.amazonaws.com/firmwares/TRTL_ThermalSensor_PROD_OTA_V21_1.00.21.ota for ImageKey(manufacturer_id=4659, image_type=54185)
2022-12-07 21:42:53.093 DEBUG (MainThread) [zigpy.ota.provider] Finished downloading from https://tr-zha.s3.amazonaws.com/firmwares/TRTL_ThermalSensor_PROD_OTA_V21_1.00.21.ota for ImageKey(manufacturer_id=4659, image_type=54185) ver 1.00.21
2022-12-07 21:42:53.095 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA image version: 33, size: 124946. Update needed: True
2022-12-07 21:43:07.778 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA query_next_image handler for 'Third Reality, Inc 3RTHS24BZ': field_control=FieldControl.0, manufacturer_id=4659, image_type=54185, current_file_version=21, hardware_version=None, model='3RTHS24BZ'
...
2022-12-07 21:43:42.310 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.0
2022-12-07 21:43:42.529 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.1
2022-12-07 21:43:42.780 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.1
2022-12-07 21:43:43.032 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.1
2022-12-07 21:43:43.273 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.2
2022-12-07 21:43:43.531 DEBUG (MainThread) [zigpy.zcl] [0x9253:1:0x0019] OTA upgrade progress: 0.2

@puddly Thank you for your help. Yesterday I tried many times and was able to OTA devices.

@hwzolin
Copy link
Contributor Author

hwzolin commented Dec 11, 2022

@puddly Hello, excuse me, I still have a question I would like to consult you.
What does the mean of the parameter "query_jitter" in the image_notify? What is the basis for setting this value?

Mephistofeles pushed a commit to Mephistofeles/zigbee-herdsman-converters that referenced this pull request Dec 13, 2022
…nkk#4927)

Add URL for Third Reality (3reality) OTA provider to OTA_URLs.md 

https://tr-zha.s3.amazonaws.com/firmware.json

FYI; Third Reality (3reality) OTA provider support and custom image format parser was recently added to zigpy library:

zigpy/zigpy#1096

zigpy/zigpy#1090

zigpy/zigpy#1089


Official website and Facebook group for reference:

https://www.3reality.com/

https://www.facebook.com/ThirdReality.offical/
@hwzolin
Copy link
Contributor Author

hwzolin commented Dec 21, 2022

@puddly Hello, I have the following brands of dongle around me now: nortek, conbe, nxp 5169 (zigate firmware), sonoff. I can't use SONOFF's dongle to OTA Third Reality devices. Do you know how to solve this problem?

@puddly
Copy link
Collaborator

puddly commented Dec 21, 2022

@hwzolin I've been testing using a Silicon Labs radio like the Sonoff and have had no issues. You really need to provide more context here.

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

Successfully merging this pull request may close these issues.

5 participants