示例#1
0
        async private Task <ISensorItem> CreateVideoSensor(
            SsdpDevice fullDevice,
            string serialNumber,
            IDeviceItem videoCameraDeviceItem)
        {
            ISensorItem sensor = null;

            // We need to do this in the UI thread since it may cause some UI elements to be updated.
            await DispatcherHelper.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                sensor = new SensorItem(videoCameraDeviceItem.DeviceId)
                {
                    Description  = (fullDevice.FriendlyName ?? string.Empty),
                    IsEnabled    = true,
                    SensorType   = SensorType.VideoCamera,
                    SensorUsage  = SensorUsage.Other,
                    SerialNumber = serialNumber,
                };

                sensor = await App.SensorCollection.BeginAdd(sensor);
            });

            Debug.Assert(null != sensor);

            return(sensor);
        }
示例#2
0
        public IActionResult Create([FromBody] SensorItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            //item.Timestamp.ToString("HH:mm:ss");
            TimeSpan TS = item.Timestamp.TimeOfDay;
            //check of er een status van agendaitem moet worden ge-update
            //verander timestamp, starttime en endtime naar Time value!
            var agendaitem = _context.Agendadata.FirstOrDefault(t => t.StartTime <TS && t.EndTime> TS && t.StartDate.Date <= item.Timestamp.Date && t.EndDate.Date >= item.Timestamp.Date && t.CostumerId == item.CostumerId);

            if (agendaitem != null)
            {
                agendaitem.State = "completed";
                _context.Agendadata.Update(agendaitem);
            }
            //Geef sensoritem een id
            var sensoritemhighid = _context.SensorItems.LastOrDefault();

            item.Id = sensoritemhighid.Id + 1;


            _context.SensorItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetSensordata", new { id = item.Id }, item));
        }
示例#3
0
        public async Task <ActionResult <SensorItem> > PostSensorItem(SensorItem item)
        {
            _context.SensorItems.Add(item);
            _service.Write(item);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetSensorItem), new { id = item.Id }, item));
        }
示例#4
0
        public void Write(SensorItem item)
        {
            string text = item.Id.ToString() + ";" +
                          item.Tag + ";" +
                          item.Timestamp.ToString() + ";" +
                          item.Valor + Environment.NewLine;

            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            File.AppendAllText(Path.Combine(docPath, "SensorLog.txt"), text);
        }
        private SensorItem CreateSensor(int i)
        {
            var item = new SensorItem(
                name: $"Volume IO _Total{i}",
                typeRaw: "aggregation",
                objid: (4000 + i).ToString(),
                downtimeTimeRaw: (1220 + i).ToString(),
                messageRaw: "OK1" + i,
                lastUpRaw: new DateTime(2000, 10, 1, 4, 2, 1, DateTimeKind.Utc).AddDays(i).ToUniversalTime().ToOADate().ToString(CultureInfo.InvariantCulture)
                );

            return(AdjustProperties(item, Content.Sensors));
        }
示例#6
0
        private BaseItem GetTileForModule(Module m)
        {
            BaseItem        tile   = null;
            ModuleParameter widget = m.GetProperty("Widget.DisplayModule");

            if (widget != null && !String.IsNullOrEmpty(widget.Value))
            {
                switch (widget.Value)
                {
                case "homegenie/generic/sensor":
                case "homegenie/generic/temperature":
                    tile = new SensorItem();
                    break;

                case "homegenie/generic/doorwindow":
                    tile = new DoorWindowItem();
                    break;

                default:
                    tile = new GenericItem();
                    break;
                }
            }
            else
            {
                switch (m.DeviceType)
                {
                case "Sensor":
                case "Temperature":
                    tile = new SensorItem();
                    break;

                case "DoorWindow":
                    tile = new DoorWindowItem();
                    break;

                default:
                    tile = new GenericItem();
                    break;
                }
            }
            return(tile);
        }
