Exemplo n.º 1
0
        /// <summary>
        /// Write the sensor value to the database
        /// </summary>
        /// <param name="SensorValue">Tinkerforge Sensor plugin value</param>
        /// <param name="MType">Used measurement type - the sensor name</param>
        /// <param name="MUnit">used measurement unit</param>
        /// <param name="MLocation">used measurement location</param>
        private void WriteSensorData(MeasurementValue SensorValue, MType MType, MUnit MUnit, MLocation MLocation)
        {
            var MValue = new MValue
            {
                Type       = MType,
                Unit       = MUnit,
                Location   = MLocation,
                RecordTime = SensorValue.Timestamp,
                Value      = SensorValue.Value
            };

            DBInstance.Add(MValue);
            DBInstance.SaveChanges();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determine measurement unit object, create if not exists
        /// </summary>
        /// <param name="SensorValue">Tinkerforge Sensor plugin value</param>
        /// <returns>Referenced measurement unit object</returns>
        public MUnit DetermineMeasurementUnit(MeasurementValue SensorValue)
        {
            var MUnit = DBInstance.DBMeasurementUnits.Where(a => a.Name == SensorValue.Unit).FirstOrDefault();

            if (MUnit == null)
            {
                MUnit = new MUnit {
                    Name = SensorValue.Unit
                };
                DBInstance.Add(MUnit);
                DBInstance.SaveChanges();
            }

            return(MUnit);
        }