PhilipsHue / PhilipsHueSDK-Java-MultiPlatform-Android

The Software Development Kit for Philips Hue Java Mulfi-Platform and Android (beta)
273 stars 214 forks source link

Offline bridge? #20

Closed yeutterg closed 9 years ago

yeutterg commented 9 years ago

Hi all,

I've encountered an installation that requires the Hue bridges to be on their own network with my app/device that is not connected to the internet. Using the Hue smartphone app, the bridge is found on the local network and I can control lights, I can use the Hue Tap switch, etc., but in my Java app, I get a "Bridge Not Found" error when trying to find the bridge(s).

This is using the UPNP/Portal search method (sm.search(true, true)), then catching the error, then resorting to the IP Search method (sm.search(false, false, true)), just like in the quickstart app. All search methods fail.

I can see the hue bridge IP as connected in my DD-WRT router settings page, use the clip debugger, etc. The router has its own DHCP server and local DNS server set up. I've tried a number of router configurations but haven't been able to get it to respond.

So, theoretically, is it possible to connect an SDK app to the bridge when it is offline, as you can do with the official Hue smartphone app? Any suggestions on what I can do to mitigate this problem?

Thanks a lot, Greg

SteveyO commented 9 years ago

Hi Greg,

Yes, the Java SDK can find an offline Hue Bridge, just using the Upnp search. i.e. The below should work.

PHBridgeSearchManager sm = (PHBridgeSearchManager) phHueSDK.getSDKService(PHHueSDK.SEARCH_BRIDGE); sm.search(true, false);

I have tried this on many a bridge and never seen a problem (+ also at hackathons were we sometimes dont have an internet connection). The found bridges should be returned on the onAccessPointsFound method in your PHSDKListener. If you are on the same network as your bridge and are not seeing anything here, am not sure what the problem could be to be honest. I will ask some of my colleagues and see if they have any ideas.

Steve

yeutterg commented 9 years ago

Hi Steve,

Thanks for the suggestions. I tried switching to just the upnp search, but it still failed. However, I think I stumbled upon the solution:

I was testing my software on 3 routers, all TP-Link TL-WR841N v9.2 N models with recent versions of the DD-WRT firmware installed. It turns out that I was even getting some bridge connection problems when I had the routers connected to the internet. After trying a lot of different settings, DD-WRT firmware resets/upgrades, I decided to revert one of the routers back to its stock firmware. Lo and behold, my app found the bridge via upnp search almost immediately, even when offline.

My suggestion to other devs is to be careful if you are dealing with configurations involving DD-WRT, especially if it involves this router model. There might be some way to get the SDK to talk to the bridges via some combination of settings that I haven't been able to pinpoint, but something is definitely funny with out-of-the-box DD-WRT here.

Thanks, Greg

SteveyO commented 9 years ago

Hi Greg, Thanks for posting your fix. Hopefully this will help others. Steve