private static void CollectData() { Console.WriteLine("CollectData..."); bool collected = false; try { MyStromConnector licht = new MyStromConnector("192.168.1.206"); MyStromConnector umLuft = new MyStromConnector("192.168.1.108"); MyStromConnector abLuft = new MyStromConnector("192.168.1.241"); MyStromConnector watering = new MyStromConnector("192.168.1.109"); ShellyConnector tempHygro = new ShellyConnector("192.168.1.187"); Watering = DataConverter.ConvertToWateringDevice(watering.Get()); Light = DataConverter.ConvertToLightDevice(licht.Get()); FanIn = DataConverter.ConvertToFanDevice(umLuft.Get()); Suction = DataConverter.ConvertToSuctionDevice(abLuft.Get()); var tempHygroValue = tempHygro.Get(); Temperature = DataConverter.ConvertToTemperatureDevice(tempHygroValue); Humidity = DataConverter.ConvertToHumidityDevice(tempHygroValue); collected = true; } catch (Exception ex) { Console.WriteLine("DATACOLLECTOR FAILED"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } if (collected) { _gateway.AddData(5, Watering.Name, Watering.PowerValue.ToString(), DateTime.Now.ToString()); _gateway.AddData(1, Light.Name, Light.PowerValue.ToString(), DateTime.Now.ToString()); _gateway.AddData(3, FanIn.Name, FanIn.PowerValue.ToString(), DateTime.Now.ToString()); _gateway.AddData(4, Suction.Name, Suction.PowerValue.ToString(), DateTime.Now.ToString()); _gateway.AddData(2, Temperature.Name, Temperature.CelsiusValue.ToString(), DateTime.Now.ToString()); _gateway.AddData(6, Humidity.Name, Humidity.HumidityValue.ToString(), DateTime.Now.ToString()); Console.WriteLine("Collected & Insered!"); } else { Console.WriteLine("Not collected & not insered!"); } }
public ActionResult Index() { OverViewModel model = new OverViewModel(); MyStromConnector licht = new MyStromConnector("192.168.1.206"); MyStromConnector umLuft = new MyStromConnector("192.168.1.108"); MyStromConnector abLuft = new MyStromConnector("192.168.1.241"); ShellyConnector tempHygro = new ShellyConnector("192.168.1.187"); MyStromConnector watering = new MyStromConnector("192.168.1.109"); model.Watering = DataConverter.ConvertToWateringDevice(watering.Get()); model.Light = DataConverter.ConvertToLightDevice(licht.Get()); model.FanIn = DataConverter.ConvertToFanDevice(umLuft.Get()); model.Suction = DataConverter.ConvertToSuctionDevice(abLuft.Get()); var tempResp = tempHygro.Get(); model.Temperature = DataConverter.ConvertToTemperatureDevice(tempResp); model.Humidity = DataConverter.ConvertToHumidityDevice(tempResp); FlowersGateway flowers = new FlowersGateway(); model.FlowersInBloom = flowers.GetFlowersInBloom(); SystemSettingsGateway gateway = new SystemSettingsGateway(); List <SystemSetting> settings = gateway.GetSystemSettings(); model.Sunrise = settings.First(x => x.Name == "Sunrise").Value; model.SunSet = settings.First(x => x.Name == "Sunset").Value; model.TempMinMax = "Temp: " + settings.First(x => x.Name == "MinTemp").Value + "°C - " + settings.First(x => x.Name == "MaxTemp").Value + "°C"; model.HumidityMinMax = "RLF: " + settings.First(x => x.Name == "MinHumidity").Value + "% - " + settings.First(x => x.Name == "MaxHumidity").Value + "%"; //var x = _gateway.GetCollectedData(); var notifications = _notyGateway.GetDeviceNotification(); model.Temperature.Info = notifications.First(x => x.DeviceId == model.Temperature.Id); model.Humidity.Info = notifications.First(x => x.DeviceId == model.Humidity.Id); model.Watering.Info = notifications.First(x => x.DeviceId == model.Watering.Id); return(View(model)); }