michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
412 stars 114 forks source link

Problem getting bridge ip #169

Closed joao-mambelli closed 5 years ago

joao-mambelli commented 5 years ago

I'm trying to use the following:

IBridgeLocator locator = new HttpBridgeLocator();
var bridgeIPs = await locator.LocateBridgesAsync(TimeSpan.FromSeconds(5));
Console.WriteLine(bridgeIPs.First());

But what I get on console is "Q42.HueApi.Models.Bridge.LocatedBridge192". I don't know if it's a bug or it's just me that is not getting what I'm doing wrong.

Any help would be great.

P.S.: Currently I'm using the following to get the bridge ip, but I really wanted to use the LocateBridgesAsync method.

HttpClient client = new HttpClient();

string response = await client.GetStringAsync("https://discovery.meethue.com");
response = response.Substring(1, response.Length - 3); // removes '[' and ']' from string
var responseModel = JsonConvert.DeserializeObject(response);
JObject data = JObject.Parse(responseModel.ToString());

Console.WriteLine(data["internalipaddress"]?.ToString());
michielpost commented 5 years ago

LocateBridgesAsync returns a List of LocatedBridge. LocatedBridge contains the IP and BridgeId. So you have to do this: bridgeIPs.First().IpAddress

joao-mambelli commented 5 years ago

Thank you.