bwssytems / ha-bridge

Home automation bridge that emulates a Philips Hue light system and can control other systems such as a Vera, Harmony Hub, Nest, MiLight bulbs or any other system that has an http/https/tcp/udp interface. This is a compact impl to run on small format computers. This is impl started from this project https://github.com/armzilla/amazon-echo-ha-bridge.
Apache License 2.0
1.45k stars 198 forks source link

Integrate with Ikea Trådfri Gateway as bridge to communicate and control connected Ikea's ZigBee based smart lights, switches, and sensors #570

Closed Hedda closed 5 years ago

Hedda commented 7 years ago

Ikea have just released a new app-controlled network-attached home automation hub which will serve as a Gateway to control its new "Trådfri" series of affordable smart lights / lightbulbs, switches / remotes, and sensors, which in turn so far all uses ZigBee based protocols. These products are set to be released on the 31st of March 2017 in selected countries around the world.

https://www.cnet.com/news/ikeas-rolling-out-a-brand-new-smart-home-lineup/

http://www.ikea.com/ms/sv_SE/customer-service/about-our-products/smart-lighting/index.html

"Trådfri" means 'wireless' in Swedish, and Ikea have so far announced this very aggresivly low-priced network-attached (Ethernet) "Ikea Trådfri Gateway" home automation hub in their "Tradfri" series, as well as a wireless Motion Sensor Kit (that have integrated light sensor too), a wireless Dimmer Remote (which is accelerator-based), a wireless multi-switch remote, and several smart light bulbs of different formats and even a few unique panel lights. All these products will then be released in most other contries worldwide too as Ikea steps up manufacturing (and irons our the initial software bugs I guess).

Ikea had already leaked news about this upcoming gateway/hub more than 6-months ago, during the summer or 2016, and at that time they also revealved that they will use ZigBee and keep validated access to the gateway/hub as open as possible, including providing an open API for this network-attached home automation hub.

Ikea in Sweden are first to post this news about the network-connected Home Automation Gateway / Hub, but again these products will become available worldwide. Here is link to the Swedish links:

http://www.ikea.com/se/sv/catalog/categories/departments/living_room/36812/ http://www.ikea.com/se/sv/catalog/products/40337806/ http://www.ikea.com/se/sv/catalog/products/80338960/ http://www.ikea.com/se/sv/catalog/products/80338941/ http://www.ikea.com/se/sv/catalog/products/80349888/

Link are in Swedish for Ikea Sweden site, but the PDF manuals on each page are available in English and many more languages, however they don't say much other than mounting instructions.

http://www.ikea.com/ms/en_US/img/buying_guides/fy17/april/Home_Smart_lighting_Buying_guide_APRIL1.pdf

Reason why I think that this news being interested is Ikea's aggresive pricing might them the first to make two-way communication home automation really affordable for almost everyone while still following all the electrical safety and wireless communications regulations in all countries, as they are today well known to have very low prices yet good manufacturing quality items.

