Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Philips Hue with Port Forwarding

I am working on Android project that utilises that Philips Hue SDK.

I've implemented some of the functionality so that I can successfully control the lights but I am also trying to make the app control the lights when the user is away from home.

I have set up port forwarding so that I can connect to my public IP address through port 80 and it forwards it to the bridge.

The idea is that the user connects to the bridge and authenticates with the bridge on its local ip addresss. The user is then able to enter what the external address is.

I have a function that when connecting to the bridge, I check to see if the user connected Wifi and are they on their own home wifi I then set the IP address of the PHAccessPoint of the users local bridge bridge address.

If the user is not on wifi, or they are but on the home wifi, then the PHAccessPoint IP address is updated to what the user entered as they're external address.

When I do this, I keep getting either Bridge not responding, not connected or bridge already connected and this keeps happening rapidly. Even though in the error handler, if I get bridge not responding or not connected, I ensure I disconnect the PHAccessPoint and attempt to re-connect again.

I've tried disabling the Heartbeat Interval or increasing it and it makes no difference.

If however I am on the wifi but still connect via my public IP address it works, I only get this problem if going through mobile data.

Are there any tricks to make this work I've seen other apps do something similar but its not open source so can't see how they've implemented it.

I have signed up to Philips Hue Remote API, but I've had no response from them.

like image 468
Boardy Avatar asked Apr 22 '16 17:04

Boardy


People also ask

What port does Philips Hue use?

The Hue bridge cannot change the port it is listening on (ie. port 80) unfortunately.

Can I connect Hue Bridge to Ethernet port?

The Hue Bridge connects to any available Ethernet port on your wireless router using an Ethernet cable. Plug the provided Ethernet cable into the Bridge and the opposite end into an open Ethernet slot on your router. Once the four lights on the Bridge light up, it is ready to set up.

What protocol does Philips Hue use?

Supported Things The Hue bridge is required as a "bridge" for accessing any other Hue device. It supports the ZigBee LightLink protocol as well as the upwards compatible ZigBee 3.0 protocol. There are two types of Hue bridges, generally referred to as v1 (the rounded version) and v2 (the squared version).

Does Philips Hue use ZigBee IP?

The Philips Hue bridge uses the Zigbee Light Link standard, which makes it, according to Philips, compatible to all such light bulbs and devices.


1 Answers

After lots of trial and error and Android Studio being able to decompile the SDK so I can see some of the code I think its a limitation of how the official SDK is implemented.

Basically I think the problem is that you create a PHAccessPoint object and set your external ip e.g. 86.85.84.83, when you connect to the bridge, you successfully connect and get the bridge details, and it stores the bridge configuration as a PHBridge object. This object contains the bridge's local network IP e.g. 192.168.x.x. When you then come to do anything else the connected bridge object and the PHAccessPoint object don't match and therefore a no connection error is returned, upon trying to handle that and re-connect, because the SDK has a bridge set up as connected the SDK returns that you are already connected and you end up getting stuck in a loop.

I think the only way around this would be to either have a server that is exposed via port forwarding and the messages are passed on from the server to the local bridge and then back out though the server (so the actual bridge stays local) or to roll your own implementation of the SDK using the RESTful API

like image 122
Boardy Avatar answered Oct 05 '22 22:10

Boardy