Koenkk / zigbee-herdsman

A Node.js Zigbee library
MIT License
456 stars 277 forks source link

Support OTA upgrades #60

Closed lorek123 closed 4 years ago

lorek123 commented 4 years ago

It was mentioned here https://github.com/Koenkk/zigbee2mqtt/issues/1865#issuecomment-522321328 that this should be at some point implmented in herdsman.

More info: https://github.com/Koenkk/zigbee2mqtt/issues/1696 https://github.com/zigpy/zigpy/pull/213

Koenkk commented 4 years ago

Would be great if somebody could help with this!

lorek123 commented 4 years ago

I can help test it with Ikea Tradfri devices

Koenkk commented 4 years ago

I think you need to add the genOta cluster similar like https://github.com/Koenkk/zigbee-herdsman/blob/master/src/adapter/z-stack/adapter/startZnp.ts#L48

Afterwards you can use https://github.com/Koenkk/zigbee-herdsman/blob/master/src/controller/model/device.ts#L208 to get the coordinator and first endpoint of it to start sending requests.

zigbee-herdsman has no replacement for zapp (which zigbee-shepherd had)

Koenkk commented 4 years ago

Change https://github.com/Koenkk/zigbee-herdsman/blob/master/src/controller/controller.ts#L424 to

if (type && data && cluster !== 'genOta') {
sjorge commented 4 years ago

Just of minor interest, ubisys allows us to request the OTA firmware once we have this working!

https://www.ubisys.de/wp-content/uploads/ubisys-s1-technical-reference.pdf

7.7.4.Over-the-Air Upgrade Cluster(Client)

The image type for S1 is 0x7B02, for S1-R it is 0x7B05. You may request the latest firmware in ZigBee OTA image format to upgrade devices in the field using your own OTA server and back-end. If you operate the power switch S1together with the ZigBee/Ethernet Gateway ubisys G1, the latest firmware for S1 and S1-R will always be available automatically and you do not need to request it explicitly.

Looks like they just post them for us! https://www.ubisys.de/en/support/firmware/

BudBundi commented 4 years ago

Ledvance/Osram Smart+ firmware can be found here: https://update.ledvance.com/firmware-overview?submit=all

Maybe this also helps https://phoscon.de/en/support#ota-update-osram-devices

jdtsmith commented 4 years ago

What's the status of your OTA branch @tb-killa? The Deconz folks have OTA working for a variety of devices.

andreasbrett commented 4 years ago

If you need a tester, just let me know.

TDCroPower commented 4 years ago

I also offer myself as a tester. I have a CC2351 stick and some ZigBee devices from Ledvance/Osram, Xiaomi, Aqara etc.

atxbyea commented 4 years ago

I too can test if needed, CC1352P-2 and Tradfri, hue, Xiaomi, gledopto here

dbruggner commented 4 years ago

Ledvance/Osram has a REST API to download firmware info and firmware files: https://portal.update.ledvance.com/docs/services/firmware-rest-api/operations/5d8e482edb442c3151c64fae

twsl commented 4 years ago

Is there any way I can help or contribute?

CodeFinder2 commented 4 years ago

Would also love to see this feature and glad to help testing (Bitron, OSRAM/Ledvance, Xiaomi/Aqara/Mija, Konke, Philips, Heimann, Ikea, ...) 🙈

twsl commented 4 years ago

@Koenkk if you'd start with the general architecture, I could implement the code for certain vendors. Got Xiaomi, OSRAM, Ikea for testing as well

Koenkk commented 4 years ago

@twsI good idea, will let you know here once its available.

svh1985 commented 4 years ago

OTA getting more important: Signify confirmed the existence of the vulnerability in their product, and issued a patched firmware version (Firmware 1935144040) which is now available on their site. We recommend users to make sure that their product received the automatic update of this firmware version.

Full article: https://blog.checkpoint.com/2020/02/05/the-dark-side-of-smart-lighting-check-point-research-shows-how-business-and-home-networks-can-be-hacked-from-a-lightbulb/

lwfitzgerald commented 4 years ago

I went looking for the OTA firmwares for Salus devices this evening and after sniffing the traffic from their iOS app, I found them!

https://eu.salusconnect.io/demo/default/status/firmware?timestamp=0.

Unfortunately, the newest firmware for the SP600 plug I've got is pretty old:

→ strings SAL2PU1_02015120_OTA.ota | grep -E '20\d\d'
SAL2PU1_02015120_OTA ota image f~`
20170220
Koenkk commented 4 years ago

First OTA update with zigbee-herdsman/zigbee2mqtt is a fact!

image

Before: "dateCode":"20170315","swBuildId":"1.3.002" After: "dateCode":"20180410","swBuildId":"1.3.009"

CodeFinder2 commented 4 years ago

Is it a good idea to collect and upload (the most recent) firmware images somewhere? Maybe even collecting (links to) them on the appropriate wiki device pages, perhaps with a hint like 'tested'? 🙈

Koenkk commented 4 years ago

There is no need for downloading stuff manually, zigbee2mqtt grabs the latest from the ikea servers.

CodeFinder2 commented 4 years ago

Uhh, that's great! ☺️👌

In general, will it be difficult to port this to other vendors like OSRAM or Xiaomi?

pedrolamas commented 4 years ago

I have a couple of Tradfri start plugs that will certainly make use of this feature!

tim-devel commented 4 years ago

Great work @Koenkk ! Can I suggest that a log messages at a lower level is added to say the end point has received an update. E.g. Warning: {friendly_name} firmware update successfully completed.

kiall commented 4 years ago

There is no need for downloading stuff manually, zigbee2mqtt grabs the latest from the ikea servers.

What about for other brands who aren't so "open" with their firmware URLs? E.g. Philips firmwares are occasionally discovered and linked to, but there's no known equivalent to IKEAs version_info.json to base the discovery off.

Koenkk commented 4 years ago

@kiall then we should make the version info ourselves

lorek123 commented 4 years ago

About the automatic updates: what will happen if we cut off the power during OTA update? If we risk bricking device then we should consider creating manual update procedure.

andreasbrett commented 4 years ago

About the automatic updates: what will happen if we cut off the power during OTA update? If we risk bricking device then we should consider creating manual update procedure.

I'd also say automatic updates should not be on by default. Users need to be able to control how and when their devices get updated. Also for automatic updates there should be some kind of time frame as devices are unavailable during the update which takes some minutes. It's the perfect situation where you might assume you're lights have crashed as they're irresponsive and then you power-toggle them to fix them. Bad decision!

sjorge commented 4 years ago

There is no need for downloading stuff manually, zigbee2mqtt grabs the latest from the ikea servers.

@Koenkk so for the manufacturer publishing something online we need to write a specific extension to take care of those right? At least from the code it looks like you added a special one for tradfri

So fallback that will try to parse a local dir with files that are manuId_devId.bin or something could work for those were we only sporadically get binaries for?

In general, will it be difficult to port this to other vendors like OSRAM or Xiaomi? Form the looks of it, not super hard if they have a nice json or other parseable index online like Tradfri does. Not sure either OSRAM or Xiaomi have those though. (At least signify (Hue) does not so that sucks)

About the automatic updates: what will happen if we cut off the power during OTA update? If we risk bricking device then we should consider creating manual update procedure.

Same risk as when the ikea gateway will do the update I think. I have at least pulled the battery on their remotes when updates were stuck... so not sure how harmful it is.

Looking at the code, I looks still very drafty so I don't think the final result will have them randomly update. There will probably be a mqtt topic to check for updates and one to do the update. If not, I'm sure they could be added without too much hassle.

Kryzek commented 4 years ago

Holy moly! No need to plug Trådfri gateway into network anymore to get latest firmwares. Huge kudos @Koenkk!

Koenkk commented 4 years ago

Implemented, let's continue here: https://github.com/Koenkk/zigbee2mqtt/issues/2921