private static void LightOnOff() { Console.WriteLine("Press [ENTER] to send command ({0}) - true", LightOnOffAddress); Console.ReadLine(); _connection.Action(LightOnOffAddress, true); Thread.Sleep(200); Console.WriteLine("Press [ENTER] to send command ({0}) - false", LightOnOffAddress); Console.ReadLine(); _connection.Action(LightOnOffAddress, false); Thread.Sleep(200); }
private static void LightOnOff(KnxConnection connection) { Console.WriteLine("Press [ENTER] to send command ({0}) - false", LightOnOffAddress); Console.ReadLine(); connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), false); Thread.Sleep(200); Console.WriteLine("Press [ENTER] to send command ({0}) - true", LightOnOffAddress); Console.ReadLine(); connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), true); Thread.Sleep(200); }
public object InterfaceControl(MigInterfaceCommand request) { var response = new ResponseText("OK"); //default success value Commands command; Enum.TryParse(request.Command.Replace(".", "_"), out command); var module = _modules.Find(m => m.Address.Equals(request.Address)); if (module != null) { switch (command) { case Commands.Control_On: _connection.Action(module.Address.Replace(".", "/"), true); break; case Commands.Control_Off: _connection.Action(module.Address.Replace(".", "/"), false); // TODO: ... break; case Commands.Dimmer_Up: _connection.Action(module.Address.Replace(".", "/"), _connection.ToDataPoint("3.008", 3)); // TODO: ... break; case Commands.Dimmer_Down: _connection.Action(module.Address.Replace(".", "/"), _connection.ToDataPoint("3.008", -3)); // TODO: ... break; } } else { response = new ResponseText("ERROR: invalid module address"); } return(response); }
public static void Main(string[] args) { /*test output werte richtig anzeigen * testen knx connection unten abschalten * auf nas probiren*/ _connection = new KnxConnectionTunneling("192.168.100.250", 3671, "192.168.100.166", 3671) { Debug = false }; //_connection = new KnxConnectionTunneling("192.168.100.250", 3671, "172.17.0.2", 3672) { Debug = true }; //_connection = new KnxConnectionTunneling("192.168.100.250", 3671, "192.168.100.90", 3672) { Debug = false }; /*DOCKER NAS*/ //_connection = new KnxConnectionTunneling("192.168.100.250", 3671, "192.168.100.172", 3671) { Debug = false }; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxEventDelegate += Event; _connection.KnxStatusDelegate += Status; _connection.Connect(); Console.WriteLine("Done. Press [ENTER] to finish"); //Console.ReadLine(); //Console.WriteLine("send"); //_connection.Action("2/1/3", true); //Console.ReadLine(); //_connection.Action("2/1/3", false); Console.ReadLine(); Console.WriteLine("send"); _connection.Action("2/1/3", true); Console.ReadLine(); _connection.Action("2/1/3", false); Console.ReadLine(); _connection.KnxDisconnectedDelegate -= Disconnected; _connection.Disconnect(); Console.ReadLine(); Environment.Exit(0); }
public void GoChenillard() { Console.WriteLine("Go !"); int i = 0; while (isActive == true) { if (i == 4) { i = 0; } client.Action(arrayLed[i], true); Thread.Sleep(speed); client.Action(arrayLed[i], false); i++; client.Action(arrayLed[i], true); Thread.Sleep(speed); //Attention, ne doit pas ĂȘtre en dessous de 500ms. client.Action(arrayLed[i], false); i++; } }
/// <summary> /// Send action data to the specified address. /// </summary> /// <param name="address">Address.</param> /// <param name="data">boolean action value.</param> public KnxClientHelper Action(string address, bool data) { knxClient.Action(address, data); return(this); }
public void Init() { lock (_runLock) { if (_run) { return; } _run = true; } _connection = new KnxConnectionTunneling("192.168.1.100", 3671, "192.168.1.101", 3671); _connection.Debug = true; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxConnectedDelegate += Connected; _connection.KnxStatusDelegate += Status; _connection.KnxEventDelegate += Event; #region Never ending loop Task.Factory.StartNew(() => { //var doAction = true; //var address = "0/0/1"; //var state = true; //Repeat daily var rrule = new RecurrencePattern(FrequencyType.Daily, 1); double offsetOn = 0.5; //SP should become 20.5 double offsetOff = -2; //SP should become 18 var calendar = new Ical.Net.Calendar(); List <MyCalendarEvent> myCalendarEvents = new List <MyCalendarEvent>(); //off var e_00__6_30 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 0, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 6, 30, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_00__6_30); myCalendarEvents.Add(e_00__6_30); //on var e_6_30__8 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 6, 30, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 8, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_6_30__8); myCalendarEvents.Add(e_6_30__8); //off var e_8__12 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 8, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 12, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_8__12); myCalendarEvents.Add(e_8__12); //on var e_12__14 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 12, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 14, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_12__14); myCalendarEvents.Add(e_12__14); //off var e_14__17 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 14, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 17, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_14__17); myCalendarEvents.Add(e_14__17); //on var e_17__18_30 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 17, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 18, 30, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_17__18_30); myCalendarEvents.Add(e_17__18_30); //off var e_18_30__20_30 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 18, 30, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 20, 30, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_18_30__20_30); myCalendarEvents.Add(e_18_30__20_30); //on var e_20_30__22 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 20, 30, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 22, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_20_30__22); myCalendarEvents.Add(e_20_30__22); //off var e_22__00 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 22, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 5, 0, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_22__00); myCalendarEvents.Add(e_22__00); var serializer = new CalendarSerializer(); var serializedCalendar = serializer.SerializeToString(calendar); var searchStart = DateTime.Now.Date; var searchEnd = searchStart.AddDays(1); List <EventOccurrency> events = GetEventOccurrencies(myCalendarEvents, calendar, searchStart, searchEnd); foreach (var myEvent in events) { _logger.LogInformation("Event: {0} - {1}, offset: {2}", myEvent.Start, myEvent.End, myEvent.Offset); } EventOccurrency currentEvent = null; while (_run) { if (!_connected) { InitGroups(); _logger.LogInformation("Connecting"); _connection.Connect(); Task.Delay(5000).GetAwaiter().GetResult(); StartupCaldaia(); //var readOnlyGroupAddresses = Groups.Values.Where(g => g.Direction == KnxGroupDirection.OUTPUT).Select(g => g.Address).ToList(); //foreach (var readOnlyGroupAddress in readOnlyGroupAddresses) //{ // if (!_connected) // { // break; // } // _connection.RequestStatus(readOnlyGroupAddress); // Task.Run(() => // { // Thread.Sleep(1000); // }).Wait(); //} //_connection.Action("2/1/11", true); //Task.Delay(2000).GetAwaiter().GetResult(); //_connection.RequestStatus("2/1/11"); //if (_connected) //{ // var dpValue = _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.HVAC], "3"); // _connection.Action("2/1/4", dpValue); // var dpTempValue = _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.TEMPERATURE], "1"); // _connection.Action("2/1/13", dpTempValue); // var _2_1_xAddresses = Groups.Values.Where(v => v.Address.StartsWith("2/1/")).ToList(); // foreach (var _2_1_xAddress in _2_1_xAddresses) // { // _connection.RequestStatus(_2_1_xAddress.Address); // Task.Delay(200).GetAwaiter().GetResult(); // } // //Task.Delay(2000).GetAwaiter().GetResult(); // //_connection.RequestStatus("2/1/4"); //} } var now = DateTime.Now; if (now >= searchEnd) { searchStart = now.Date; searchEnd = searchStart.AddDays(1); _logger.LogInformation("Changing day: {0} - {1}", searchStart, searchEnd); events = GetEventOccurrencies(myCalendarEvents, calendar, searchStart, searchEnd); foreach (var myEvent in events) { _logger.LogInformation("Event: {0} - {1}, offset: {2}", myEvent.Start, myEvent.End, myEvent.Offset); } } //now < searchEnd else if (currentEvent == null || currentEvent.End <= now) { _logger.LogInformation("Set current event: {0}", now); events.RemoveAll(e => e.End <= now); if (events.Any()) { currentEvent = events.OrderBy(e => e.Start).First(); _logger.LogInformation("Event: {0} - {1}, offset: {2}", currentEvent.Start, currentEvent.End, currentEvent.Offset); var offsetString = currentEvent.Offset.ToString(CultureInfo.InvariantCulture); var dpTempValue = _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.TEMPERATURE], offsetString); _connection.Action("2/1/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/2/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/3/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/4/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/5/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/6/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); } } Task.Delay(100).GetAwaiter().GetResult(); } }); #endregion }
private void RequestStateChange(KnxGroupWithStateDto group) { switch (group.DPT.Value) { case KnxDPTEnum.BOOLEAN: { Console.Write("true/false: "); var boolString = Console.In.ReadLine(); bool boolState; if (bool.TryParse(boolString, out boolState)) { _connection.Action(group.Address, boolState); } else { Console.Out.WriteLine("Stato non valido"); } } break; case KnxDPTEnum.SWITCH: { Console.Write("on/off: "); var onOffString = Console.In.ReadLine(); if (onOffString.ToLower() == "on".ToLower()) { _connection.Action(group.Address, true); } else if (onOffString.ToLower() == "off".ToLower()) { _connection.Action(group.Address, false); } else { Console.Out.WriteLine("Stato non valido"); } } break; case KnxDPTEnum.UP_DOWN: { Console.Write("up/down: "); var onOffString = Console.In.ReadLine(); if (onOffString.ToLower() == "up".ToLower()) { _connection.Action(group.Address, false); } else if (onOffString.ToLower() == "down".ToLower()) { _connection.Action(group.Address, true); } else { Console.Out.WriteLine("Stato non valido"); } } break; case KnxDPTEnum.TEMPERATURE: { Console.Write("5..28: "); var tempString = Console.In.ReadLine(); double tempState; if (double.TryParse(tempString, NumberStyles.Any, CultureInfo.InvariantCulture, out tempState)) { _connection.Action(group.Address, _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.TEMPERATURE], tempString)); } else { Console.Out.WriteLine("Stato non valido"); } } break; case KnxDPTEnum.OPEN_CLOSE: { Console.Write("open/closed: "); var openClosedString = Console.In.ReadLine(); if (openClosedString.ToLower() == "open".ToLower()) { _connection.Action(group.Address, false); } else if (openClosedString.ToLower() == "closed".ToLower()) { _connection.Action(group.Address, true); } else { Console.Out.WriteLine("Stato non valido"); } } break; case KnxDPTEnum.COUNTER_PULSES: case KnxDPTEnum.DIMMING_CONTROL: Console.Out.WriteLine("DPT non gestito"); break; case KnxDPTEnum.PERCENTAGE: { Console.Write("0..100: "); var percString = Console.In.ReadLine(); double percState; if (double.TryParse(percString, NumberStyles.Any, CultureInfo.InvariantCulture, out percState) && percState >= 0 && percState <= 100) { _connection.Action(group.Address, _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.PERCENTAGE], percString)); } else { Console.Out.WriteLine("Stato non valido"); } } break; case KnxDPTEnum.HVAC: { Console.Write("0..4: "); var intString = Console.In.ReadLine(); int intHVAC; if (int.TryParse(intString, NumberStyles.Any, CultureInfo.InvariantCulture, out intHVAC) && intHVAC >= 0 && intHVAC <= 4) { _connection.Action(group.Address, _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.HVAC], intString)); } else { Console.Out.WriteLine("Stato non valido"); } } break; default: break; } }