fairecasoimeme / ZiGate

Zigate is an Universal Zigbee Gateway
http://zigate.fr
170 stars 59 forks source link

About OTA #86

Closed ISO-B closed 5 years ago

ISO-B commented 5 years ago

Should zigate be able to work as OTA server? I am using firmware 3.0e. I have been trying to get Ikea trådfri lamp to fetch ota updates from zigate. For me it seems that 0x0505 command doesn't do anything.

pipiche38 commented 5 years ago

That would be awesome. But where can we get the firmware?

Envoyé de mon iPhone

Le 28 nov. 2018 à 17:37, Vesa notifications@github.com a écrit :

Should zigate be able to work as OTA server? I am using firmware 3.0e. I have been trying to get Ikea trådfri lamp to fetch ota updates from zigate. For me it seems that 0x0505 command doesn't do anything.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Smanar commented 5 years ago

https://www.reddit.com/r/tradfri/comments/79vycn/ikea_just_updated_releasenotes_for_ikea_bridge/

It s talking about the gateway, but you can find firmware link for bulbs in a json. But 1 Years old, IDK if there is more in date link.

ISO-B commented 5 years ago

At the moment you can update Ikea stuff using deCONZ using their conbee or rasbee sticks. Their rest api repo has python script that show how to download latest ota files from Ikea. Those ota files contain some extra stuff that can be easily removed and after that you have standard ota image.

As far as I understand OTA process works two ways.

  1. Devices are quering server from time to time for new images
  2. Server can send notify image command for device(s) to force it to ask ota image

So far I havn't seen any devices quering images on their own. Also using notify image command 0x0505 doesn't make any difference. Zigate gets status success message after that command but nothing else happens. Might be that I have wrong syntax and that why lamp doesn't ask for ota image. Figured it would be easier to ask that are these commands and features even implemented on current firmware rather than banging my head against wall for many hours.

ISO-B commented 5 years ago

Just little update for this. Managed to build debug version of ZiGate firmware which makes debugging this easier. Noticed that devices actually request OTA files time to time and usually on startup. After that I had big facepalm moment when I found out that I have been using wrong OTA image. Now I am able to start updating process. Next things is to improve python library to get OTA file sent to client. I can confirm that OTA is implemented and it is working.

Would it be helpfully to get QUERY_NEXT_IMAGE_REQUEST messages passed to serial line?

pipiche38 commented 5 years ago

Excellent news ! Where do you find the OTA images ?

doudz commented 5 years ago

great news !

ISO-B commented 5 years ago

Managed to update Trådfrin 980lm E27 bulb firmware with ZiGate using python library. You can probably use TestGui to do same as well.

Excellent news ! Where do you find the OTA images ?

deCONZ have python script for downloading ota files from ikea. You can also use deCONZ to convert ikea ota files to standard ota files. Load ikea file using STD OTAU Plugin. Open it from OTAU File tab and save it and its converted to standard ota file.

KiwiHC16 commented 5 years ago

Could you share a quick doc on how to do it (direct liks to source, steps to follow,...)

ISO-B commented 5 years ago

Downloading and converting ikea ota files

  1. Download and install deCONZ from their website https://www.dresden-elektronik.de/funktechnik/products/software/pc/deconz/
  2. A) Download ikea-ota-downloader python script from https://github.com/dresden-elektronik/deconz-rest-plugin/blob/master/ikea-ota-download.py . When you run script it will download all ikea ota files to otau folder next to script.
  3. B) If you don't want/can run python script then get url from that python script and open it in browser. It will point to json file that contains firmware urls that you can download using browser.
  4. Start deCONZ.
  5. From menu select Plugins -> STD OTAU Plugin
  6. Select OTAU File tab
  7. Click open and find downloaded ota files from your computer and select desired. Click open.
  8. Now you should see firmware header details. Press save. It saves file with same.
  9. Close deCONZ

Upgrading firmware using python ZiGate library

  1. Install python library by following installation instructions
  2. Plug ZiGate to computer and start using python library
    
    import logging
    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

import zigate z = zigate.connect(port=None)