示例#7
0
        public IActionResult Update([FromBody] SensorItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var sensordata = _context.SensorItems.FirstOrDefault(t => t.Id == item.Id);

            if (sensordata == null)
            {
                return(NotFound());
            }

            sensordata.CostumerId = item.CostumerId;
            sensordata.SensorId   = item.SensorId;
            sensordata.Timestamp  = item.Timestamp;
            sensordata.Value      = item.Value;

            _context.SensorItems.Update(sensordata);
            _context.SaveChanges();
            return(new NoContentResult());
        }
        public void StartClient()
        {
            // Data buffer for incoming data.
            byte[] bytes = new byte[1024];

            // Connect to a remote device.
            try
            {
                // Establish the remote endpoint for the socket.
                // This example uses port 11000 on the local computer.
                IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress   ipAddress  = IPAddress.Parse(txtIP.Text); //ipHostInfo.AddressList[0];
                IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, int.Parse(txtPort.Text));

                // Create a TCP/IP  socket
                Socket sender = new Socket(AddressFamily.InterNetwork,//stop here   //.InterNetwork, //code change here .Address
                                           SocketType.Stream, ProtocolType.Tcp);

                // Connect the socket to the remote endpoint. Catch any errors.
                try
                {
                    sender.Connect(remoteEP);
                    while (isConnect)
                    {
                        Debug.WriteLine("Socket connected to {0}",
                                        sender.RemoteEndPoint.ToString());

                        // Receive the response from the remote device.
                        int bytesRec = sender.Receive(bytes);
                        var received = Encoding.ASCII.GetString(bytes, 0, bytesRec);
                        Debug.WriteLine("Echoed test = {0}", received);
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            try
                            {
                                SensorItem item = JsonConvert.DeserializeObject <SensorItem>(received);
                                Debug.WriteLine(item.Acc.X);

                                SensorItems.Add(item);
                                lblTemp.Text = item.Tem.ToString();
                                gauIndicatorTemperature.Value = item.Tem;
                                if (SensorItems.Count > 5)
                                {
                                    SensorItems.RemoveAt(0);
                                }
                            }
                            catch (Exception e) {
                                Alert(e.ToString());
                            }
                        });



                        Debug.WriteLine("Loop Done");
                    }


                    // Release the socket.
                    sender.Shutdown(SocketShutdown.Both);
                    sender.Close();
                }
                catch (ArgumentNullException ane)
                {
                    Alert(string.Format("ArgumentNullException : {0}", ane.ToString()));
                }
                catch (SocketException se)
                {
                    Alert(string.Format("SocketException : {0}", se.ToString()));
                }
                catch (Exception e)
                {
                    Alert(string.Format("Unexpected exception : {0}", e.ToString()));
                }
            }
            catch (Exception e)
            {
                Alert(string.Format(e.ToString()));
            }
        }
        async Task PopulateDemoSensorCollection()
        {
            //await App.BuildDBTables.SensorTable.BeginEmpty();
            //await App.BuildDBTables.SensorDataTable.BeginEmpty();
            //App.SensorCollection.Clear();

            if (null == App.DeviceCollection)
            {
                return;
            }
            if (0 == App.DeviceCollection.Count)
            {
                return;
            }

            // Sensor 00
            ISensorItem sensor = new SensorItem(App.DeviceCollection[0].DeviceId);

            sensor.Name                 = "Sensor 00";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnitType       = UnitType.Power;
            sensor.SensorUnits          = Units.AmpHrs;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 01
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 01";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.Amps;
            sensor.SensorUnitType       = UnitType.Current;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 02
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 02";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.Bar;
            sensor.SensorUnitType       = UnitType.Pressure;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 03
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 03";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.Fahrenheit;
            sensor.SensorUnitType       = UnitType.Temperature;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 04
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 04";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.CubicMeters;
            sensor.SensorUnitType       = UnitType.Volume;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 05
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 05";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.CubicMetersPerHr;
            sensor.SensorUnitType       = UnitType.VolumeFlow;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 06
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 06";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.CubicMetersPerHr;
            sensor.SensorUnitType       = UnitType.VolumeFlow;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsEnabled            = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 07
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 07";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.CubicMetersPerHr;
            sensor.SensorUnitType       = UnitType.VolumeFlow;
            sensor.IsEnabled            = true;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 08
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 08";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnits          = Units.CubicMetersPerHr;
            sensor.SensorUnitType       = UnitType.VolumeFlow;
            sensor.IsEnabled            = true;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            // Sensor 09
            sensor                      = new SensorItem(App.DeviceCollection[0].DeviceId);
            sensor.Name                 = "Sensor 09";
            sensor.SerialNumber         = Guid.NewGuid().ToString();
            sensor.SensorUnits          = Units.CubicMetersPerHr;
            sensor.SensorType           = SensorType.Tank;
            sensor.SensorUnitType       = UnitType.VolumeFlow;
            sensor.IsEnabled            = true;
            sensor.IsHighAlarmEnabled   = true;
            sensor.IsHighWarningEnabled = true;
            sensor.IsLowAlarmEnabled    = true;
            sensor.IsLowWarningEnabled  = true;
            sensor.IsDemoMode           = true;
            sensor                      = await App.SensorCollection.BeginAdd(sensor);

            //// Sensor 10
            //sensor = new SensorItem(App.DeviceCollection[0].DeviceId);
            //sensor.SerialNumber = Guid.NewGuid().ToString();
            //sensor.SensorType = SensorType.Tank;
            //sensor.SensorUnits = Units.CubicMetersPerHr;
            //sensor.SensorUnitType = UnitType.VolumeFlow;
            //sensor.IsEnabled = true;
            //sensor = await App.SensorCollection.BeginAdd(sensor);

            //for (int i = 0; i < 100; i++)
            //{
            //    sensor = new SensorItem(App.DeviceCollection[0].DeviceId);
            //    sensor.SerialNumber = Guid.NewGuid().ToString();
            //    sensor.SensorUnits = Units.CubicMetersPerHr;
            //    sensor.SensorUnitType = UnitType.VolumeFlow;
            //    sensor = await App.SensorCollection.BeginAdd(sensor);
            //}

            //App.SensorCollection.Clear();
            //App.SensorCollection.Load();
        }
