如何远程连接后端服务与飞利浦 Hue Bridge? [英] How to connect backend service with philips hue bridge remotely?

查看:37
本文介绍了如何远程连接后端服务与飞利浦 Hue Bridge?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望编写一个飞利浦 Hue 服务,该服务需要允许用户在我的服务中注册他们的 Hue 桥接器.此服务将根据事件更改灯泡的颜色.我知道我可以使用 IFTTT,但在这种情况下,我不想使用 IFTTT,我想使用飞利浦 Hue 的应用程序注册我的网站.

知道我该怎么做吗?非常感激你的帮助.谢谢!

不知道为什么我被否决了,但我确实做了我的研究.我查看了 philips Hue 的开发人员网站,但在他们的 API 上找不到任何明确的内容.我还查看了 iOS SDK,没有看到任何会触发远程设备配对例程的方法.到目前为止,我有这个工作的唯一例子(飞利浦的产品之外是 IFTTT 服务,它允许将条目添加到我的应用程序"部分).

解决方案

TLDR:我写了一个 API:https://github.com/jarvisinc/PhilipsHueRemoteAPI

我在我的技术博客(http://blog.paulshi.me/technical/2013/11/27/Philips-Hue-Remote-API-Explained.html),我将在这里发布:

问题实际上分为两部分:

  • 身份验证
  • 远程控制

身份验证

我还没有找到自动进行身份验证的可靠方法.以下程序需要自动化: 其想法是伪装成官方 iOS APP,启用后可以远程控制.我们需要获得 BRIDGEIDACCESSTOKEN 才能通过远程控制的认证步骤.

  1. https://www.meethue.com/api/nupnp 中查找您的 BRIDGEID.(或在 meethue 网站上的我的桥页面,然后点击显示更多")

  2. 获取ACCESSTOKEN

    www.meethue.com/en-US/api/gettoken?devicename=iPhone+5&appid=hueapp&deviceid=**BRIDGEID**

  3. 右键点击BACK TO THE APP"并在重定向到的链接内写下ACCESSTOKEN

    phhueapp://sdk/login/**ACCESSTOKEN**

基本上,获取访问令牌是一种黑客行为.你将你的应用程序伪装成官方的 iOS Hue 应用程序,并以这种方式请求访问令牌.我不确定有没有更简单的方法,如果你知道,请在下面发表评论.

您可以通过进行模拟登录会话并通过抓取页面内容来获取 ACCESSTOKEN 来潜在地自动化它.但我认为它非常不可靠,因为对官方页面的任何更改都可能会破坏它.

我写了这个脚本,它允许自动获取ACCESSTOKEN 截至今天,但我不保证它明天会起作用,原因我在上面解释过:P

目前,此 OAUTH 流程仅适用于官方应用.他们可能会向其他 3rd 方应用打开它.

远程控制

认证完成后,这部分可以自动完成.有 2 个已知的私有端点用于发送控制命令和获取与 Hue 桥接器相关的所有状态.

  • 发送命令端点:

    POST https://www.meethue.com/api/sendmessage

  • 获取状态端点:

    GET https://www.meethue.com/api/getbridge

发送命令端点

  • 网址:https://www.meethue.com/api/sendmessage

  • 方法:POST

  • 网址参数:

    token=**ACCESSTOKEN**(您之前获得的)

  • 请求头

    content-type=application/x-www-form-urlencoded

  • 身体

    clipmessage={ bridgeId: "**BRIDGEID**", clipCommand: { url: "/api/0/**APIENDPOINT**", method: "**METHOD**", body: **JSONCOMMAND** } }

    • BRIDGEID 与您之前获得的相同
    • APIENDPOINT 与官方 API /api//*** 相同,删除 /api//> 部分
    • METHOD PUT/GET/POST/DELETE 与官方 API 相同的 4 种方法.尽管 GET 确实不起作用,因为来自发送命令端点的所有响应都是 200,在下面的部分中进行了解释,而 DELETE 没有经过测试
    • JSONCOMMAND 实际的命令体,例如 {"on":true}

获取状态端点

  • 网址:https://www.meethue.com/api/getbridge

  • 方法:GET

  • 网址参数:

    token=**ACCESSTOKEN**bridgeid=**BRIDGEID**

  • 请求头

    content-type=application/x-www-form-urlencoded

限制

目前的限制是您无法像官方 API 那样立即从响应中知道您的控制命令是否成功.如果您的操作正确,您从调用发送命令端点获得的所有响应几乎总是 <200>.但您始终可以从获取状态端点"中提取与 Hue 桥接器相关的所有状态.

远程控制 API

我写了Philips HUE Remote API专门解决遥控问题.

享受:)

有关完整文档,请参阅这篇优秀论文:

黑客灯泡:飞利浦 Hue 个人无线照明系统的安全评估来自 Nitesh Dhanjani

I'm looking to write a philips hue service that needs to allow users to register their hue bridge with my service. This service would change the color of bulbs based on an event. I'm aware that I can use IFTTT but in this scenario, I'd like to not use IFTTT and I'd like to register my website with philips hue's apps.

Any idea how I can do this? Your help is very much appreciated. Thanks!

EDIT: Not sure why I was down voted but I definitely did do my research. I looked on philips hue's developer website and couldn't find anything that was explicit on their APIs. I also looked through the iOS SDK and didn't see any methods that would trigger the pairing routine for remote devices. So far, the only example I have of this working (outside of Philips' products is the IFTTT service, which allows for an entry to be added into the 'My Apps' section).