UPDATE 1: Sound as Ikea Trådfri Gateway software uses the Cypress WICED IoT platform SDK (formerly Broadcom WICED IoT platform before acquired by Cypress http://www.cypress.com/internet-things-iot ) and have choosen to base their implementation on OMA (Open Mobile Alliance) and Eclipse recommended IoT protocol standards of those three logical components; CoAP (coaps) and DTLS layers of the LwM2M (Lightweight machine-to-machine) security model for IoT device management and protocol stack, using IPSO (IP for Smart Objects) Smart Object Guidelines provide a common design pattern. That is, looks as if the communication between Android/iOS app and the Gateway takes place via OMA Lightweight M2M (LwM2M) wrapped in CoAP with DTLS.

http://openmobilealliance.org/data-models-for-the-internet-of-things/

Update 2: Jaime Jiménez (from the company Ericsson) who is an active member of the IPSO Alliance’s working group and part of the team that published the IPSO Smart Object Guidelines, posted this great teardown of the Ikea Trådfri implementation:

http://jaimejim.github.io/tradfri/

For those who don’t know, LWM2M is a protocol built around CoAP and use for managing devices. So things like firmware upgrades, error reports, etc. Apart form the management interfaces, LWM2M also adds a very simple Object Model for managing those devices. IPSO expands that set of Objects so that you can have application information too (e.g. sensor readings, commands, etc). IPSO defines objects and resources that map to device properties.

Particular pay attention to the IPSO Light Control objects:

https://github.com/IPSO-Alliance/pub/blob/master/reg/xml/3311.xml

If you want to know more about the wealth of data models out there you can check the IoTSI Workshop as a reference.

https://www.iab.org/activities/workshops/iotsi/

LwM2M (Lightweight machine-to-machine) meanwhile is a system standard in the Open Mobile Alliance. It includes DTLS, CoAP, Block, Observe, SenML and Resource Directory and weaves them into a device-server interface along with an Objects structure based on IPSO Smart Object Guidelines.

https://connect2.io/open-mobile-alliance-lightweightm2m-oma-lwm2m/ https://www.eclipsecon.org/na2014/sites/default/files/slides/Eclipsecon%20NA14%20-%20One%20protocol%20to%20rule%20them%20all-%20(1).pdf http://openmobilealliance.org/constrained-application-protocol-coap-is-iots-modern-protocol/

IPSO provide common object model for interoperability of IoT Devices and Applications.

https://github.com/IPSO-Alliance/pub/blob/master/reg/README.md https://github.com/IPSO-Alliance/pub/tree/master/reg/xml https://github.com/IPSO-Alliance/pub/blob/master/reg/xml/3311.xml https://github.com/IPSO-Alliance/pub

r41d commented 7 years ago

@gobo-ws I don't see why you would need exec. Also this looks like too many quotes. For example "\"Client_identity"\" translates to the string "Client_identity" being send, while it should just be Client_identity (which you can write as "Client_identity" for the -u parameter. Same for other parameters.

gobo-ws commented 7 years ago

@r41d thanks! Do not know why I made it harder than it was... The following line works fine: coap-client -m put -u "Client_identity" -k "$1" -e '{ "3311": [{ "5850": '$2' }] }' "coaps://$3:5684/15001/$4"

csjames commented 7 years ago

Hi, My colleagues and I have tried all of the above methods, involving several builds of libcoap with dtls, as well as using golang implementations of DTLS over COAP (https://github.com/zubairhamed/canopus) but have had no luck. Have IKEA changed something, we simply cannot get a key/certificate exchange to occur, as shown by the following wireshark dump,

coap-client -m put -u "Client_identity" -k "bloop" -e '{ "3311": [{ "5850": 0 }] }' "coaps://10.0.2.117:5684/15001/65537" v:1 t:CON c:PUT i:78d5 {} [ ] ^ No further output is produced

and 2017-05-27-222755_957x350_scrot

Hedda commented 7 years ago

@csjames have you tried installing pytradfri by ggravlingen and test as a proof-of-concept?

https://github.com/ggravlingen/pytradfri

Follow the instructions in its README.md you install libcoap fork from home-assistant repo.

Matt8119 commented 7 years ago

Ikea has already said they are adding support for the echo, Google home, and homekit in a month...

Matt8119 commented 7 years ago

Homebridge

Hedda commented 7 years ago

Ikea has already said they are adding support for the echo, Google home, and homekit in a month.

@Matt8119 that does not help Ikea Trådfri Gateway emulate Philips Hue API which ha-bridge does for us.

The way ha-bridge works is it emulates Philips Hue API because which brings compatibility to many more home automations systems since most of them are already compatible with the Philips Hue API.

Samsung SmartThings => ha-bridge => Ikea Trådfri Gateway => Ikea Trådfri Lightbulbs/Lightpanels.

Vera => ha-bridge => Ikea Trådfri Gateway => Ikea Trådfri Lightbulbs/Lightpanels.

Harmony Hub => ha-bridge => Ikea Trådfri Gateway => Ikea Trådfri Lightbulbs/Lightpanels.

Once ha-bridge gets native support for Ikea Trådfri Gateway then you can use ha-bridge as bridge to other systems that does not yet have native support for Ikea Trådfri Gateway, such as Samsung SmartThings, Vera, Harmony Hub, and many more that already supports Ikea Trådfri Gateway.

csjames commented 7 years ago

Yeah so I have tried the pytradfri aswell, and just get a request timeout unfortunately python3 -i -m pytradfri 10.0.1.5 bloop

DEBUG:pytradfri.coap_cli:Executing 10.0.1.5 get ['status'] Traceback (most recent call last): File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/usr/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/james/libcoap/pytradfri/pytradfri/main.py", line 18, in api = api_factory(sys.argv[1], sys.argv[2]) File "/home/james/libcoap/pytradfri/pytradfri/coap_cli.py", line 104, in api_factory request('get', ['status']) File "/home/james/libcoap/pytradfri/pytradfri/coap_cli.py", line 58, in request raise RequestTimeout() from None pytradfri.error.RequestTimeout

gabrielsson commented 7 years ago

@csjames Me and a collegue had a similar problem. Turned out that the key printed in text was wrong, turned out that the QR code had an "o" instead of a "c", might have been scraped off but it was not easy to detect. Scan the QR code with a cell phone just to be sure.

csjames commented 7 years ago

Last night we reset our Tradfri hardware by holding the reset button down and then resetting all settings within the application.

This lead to the coap working fine, then, after about 10 minutes the base station proceeded to update and the coap interface became unresponse (5 second delays) for both the apps and coap-client. Following the update, performance returned to normal and everything is working smoothly.

Thanks for all your help! :)

r41d commented 7 years ago

Just added support for Moods in the MQTT bridge https://github.com/r41d/TRADFRI2MQTT/commit/eb90ef40f6a69b09ab05e080e6462d5435462686 Does anyone know if there is a DTLS-capable Python Library/binding yet? All I've seen yet is this ugly calling of coap-client via subprocesses, this kinda keeps me from using anything else than Java atm :/

ticatagdev commented 7 years ago

I need a libcoap implementation with DTLS support for iOS. It seems nothing is available... any idea ?

hanpal commented 7 years ago

Anyone aware of a polling command to update the reachable property? I want to know if a bulb is reachable. The problem is that it seems like this property is not updated until something is commanded without success. If I disconnect a bulb, the property is not updated in the gateway (according to pytradfri), also not when I check the status from the app. But if I try to command something it is updated after some time. For the cheaper lamp with fixed colour temperature I can send a command to change colour temperature as a "NOP" command, reachable is then updated. Don't know what to send to the other bulbs though, unless I save the commanded values and send them a again. Is there no "poll" command? Why doesn't the gateway poll the bulbs at a regular interval?

szokeptr commented 7 years ago

@hanpal Maybe you could try sending a command with invalid payload (out of range color XY values for example). In theory that would work the same like the color setting request on bulbs that don’t support it.

On 12 Jul 2017, at 10:27, hanpal notifications@github.com wrote:

Anyone aware of a polling command to update the reachable property? I want to know if a bulb is reachable. The problem is that it seems like this property is not updated until something is commanded without success. If I disconnect a bulb, the property is not updated in the gateway (according to pytradfri), also not when I check the status from the app. But if I try to command something it is updated after some time. For the cheaper lamp with fixed colour temperature I can send a command to change colour temperature as a "NOP" command, reachable is then updated. Don't know what to send to the other bulbs though, unless I save the commanded values and send them a again. Is there no "poll" command? Why doesn't the gateway poll the bulbs at a regular interval?

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

hanpal commented 7 years ago

Nice idea but didn't work. Invalid values stopped by gateway or pytradfri. Had no effect.

kloknibor commented 7 years ago

After reading this thread it seems like we now know which commands we need to send but there is still no ha-bridge support. Is this correct?

If so is anybody working on the tradfri integration with ha-bridge or ha-bridge to homebridge automation?

Last question. With ha-bridge is it possible to use the philips hue app and control your light from abroad?

Thanks!

FloFoer commented 7 years ago

I think this project needs more active developers other than bwssystems. One man can't do anything alone.

To your last Question regarding "control from abroad": No, because that would require to link ha-bridge with a hue account which i believe is not possible. You can use the hue app with ha-bridge, but only locally.

emigrating commented 7 years ago

To your last Question regarding "control from abroad": No, because that would require to link ha-bridge with a hue account which i believe is not possible. You can use the hue app with ha-bridge, but only locally.

To be fair, any person with enough knowhow to get ha-bridge running and working correctly is likely also able to configure a VPN server on their home router, in which case yes, yes you can control your lights remotely. (Though, I personally dont see the point in doing so, as we are all trying to build smart homes, the home should control the lights itself based on a variety of factors - having to remember to turn the lights on, off or dim to a specific setting while you're sitting on the playa with an umbrella drink isn't really a viable solution to this)

Oh, and IKEA has recently said (few days ago) their bulbs will be fully ZLL compatible as of the next firmware update so then you can mix and match Hue and Tradfri bulbs, hubs and actuators as needed.

matemaciek commented 7 years ago

I've added support for changing colour temperature in whole spectrum between 2200K and 4000K: https://github.com/ggravlingen/pytradfri/pull/48/files

Next step: add it in home assistant.

emigrating commented 7 years ago

@kloknibor Can't you just use the pytradfri solution?

r41d commented 7 years ago

Apparently E27 RGB bulbs are now available, today I bought one in an IKEA in Germany. I didn't find anything online, so these gotta be released brand-new. Here are some photos and screenshots: http://imgur.com/a/yC5VW The Android App is able to display the colors that the bulb shows, but it's not able to set them. Setting RGB color only work ATM by repeatedly pressing the < and > buttons on the Tradfri remote. Will try to do further investigation soon.

matemaciek commented 7 years ago

As soon as I get RGB bulb I'll be able to add support to pytradfri. @r41d , do you have IKEA product number (8 digits)? I'll check when they'll be available in Poland.

emigrating commented 7 years ago

@r41d, what was the price of the RGB bulb compared to the 980lm white ones?

davetaz commented 7 years ago

I've been having issues with my gateway and now cannot connect to it using coap-client. It was running firmware 1.1.0012 (i think) when i could connect but this lost connection to all the bulbs, which made it useless. I reset it and now it is running fireware version 1.0.008 according to the app. Bulbs are all connected however coap-client won't. Clicking check for updates says there are no updates. Any one had similar issues and know how to force it to update to 1.1.0015 from http://fw.ota.homesmart.ikea.net/feed/version_info.json?

r41d commented 7 years ago

@matemaciek: on the back of the box it says 703.389.51 @emigrating: It cost 35€ for an RGB bulb with a remote (10€ more than a regular white spectrum bulb with remote) Sadly it wasn't possible to buy one without a remote... but I just had to get one ^^ @davetaz: also recently got problems with the coap-client connection to my gateway, damn, maybe they changed something.

davetaz commented 7 years ago

@r41d I'm fairly confident my gateway has an issue at the moment as it won't upgrade. Will keep you posted.

matemaciek commented 7 years ago

If anyone wants to try most recent pytradfri with home-assistant, here it is https://github.com/home-assistant/home-assistant/compare/dev...matemaciek:dev

It includes full white spectrum support, so you can use flux now (-:

pere5 commented 7 years ago

I made an attempt to document the Lwm2m+IKEA JSON format that TRÅDFRI communicates with. It is derived from these sources:

And by querying my own Trådfri system with my own python script. The format of the JSON structure below is my own invention so hopefully you can make sense of it...

  "15001": {
    "name": "DEVICES",
    "description": "Device ids for lights and remotes.",
    "example": [
      65536,
      65537,
      65538
    ],
    "15001/reset": {

    },
    "15001/{DeviceId}": [
      {
        "9019": {
          "name": "REACHABILITY_STATE",
          "example": 1
        },
        "3": {
          "name": "DEVICE_INFO",
          "example": {
            "1": "TRADFRI bulb E27 CWS opal 600lm",
            "0": "IKEA of Sweden",
            "3": "1.3.002",
            "2": "",
            "6": 1
          }
        },
        "5750": {
          "name": "APPLICATION_TYPE",
          "example": 2
        },
        "9003": {
          "name": "INSTANCE_ID",
          "example": 65538
        },
        "9002": {
          "name": "CREATED_AT",
          "example": 1504616889
        },
        "9001": {
          "name": "NAME",
          "example": "Badass bulb"
        },
        "3311": {
          "name": "LIGHT_CONTROL",
          "example": [
            {
              "5708": 0,
              "5709": {
                "name": "LIGHT_COLOR_X",
                "example": 30140
              },
              "5710": {
                "name": "LIGHT_COLOR_Y",
                "example": 26909
              },
              "5706": {
                "name": "LIGHT_COLOR",
                "example": "f1e0b5"
              },
              "5707": 0,
              "5711": 0,
              "5712": {
                "name": "TRANSITION_TIME",
                "description": "Specified in seconds/10.",
                "example": 100
              },
              "5850": {
                "name": "ON/OFF",
                "example": 1
              },
              "5851": {
                "name": "LIGHT_DIMMER",
                "example": 160
              },
              "9003": {
                "name": "INSTANCE_ID",
                "example": 0
              }
            }
          ]
        },
        "9054": {
          "name": "OTA_UPDATE_STATE",
          "example": 0
        },
        "9020": {
          "name": "LAST_SEEN",
          "example": 1504769379
        }
      },
      {
        "9019": {
          "name": "REACHABILITY_STATE",
          "example": 1
        },
        "3": {
          "name": "DEVICE_INFO",
          "example": {
            "1": "TRADFRI remote control",
            "0": "IKEA of Sweden",
            "3": "1.2.214",
            "2": "",
            "6": 3,
            "9": 87
          }
        },
        "5750": {
          "name": "APPLICATION_TYPE",
          "example": 0
        },
        "9003": {
          "name": "INSTANCE_ID",
          "example": 65536
        },
        "9002": {
          "name": "CREATED_AT",
          "example": 1504610844
        },
        "9001": {
          "name": "NAME",
          "example": "TRADFRI remote control"
        },
        "9054": {
          "name": "OTA_UPDATE_STATE",
          "example": 0
        },
        "9020": {
          "name": "LAST_SEEN",
          "example": 1504706016
        },
        "15009": {
          "name": "SWITCH",
          "description": "No references to this anywhere",
          "example": [{
            "9003": {
              "name": "INSTANCE_ID",
              "example": 0
            }
          }]
        }
      }
    ]
  },
  "15004": {
    "name": "GROUPS",
    "description": "Groups of devices.",
    "example": [
      154580
    ],
    "15004/add": {

    },
    "15004/remove": {

    },
    "15004/{GroupId}": {
      "5850": {
        "name": "ON/OFF",
        "example": 1
      },
      "9002": {
        "name": "CREATED_AT",
        "example": 1504610855
      },
      "9001": {
        "name": "NAME",
        "example": "My phat group name"
      },
      "9003": {
        "name": "INSTANCE_ID",
        "example": 154580
      },
      "9039": {
        "name": "SCENE_ID",
        "example": 205512
      },
      "9018": {
        "name": "HS_ACCESSORY_LINK",
        "example": {
          "15002": {
            "name": "HS_LINK",
            "example": {
              "9003": {
                "name": "INSTANCE_ID",
                "description": "DeviceIds reached by: 15001/DeviceId",
                "example": [
                  65536,
                  65537,
                  65538
                ]
              }
            }
          }
        }
      },
      "5851": {
        "name": "LIGHT_DIMMER",
        "example": 0
      }
    }
  },
  "15005": {
    "name": "SCENES_TOP",
    "description": "Some kind of top scene structure",
    "example": [
      154580
    ],
    "15005/{SceneTopId}": {
      "name": "SCENES",
      "description": "List of all scenes",
      "example": [
        217404,
        228154,
        203200,
        205512
      ],
      "15005/{SceneTopId}/{SceneId}": {
        "9068": {
          "name": "IKEA_MOODS",
          "example": 1
        },
        "15013": {
          "name": "LIGHT_SETTING",
          "description": "Interesting that two LIGHT_CONTROL's are specified here.",
          "example": [
            {
              "5708": 0,
              "5709": {
                "name": "LIGHT_COLOR_X",
                "example": 30140
              },
              "5710": {
                "name": "LIGHT_COLOR_Y",
                "example": 26909
              },
              "5706": {
                "name": "LIGHT_COLOR",
                "example": "f1e0b5"
              },
              "5707": 0,
              "5711": 0,
              "5850": {
                "name": "ON/OFF",
                "example": 1
              },
              "5851": {
                "name": "LIGHT_DIMMER",
                "example": 203
              },
              "9003": {
                "name": "INSTANCE_ID",
                "example": 65537
              }
            },
            {
              "5708": 0,
              "5709": {
                "name": "LIGHT_COLOR_X",
                "example": 30140
              },
              "5710": {
                "name": "LIGHT_COLOR_Y",
                "example": 26909
              },
              "5706": {
                "name": "LIGHT_COLOR",
                "example": "f1e0b5"
              },
              "5707": 0,
              "5711": 0,
              "5850": {
                "name": "ON/OFF",
                "example": 1
              },
              "5851": {
                "name": "LIGHT_DIMMER",
                "example": 203
              },
              "9003": {
                "name": "INSTANCE_ID",
                "example": 65538
              }
            }
          ]
        },
        "9003": {
          "name": "INSTANCE_ID",
          "example": 217404
        },
        "9002": {
          "name": "CREATED_AT",
          "example": 1504610855
        },
        "9001": {
          "name": "NAME",
          "example": "EVERYDAY"
        },
        "9057": {
          "name": "SCENE_INDEX",
          "example": 0
        }
      }
    }
  },
  "15006": {
    "name": "",
    "example": [{
      "9014": {
        "name": "NOTIFICATION_STATE",
        "example": 0
      },
      "9015": {
        "name": "NOTIFICATION_EVENT",
        "example": 5001
      },
      "9002": {
        "name": "CREATED_AT",
        "example": 1504794867
      }
    }]
  },
  "15010": {
    "name": "SMART_TASKS",
    "example": []
  },
  "15011": {
    "name": "GATEWAY",
    "description": "Operations on the gateway",
    "15011/15012": {
      "name": "GATEWAY_DETAILS"
    },
    "15011/9034": {
      "name": "UPDATE_FIRMWARE"
    },
    "15011/9030": {
      "name": "REBOOT"
    },
    "15011/9031": {
      "name": "RESET"
    },
    "15011/9063": {
      "name": "AUTH_PATH"
    },
    "15011/9033": {
      "name": "SESSION_ID"
    }
  },
  "status": {
    "name": "",
    "example": {}
  }
}
davetaz commented 7 years ago

@r41d managed to get my gateway working. It would seem that the gateway might hold two firmware images and each time you reset the gateway it boots either the factory default or the latest one it has. So I had my gateway running 1.1.0015 but it was corrupt, so I reset and the gateway booted 1.0.008 and it remembered the devices. Although the gateway was running 1.0.0008 the updates screen said the gateway was up to date. This is because it was, I just wasn't running that image. I then reset it again and the gateway booted a working 1.1.0015 and forgot all my devices. After re-adding them everything is now fine and homebridge and coap is all happy.

r41d commented 7 years ago

Seemingly, IKEA released the first update to the Tradfri Android App. One can now choose some colors when tapping on a bulb and then on the three dots: https://imgur.com/a/0A7iq These are many more than those colors which one can cycle through by using the physical remote

matemaciek commented 7 years ago

I'm gonna get my RGB bulb finally today, I know that they're in my IKEA (-:

Hydro8 commented 7 years ago

Someone know how to change color for an entire group ? I tried to change the mood but I didn't want to change my dimmer level.

pere5 commented 7 years ago

@Hydro8 I'm also interested in how to change for an entire group

UserXYZ commented 7 years ago

Hello guys, just wanna post my experience with development version of libcoap and some issues I have with it. If you git clone libcoap and then checkout devel branch, you get v4.2.0alpha which is way forward of the latest stable in master (4.1.2) with a bunch of bug fixes etc. Since I'm developing my own Tradfri coap-mqtt bridge in python2, I use coap-client extensively (no support for python yet and py3 version is incomplete) in polling mode, and I've noticed that it has more extensive output on stdout than before. One line more, to be precise, where it writes additional info about data type it handles, so take care of that in your parsing programs.

But, one more thing that still fails, like in old version, is subscription, or observe. It appears that you get Observe:0 option when using -s switch to coap-client which should emulate the usual mqtt subscribe method. Now, in coap-client it works for some time, but after some undetermined time it breaks and the client unsubscribes itself - or the server (Tradfri hub, in my case) kicks it out. Playing with -s timeout doesn't really change anything, and I don't even understand what is exactly that timeout for.

So, my question - did somebody manage to effectively subscribe to an endpoint (topic) on coap server without this disconnecting behaviour? If the problem is in coap-client, does anybody have and other cli coap client that actually works with tradfri? I can't compile LibNyoci on multiple platforms, and FreeCOAP has no usable client and no DTLS, so...bummer.

lwis commented 7 years ago

@UserXYZ I believe it's an issue with libcoap, as we don't experience the issue with aiocoap over at ggravlingen/pytradfri

UserXYZ commented 7 years ago

Well, I guess then that the developer of libcoap made a bug that needs to be fixed, or he chose such behavior of coap-client deliberately, since that is supposed to be a test tool...

What surprises me is that no other contributor decided to fix it, or at least make subscribe parameter with value of zero work as normal Observe:0 option, which would actually be a regular no-timeout subscription.

Since I can't use Python 3 (still being under much of development etc), aiocoap is not a solution atm...

So, anybody knows of another software that can be used instead of libcoap? Should be written in C/C++ (simplest to build), have dtls using tinydtls (gnutls is pain to include and I'm not sure if it works with keys besides certs) and pretty much everything else that libcoap has...? Like a better version of libcoap...

obgm commented 7 years ago

@UserXYZ You are always welcome to open issues on the libcoap bugtracker or discuss these on the libcoap mailing list. It is difficult to fix your issues if nobody knows about them.

You can adapt the amount of output produced by coap-client on stdout with the option '-v'.

Regarding the timeout: '-B' controls the time until coap-client terminates. By default, this is 90 seconds as documented in the manual page. The option -s controls the timeout until coap-client cancels the established observe relationship.

Regarding your question about alternatives to libcoap: There is Californium which has DTLS support, and AFAIK, there is a version of node-coap with DTLS support.

rodders99 commented 7 years ago

I came a cross a similar problem : Getting something not supported by ha-bridge working with ha-bridge. (Denon Amplifier, Samsung TV, 433Mhz based HA kit and more.

Rather than delving into ha-bridge's code, I ended up writing my own php broker and ha-bridge just flings the http command at it and the broker sorts out the rest.

Alexa / Google => ha-bridge => My Broker => Insert Weird Gateway => Weird Kit here.

It appears from the above a similar approach is being attempted by some of you. The work carried out by Adreas Spiess may help : https://www.youtube.com/watch?v=wS8Vj0ba4ic.

skatsikeas commented 6 years ago

@davetaz I have exactly the same problem, my gateway is stuck on 1.0.0008 and says there are no updates. I tried reseting with the hole button but it stays in the same version. How did you make it to boot to the other image?

davetaz commented 6 years ago

Here are some of the things I did.

1) Keep trying the reset 2) Each time you do, also reinstall the app on your phone 3) Take the gateway back to IKEA (which is what I did in the end)

UserXYZ commented 6 years ago

@lwis can you tell me how do you use aiocoap with ggravlingen/pytradfri code? In asynchronous mode, I suppose, because in synchronous mode it is just calling coap-client in the background (saw that in my process list) which kinda defeats the purpose of aiocoap...

lwis commented 6 years ago

@UserXYZ guts are all here buddy.

UserXYZ commented 6 years ago

@lwis Well, that didn't quite answer my question, but based on your link, I'd say async mode... So, no problems with observation of resource, you can track it's state for as long as you like? No need to poll, or at least disconnect and reconnect at some time to give the hub a chance to clean connections or something?

lwis commented 6 years ago

@UserXYZ Oh, you mean observation? Yes, coap-client has issues with observation, but aiocoap does not. You can observe until the connection is stopped at either end.

UserXYZ commented 6 years ago

@lwis Sweet, that's what I need...now just to figure out aiocoap's API to reimplement my code or switch totally to pytradfri as a base...oh, and learn Python3 alongside Python2...such fun...

lwis commented 6 years ago

@UserXYZ obviously I'd recommend using pytradfri 😉

UserXYZ commented 6 years ago

@lwis Weeell, that would be easier way to do it, for sure, but again it's also adding another layer. my code->pytradfri->aiocoap and I could do my code->aiocoap but with more effort on my part... Meh, I'll try with pytradfri first and then see if I get the hang of aiocoap's API, make another branch/version then.

leifnel commented 6 years ago

I found my GW, but it is not open on port 5684

The gateway is running version 1.2.42, claiming to be hue-compatible.

I'm currently scanning all ports; none seem to be open.

greluc commented 6 years ago

With 1.2.42 IKEA changed the authentication. See the following link: https://community.openhab.org/t/ikea-tradfri-gateway/26135/148?u=kai

leifnel commented 6 years ago

Where do you find the coap-client?

I got the one from libcoap-1-0-bin in debian. It does not have the -u option.

`

root@mini:# coap-client -m post -u "Client_identity" -k "qwertyuiopå" -e '{"9090":"nodered"}' \
"coaps://192.168.1.86:5684/15011/9063" 

coap-client: invalid option -- 'u'
coap-client v4.1.2 -- a small CoAP implementation
   (c) 2010-2015 Olaf Bergmann <bergmann@tzi.org>

usage: coap-client [-A type...] [-t type] [-b [num,]size] [-B seconds] [-e text]
            [-m method] [-N] [-o file] [-P addr[:port]] [-p port]
            [-s duration] [-O num,text] [-T string] [-v num] [-a addr] [-U] URI

`

I'm trying to access the hub from node-red, and it will not authenticate. node-red-contrib-tradfri 1.1.0

Registration did not work. Verify your settings and possibly try another identity. Note that an identity can only be used once and the response preshared key must be stored for usage with the identity