3. Pair your device to ZiGate  `z.permit_join()` command allows joining for 30sec
4. Check what is your devices address.  You can find it from debug messages or `z.devices` command
5. Load image to python and send headers to ZiGate `z.ota_load_image('path_to_ota_file')`
6. Notify your device that there is image available `z.ota_image_notify('ADDR')` replace ADDR with your device address.
7. Wait until upgrade process is done. You should get debug messages that tell what is going on.
8. Done

**Upgrading using TestGui**
1. Download and extract https://github.com/fairecasoimeme/ZiGate/releases/download/v3.0e/ZiGate.zip
2. Start TestGui from Tools/TestGui/ZGWUI
3. From menu click setting
4. Select correct port and baud rate(115200). Click Ok
5. From menu select open port
6. Select OTA Cluster tab
7. Press Load Image. Select desired ota image and open it. You might need to change file extension to .ota
8. OTA headers should be visible on boxes. Image headers are automatically sent to ZiGate.
9. Image notify row: Short, ADDRESS, 01, 01, JITTER, FFFFFFFFF, FFFF, FFFF, 64
10. Click image notify and you should see progress bar moving in bit.
11. Wait until process is done
12. Done

That's how you do it. I wrote these from memory so there might be some errors, but hopefully nothing major.
KiwiHC16 commented 5 years ago

Huge thanks, will have a look soon.

pipiche38 commented 5 years ago

@ISO-B

Downloading and converting ikea ota files

Thanks a lot for sharing

Jsl-1 commented 5 years ago

Hi,

I tried to update an ikea tradfri outlet using ota file. Step :

I get this: Something wrong with ota file header. I use python library 2.8.0 and zigate USB TTL with firmware 3.0f

Here is the debug log for command 0x0500:

DEBUG:zigate:REQUEST : 0x0500 b'\x02\x00\x00\x0b\xee\xf1\x1e\x01\x00\x008\x00\x00\x11|\x11\x01 \x01\x96#\x00\x02EBL tradfri_control_outlet \x00\x03\x19\xbe\x00\x00\x00\x00\x00\x03\x19\x80\x00\x02\x8c\xe3\x02' DEBUG:zigate:Msg to send b'05000048a70200000beef11e010000380000117c110120019623000245424c20747261646672695f636f6e74726f6c5f6f75746c6574202020202020000319be000000000003198000028ce302' DEBUG:zigate:Encoded Msg to send b'0102150210021048a7021202100210021beef11e0211021002103802100210117c11021120021196230210021245424c20747261646672695f636f6e74726f6c5f6f75746c65742020202020200210021319be0210021002100210021002131980021002128ce3021203' DEBUG:zigate:Waiting for status message for command 0x0500 DEBUG:zigate:Raw packet received, b'\x01\x80\x02\x10\x02\x10\x02\x15f\x02\x10\xd3\x02\x100\x02\x10\x03' DEBUG:zigate:Dispatch ZIGATE_PACKET_RECEIVED DEBUG:zigate:Received response 0x8000: b'00d30030' DEBUG:zigate:RESPONSE 0x8000 - Status response : status:0, sequence:211, packet_type:48, error:b'', lqi:0 DEBUG:zigate:Dispatch ZIGATE_RESPONSE_RECEIVED DEBUG:zigate:STATUS code to command 0x0030:RESPONSE 0x8000 - Status response : status:0, sequence:211, packet_type:48, error:b'', lqi:0 DEBUG:zigate:Waiting for message 0x8030 DEBUG:zigate:Raw packet received, b'\x01\x80\x02\x10\x02\x10\x02\x15\x80\x02\x10\x02\x10\x02\x15\x02\x10\x02\x10\x03' DEBUG:zigate:Dispatch ZIGATE_PACKET_RECEIVED DEBUG:zigate:Received response 0x8000: b'00000500' DEBUG:zigate:RESPONSE 0x8000 - Status response : status:0, sequence:0, packet_type:1280, error:b'', lqi:0 DEBUG:zigate:Dispatch ZIGATE_RESPONSE_RECEIVED DEBUG:zigate:STATUS code to command 0x0500:RESPONSE 0x8000 - Status response : status:0, sequence:0, packet_type:1280, error:b'', lqi:0 WARNING:zigate:Something wrong with ota file header. WARNING:zigate:Cannot read ota header. No ota file loaded.

I tried with other files from http://fw.ota.homesmart.ikea.net with same result Did I miss something ?

Thank you for your help.