解决方案

TLDR: I wrote an API: https://github.com/jarvisinc/PhilipsHueRemoteAPI

I answered this question on my technical blog (http://blog.paulshi.me/technical/2013/11/27/Philips-Hue-Remote-API-Explained.html), which I will post here:

The question actually comes as two part:

  • Authentication
  • Remote Control

Authentication

I haven't figure out a reliable way to do authentication automatically. The following procedures needs to be automated: The idea is to fake as official iOS APP which has the ability to control remotely when enabled. We will need to get BRIDGEID and ACCESSTOKEN to pass the authentication step for remote control.

  1. Find your BRIDGEID from https://www.meethue.com/api/nupnp. (or in My bridge page on the meethue website and by clicking on "Show me more")

  2. Get ACCESSTOKEN

    www.meethue.com/en-US/api/gettoken?devicename=iPhone+5&appid=hueapp&deviceid=**BRIDGEID**
    

  3. Right click on "BACK TO THE APP" and write down ACCESSTOKEN inside the link it redirect to

    phhueapp://sdk/login/**ACCESSTOKEN**
    

Basically it is a hack to get your access token. You fake your app as the official iOS Hue App, and ask for access token that way. I am not sure there is an easier way out there, if you do know one, please do comment below.

You can potentially automate it by doing simulated log-in session and grab the the ACCESSTOKEN by scraping the page content. But I consider it highly unreliable because any change to the official page will likely break it.

I wrote this script that allows the automation of getting ACCESSTOKEN as of today, but I don't guarantee it will work tomorrow for the reason I explained above :P

Currently, this OAUTH process only works with official apps. There might be a slight chance that they will open it to other 3rd party apps.

Remote Control

Once authentication is done, this part can be done automatically. There are 2 known private endpoints for sending control command and getting all the status related to the hue bridge.

  • Sending Command Endpoint:

    POST https://www.meethue.com/api/sendmessage
    

  • Getting Status Endpoint:

    GET https://www.meethue.com/api/getbridge
    

Sending Command Endpoint

  • URL: https://www.meethue.com/api/sendmessage

  • Method: POST

  • URL Parameters:

    token=**ACCESSTOKEN** (which you obtained earlier)
    

  • Request header

    content-type=application/x-www-form-urlencoded
    

  • body

    clipmessage={ bridgeId: "**BRIDGEID**", clipCommand: { url: "/api/0/**APIENDPOINT**", method: "**METHOD**", body: **JSONCOMMAND** } }
    

    • BRIDGEID is the same one you obtained earlier
    • APIENDPOINT the same as official API /api/<username>/*** by removing /api/<usename>/ part
    • METHOD PUT/GET/POST/DELETE the same 4 method as official API. Despite GET really doesn't work since all response from the Sending Command Endpoint is 200 explained in the following part, while DELETE is not tested
    • JSONCOMMAND The actual command body for example {"on":true}

Getting Status Endpoint

  • URL: https://www.meethue.com/api/getbridge

  • Method: GET

  • URL Parameters:

    token=**ACCESSTOKEN**
    bridgeid=**BRIDGEID**
    

  • Request header

    content-type=application/x-www-form-urlencoded
    

Limitations

Current limitation is you cannot immediately know from the response whether your control command succeeded like the official API. All the response you get from calling the Sending Command Endpoint is pretty much always <200> if you are doing it correctly. But you can always pull all the status related to the Hue bridge from the Getting Status Endpoint.

Remote Control API

I wrote Philips HUE Remote API to specifically solve the remote control problem.

Enjoy :)

Paper

For full documentation please refer to this excellent paper:

Hacking Lightbulbs: Security Evaluation of the Philips Hue Personal Wireless Lighting System by Nitesh Dhanjani

这篇关于如何远程连接后端服务与飞利浦 Hue Bridge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