示例#10
0
        private List <ISensorItem> ParseSensors(XmlDocument xmlDocument)
        {
            List <ISensorItem> sensorItemList = new List <ISensorItem>();

            XmlNodeList sensorListNode = xmlDocument.GetElementsByTagName("Sensor");

            foreach (XmlNode node in sensorListNode)
            {
                XmlElement element = (XmlElement)node;

                // Get a index to the deviceId for this sensor
                int deviceIndex = Convert.ToInt32(element["DeviceIndex"].InnerText);

                ISensorItem sensorItem = new SensorItem(_deviceItemList[deviceIndex].DeviceId);

                if (null != element["Description"])
                {
                    sensorItem.Description = element["Description"].InnerText;
                }
                if (null != element["HighAlarmValue"])
                {
                    sensorItem.HighAlarmValue = Convert.ToDouble(element["HighAlarmValue"].InnerText);
                }
                if (null != element["HighWarningValue"])
                {
                    sensorItem.HighWarningValue = Convert.ToDouble(element["HighWarningValue"].InnerText);
                }
                if (null != element["IsCalibrated"])
                {
                    sensorItem.IsCalibrated = Convert.ToBoolean(element["IsCalibrated"].InnerText);
                }
                if (null != element["IsEnabled"])
                {
                    sensorItem.IsEnabled = Convert.ToBoolean(element["IsEnabled"].InnerText);
                }
                if (null != element["IsHighAlarmEnabled"])
                {
                    sensorItem.IsHighAlarmEnabled = Convert.ToBoolean(element["IsHighAlarmEnabled"].InnerText);
                }
                if (null != element["IsHighWarningEnabled"])
                {
                    sensorItem.IsHighWarningEnabled = Convert.ToBoolean(element["IsHighWarningEnabled"].InnerText);
                }
                if (null != element["IsLowAlarmEnabled"])
                {
                    sensorItem.IsLowAlarmEnabled = Convert.ToBoolean(element["IsLowAlarmEnabled"].InnerText);
                }
                if (null != element["IsLowWarningEnabled"])
                {
                    sensorItem.IsLowWarningEnabled = Convert.ToBoolean(element["IsLowWarningEnabled"].InnerText);
                }
                if (null != element["IsVirtual"])
                {
                    sensorItem.IsVirtual = Convert.ToBoolean(element["IsVirtual"].InnerText);
                }
                if (null != element["Location"])
                {
                    sensorItem.Location = element["Location"].InnerText;
                }
                if (null != element["LowAlarmValue"])
                {
                    sensorItem.LowAlarmValue = Convert.ToDouble(element["LowAlarmValue"].InnerText);
                }
                if (null != element["LowWarningValue"])
                {
                    sensorItem.LowWarningValue = Convert.ToDouble(element["LowWarningValue"].InnerText);
                }
                if (null != element["MaxValue"])
                {
                    sensorItem.MaxValue = Convert.ToDouble(element["MaxValue"].InnerText);
                }
                if (null != element["MinValue"])
                {
                    sensorItem.MinValue = Convert.ToDouble(element["MinValue"].InnerText);
                }
                if (null != element["Name"])
                {
                    sensorItem.Name = element["Name"].InnerText;
                }
                if (null != element["NominalValue"])
                {
                    sensorItem.NominalValue = Convert.ToDouble(element["NominalValue"].InnerText);
                }
                if (null != element["PersistDataPoints"])
                {
                    sensorItem.PersistDataPoints = Convert.ToBoolean(element["PersistDataPoints"].InnerText);
                }
                if (null != element["PGN"])
                {
                    sensorItem.PGN = Convert.ToUInt32(element["PGN"].InnerText);
                }
                if (null != element["PortNumber"])
                {
                    sensorItem.PortNumber = Convert.ToInt32(element["PortNumber"].InnerText);
                }
                if (null != element["Priority"])
                {
                    sensorItem.Priority = Convert.ToInt32(element["Priority"].InnerText);
                }
                if (null != element["Resolution"])
                {
                    sensorItem.Resolution = Convert.ToInt32(element["Resolution"].InnerText);
                }
                if (null != element["SensorType"])
                {
                    sensorItem.SensorType = (SensorType)Enum.Parse(typeof(SensorType), element["SensorType"].InnerText);
                }
                if (null != element["SensorUnits"])
                {
                    sensorItem.SensorUnits = (Units)Enum.Parse(typeof(Units), element["SensorUnits"].InnerText);
                }
                if (null != element["SensorUnitType"])
                {
                    sensorItem.SensorUnitType = (UnitType)Enum.Parse(typeof(UnitType), element["SensorUnitType"].InnerText);
                }
                if (null != element["SensorUsage"])
                {
                    sensorItem.SensorUsage = (SensorUsage)Enum.Parse(typeof(SensorUsage), element["SensorUsage"].InnerText);
                }
                if (null != element["SerialNumber"])
                {
                    sensorItem.SerialNumber = element["SerialNumber"].InnerText;
                }
                if (null != element["ShowNominalValue"])
                {
                    sensorItem.ShowNominalValue = Convert.ToBoolean(element["ShowNominalValue"].InnerText);
                }

                sensorItem.IsEnabled  = true;
                sensorItem.IsDemoMode = true;
                sensorItemList.Add(sensorItem);
            }

            return(sensorItemList);
        }