/// <summary>
        /// Gets the data.
        /// </summary>
        /// <returns>The DHT data.</returns>
        public DhtData GetData()
        {
            if (!started)
            {
                pin.Write(true);
                previousRead = DateTime.UtcNow;
            }

            DhtData data     = null;
            var     tryCount = 0;

            while (data == null && tryCount++ <= 10)
            {
                try
                {
                    data = TryGetData();
                    data.AttemptCount = tryCount;
                }
                catch (Exception ex)
                {
                    var logger = LogManager.GetLogger <DhtConnection>();
                    logger.Error(
                        CultureInfo.InvariantCulture,
                        h => h("Failed to read data from DHT11, try {0}", tryCount),
                        ex);
                }
            }

            if (!started)
            {
                pin.Write(false);
            }

            return(data);
        }
示例#2
0
        public bool TempSensorConnection(GpioInputOutputBinaryPin Pin)
        {
            bool IsConnected = false;

            try
            {
                using (Raspberry.IO.Components.Sensors.Temperature.Dht.Dht22Connection dht22Connection = new Raspberry.IO.Components.Sensors.Temperature.Dht.Dht22Connection(Pin))
                {
                    Raspberry.IO.Components.Sensors.Temperature.Dht.DhtData data = new Raspberry.IO.Components.Sensors.Temperature.Dht.DhtData();
                    //data = dht22Connection.GetData();
                }


                IsConnected = true;
                Console.WriteLine("Connection has been established and Pin is declared ");
            }

            catch (Exception ex)
            {
                Console.WriteLine("Cant establish connection or declare Pin " + ex.Message);
            }
            finally
            {
                Console.WriteLine("work witch connections is finished ");
            }

            return(IsConnected);
        }
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <returns>The DHT data.</returns>
        public DhtData GetData()
        {
            if (!started)
            {
                pin.Write(true);
                previousRead = DateTime.UtcNow;
            }

            DhtData data     = null;
            var     tryCount = 0;

            while (data == null && tryCount++ <= 10)
            {
                try
                {
                    data = TryGetData();
                    data.AttemptCount = tryCount;
                }
                catch (Exception ex)
                {
                    log.LogError(null, ex, $"Failed to read data from DHT11, try {tryCount}");
                }
            }

            if (!started)
            {
                pin.Write(false);
            }

            return(data);
        }
示例#4
0
 public bool Read()
 {
     using (var dhtConnection = new Raspberry.IO.Components.Sensors.Temperature.Dht.Dht22Connection(pin))
     {
         TempData = dhtConnection.GetData();
         if (TempData != null)
         {
             Console.WriteLine("{0:0.00}% humidity, {1:0.0}°C, {2} attempts", TempData.RelativeHumidity.Percent, TempData.Temperature.DegreesCelsius, TempData.AttemptCount);
         }
         else
         {
             Console.WriteLine("Unable to read data");
         }
     }
     throw new NotImplementedException();
 }
示例#5
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <returns>The DHT data.</returns>
        public DhtData GetData()
        {
            if (!started)
            {
                pin.Write(true);
                previousRead = DateTime.UtcNow;
            }

            DhtData data     = null;
            var     tryCount = 0;

            while (data == null && tryCount++ <= 10)
            {
                try
                {
                    data = TryGetData();
                    data.AttemptCount = tryCount;
                }
                catch (Exception ex)
                {
                    ILoggerFactory loggerFactory = new LoggerFactory()
                                                   .AddConsole()
                                                   .AddDebug();
                    ILogger log = loggerFactory.CreateLogger <DhtConnection>();

                    log.LogError(null, ex, $"Failed to read data from DHT11, try {tryCount}");
                }
            }

            if (!started)
            {
                pin.Write(false);
            }

            return(data);
        }
示例#6
0
 public Raspberry.IO.Components.Sensors.Temperature.Dht.DhtData GetTempSensorData()//считывает данные с датчика температуры, сохраняет последние 200 изменений в файл и ОЗУ.
 {
     Raspberry.IO.Components.Sensors.Temperature.Dht.DhtData data = new Raspberry.IO.Components.Sensors.Temperature.Dht.DhtData();
     return(data);
 }