private WizResult UpdateLight(WizParams wizParams, string lightId) { WizSocket socket = new WizSocket(); socket.GetSocket().EnableBroadcast = true; // This will enable sending to the broadcast address socket.GetSocket().ReceiveTimeout = 1000; // This will prevent the demo from running indefinitely WizHandle handle = new WizHandle(lightId, IPAddress.Broadcast); // MAC doesn't matter here WizState state = new WizState { Method = WizMethod.setPilot, Params = wizParams }; socket.SendTo(state, handle); WizResult pilot; while (true) { state = socket.ReceiveFrom(handle); pilot = state.Result; break; } return(pilot); }
private IEnumerable <(string LightName, string MacAddress)> GetHomeIds() { WizSocket socket = new WizSocket(); socket.GetSocket().EnableBroadcast = true; // This will enable sending to the broadcast address WizHandle handle = new WizHandle("000000000000", IPAddress.Broadcast); // MAC doesn't matter here WizState state = WizState.MakeGetSystemConfig(); socket.GetSocket().ReceiveTimeout = 1000; // This will prevent the demo from running indefinitely socket.SendTo(state, handle); List <(string LightName, string MacAddress)> homeIds = new List <(string LightName, string MacAddress)>(); // You won't easily get an IP address here, but this will list all Home IDs on the network. while (true) { state = socket.ReceiveFrom(handle); if (state.Result.HomeId != null) { Console.WriteLine($"Home ID for light {state.Result.Mac} = {state.Result.HomeId}"); (string LightName, string MacAddress)result = (state.Result.ModuleName, state.Result.Mac); homeIds.Add(result); } break; } return(homeIds); }