/// <summary> /// Switch on/off the hot water /// </summary> /// <param name="state">0=off 1=on</param> /// <param name="message">mesage to display on wifilink</param> /// <returns></returns> public static string HotWaterOnOff(State state, string message = "") { string text = nextind + ",!R16D2F" + StateStrings.GetStateString(state) + @"|" + message; return(sendRaw(text).Replace(ind + ",", "")); }
/// <summary> /// send on/off command to a room/device /// </summary> /// <param name="Room">room number </param> /// <param name="Device">device number</param> /// <param name="state">state (0 or 1)</param> /// <returns>String "OK" otherwise error message</returns> public static string DeviceOnOff(int room, int device, State state) { string text = nextind + ",!R" + room + @"D" + device + @"F" + StateStrings.GetStateString(state) + @"|"; return(sendRaw(text).Replace(ind + ",", "")); }
/// <summary> /// send on/off command to a room/device /// </summary> /// <param name="Room">room number </param> /// <param name="state">state 1 = on 0 = off</param> /// <param name="message">message to display on wifilink</param> /// <returns>String "OK" otherwise error message</returns> public static string HeatOnOff(int room, State state, string message = "") { string text = nextind + ",!R" + room + @"DhF" + StateStrings.GetStateString(state) + @"|" + message; return(sendRaw(text).Replace(ind + ",", "")); }
/// <summary> /// /// </summary> private static void listenThreadWorker() { Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9760); sock.Bind(iep); EndPoint ep = (EndPoint)iep; Console.WriteLine("Ready to receive..."); try { while (true) { byte[] data = new byte[1024]; int recv = sock.ReceiveFrom(data, ref ep); string stringData = Encoding.ASCII.GetString(data, 0, recv); if (Raw != null) { Raw(null, stringData); } Match OnOffMatch = new Regex(OnOffRegEx).Match(stringData); Match AllOffMatch = new Regex(allOffRegEx).Match(stringData); Match MoodMatch = new Regex(moodRegEx).Match(stringData); Match DimMatch = new Regex(dimRegEx).Match(stringData); Match HeatMatch = new Regex(heatRegEx).Match(stringData); if (OnOffMatch.Success) { var thisDevice = new Device(new Room(int.Parse(OnOffMatch.Groups["Room"].Value)), int.Parse(OnOffMatch.Groups["Device"].Value), "Dev " + int.Parse(OnOffMatch.Groups["Device"].Value), DeviceType.OnOff, StateStrings.GetStateFromString(OnOffMatch.Groups["State"].Value)); updateLastDeviceState(thisDevice); if (OnOff != null) { OnOff(null, thisDevice.room.RoomNum, thisDevice.devicenum, thisDevice.state); } } if (AllOffMatch.Success && OnAllOff != null) { OnAllOff(null, int.Parse(AllOffMatch.Groups["Room"].Value)); } if (MoodMatch.Success && OnMood != null) { OnMood(null, int.Parse(MoodMatch.Groups["Room"].Value), int.Parse(MoodMatch.Groups["Mood"].Value)); } if (DimMatch.Success) { State deviceState = new State(); if (DimMatch.Groups["State"].Value == "0") { deviceState = State.Off; } else { deviceState = State.On; } var thisDevice = new Device(new Room(int.Parse(DimMatch.Groups["Room"].Value)), int.Parse(DimMatch.Groups["Device"].Value), "Dev " + int.Parse(DimMatch.Groups["Device"].Value), DeviceType.OnOff, deviceState); thisDevice.DimLevel = (int)Math.Round(double.Parse(DimMatch.Groups["State"].Value) / 32 * 100); updateLastDeviceState(thisDevice); if (OnDim != null) { OnDim(null, thisDevice.room.RoomNum, thisDevice.devicenum, thisDevice.DimLevel); } } if (HeatMatch.Success) { var thisDevice = new Device(new Room(int.Parse(HeatMatch.Groups["Room"].Value)), 0, "Rad " + int.Parse(HeatMatch.Groups["Room"].Value), DeviceType.Radiator, StateStrings.GetStateFromString(HeatMatch.Groups["State"].Value)); updateLastDeviceState(thisDevice); if (OnHeat != null) { OnHeat(null, thisDevice.room.RoomNum, thisDevice.state); } } } } finally { sock.Close(); } }