Using Philips Hue with port forwarding

I am working on an Android project that uses this Philips Hue SDK.

I have implemented some functions so that I can successfully control the lights, but I am also trying to get the application to control the lights when the user is away from home.

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

The idea is that the user connects to the bridge and authenticates with the bridge at their local IP addresses. The user can then enter the external address.

I have a function that, when connected to the bridge, I check if the user is connected to Wi-Fi and they are on their own home wifi. Then I set the PHAccessPoint IP address of the local bridge of the local user bridge.

If the user is not connected to Wi-Fi or is not on home Wi-Fi, then the IP address of PHAccessPoint is updated to what the user entered, since it is an external address.

When I do this, I continue to receive either the Bridge not responding, not connected, or the bridge already connected, and this quickly happens. Despite the fact that in the error handler, if I get a bridge that is not responding or not connected, I guarantee that I will disconnect PHAccessPoint and try to reconnect.

I tried to disable the heart rate interval or increase it, and it does not matter.

If, however, I am connected to Wi-Fi, but still connect through my public IP address, this works, I get this problem only when going through mobile data.

Are there any tricks to make this work, I saw that other applications do something similar, but are not open source, so I canโ€™t understand how they implemented it.

I know that I can subscribe to the Philips Hue Remote API, which I did before Christmas, but I did not have an answer from them.

Thanks for any help you can provide.

+8
android philips-hue
source share
1 answer

After many trial and error and Android Studio, you can decompile the SDK so that I can see some of the code, which, it seems to me, is a limitation of using the official SDK.

Basically, I think the problem is that you create a PHAccessPoint object and set your external ip, for example. 86.85.84.83, when you connect to the bridge, you successfully connect and get the bridge details, and it saves the bridge configuration as a PHBridge object. This object contains the IP address of the bridged network, for example. 192.168.xx When you then do something else, the connected bridge and the PHAccessPoint object do not match, and therefore the connection error does not return, trying to process it and reconnect, since the SDK has a bridge configured as the connected SDK returns that you are already connected, and you end up getting stuck in a loop.

I think the only way to get around this is to either have a server that opens through port forwarding, and messages are sent from the server to the local bridge and then back through the server (so that the actual bridge remains local) or run your own SDK implementation using the RESTful API

+4
source share

All Articles