Exemple #1
0
    static void Main(string[] args)
    {
        Console.WriteLine("Hello DHT!");

        DHTSensor dht = new DHTSensor(26, DhtType.Dht22);

        while (true)
        {
            // You have 2 ways to read the data, both are equivalent
            // First way to read the data
            bool readret = dht.ReadData();
            if (readret)
            {
                Console.WriteLine($"Temperature: {dht.Temperature.Celsius.ToString("0.00")} °C, Humidity: {dht.Humidity.ToString("0.00")} %");
            }
            else
            {
                Console.WriteLine("Error reading the sensor");
            }
            Thread.Sleep(1000);

            // Second way to read the data
            Temperature Temp;
            double      Hum;
            if (dht.TryGetTemperatureAndHumidity(out Temp, out Hum))
            {
                Console.WriteLine($"Temperature: {Temp.Celsius.ToString("0.00")} °C, Humidity: {Hum.ToString("0.00")} %");
            }
            else
            {
                Console.WriteLine("Error reading the sensor");
            }
            Thread.Sleep(1000);
        }
    }
 /// <summary>
 /// Constructor of Temperature and Humidity sensor
 /// </summary>
 /// <param name="readingFrequency"></param>
 public TemperatureHumiditySensor(ILog logger)
 {
     Type    = SensorType.Humidity;
     Unit    = UnitType.Percent;
     _logger = logger;
     _sensor = new DHTSensor(Pi.Gpio.Pin07, DHTSensorTypes.DHT11);
 }
 /// <summary>
 /// Constructor of Temperature sensor
 /// </summary>
 /// <param name="readingFrequency"></param>
 public TemperatureSensor(ILog logger)
 {
     Type    = SensorType.Temperature;
     Unit    = UnitType.CelsiusDegree;
     _logger = logger;
     _sensor = new DHTSensor(Pi.Gpio.Pin07, DHTSensorTypes.DHT11);
     Thread.Sleep(2000); //Inicializace sensoru před měřením
 }
 /// <summary>
 /// Constructor of Humidity sensor
 /// </summary>
 /// <param name="readingFrequency"></param>
 public HumiditySensor(ILog logger)
 {
     Type    = SensorType.Humidity;
     Unit    = UnitType.Percent;
     _logger = logger;
     _sensor = new DHTSensor(Pi.Gpio.Pin07, DHTSensorTypes.DHT11);
     Thread.Sleep(2000); //Inicializace sensoru před měřením
 }
Exemple #5
0
 public DHT11Result CurrentStatus()
 {
     using (DHTSensor dht = new DHTSensor(2, DhtType.Dht11))
     {
         return(new DHT11Result
         {
             Temperature = dht.Temperature.Celsius,
             Humidity = dht.Humidity
         });
     }
 }
        static void DhtSample(List <int> possiblePins)
        {
            int dataPin = possiblePins.Count > 0 ? possiblePins[0] : DefaultDHTDataPin;

            Console.WriteLine("Raspberry Pi wiringPi DHT11/22 (AM2303) reader");
            DHTSensor sensor = new DHTSensor(dataPin, 3);

            sensor.Read();
            if (sensor.IsDataValid)
            {
                Console.WriteLine("Humidity = {0:0.00} % Temperature = {1:0.00} *C (Tries: {2})",
                                  sensor.Humidity, sensor.Temperature, sensor.Tries);
            }
            else
            {
                Console.WriteLine("Error, DHT sensor not responding  (Tries: {0})",
                                  sensor.Tries);
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var pin = 17;
            var lightTimeInMilliseconds = 1000;
            var dimTimeInMilliseconds   = 1000;

            var tempSensor = new DHTSensor(27, DhtType.Dht11);

            bool result = false;

            /*
             * I2cConnectionSettings i2cSettings = new I2cConnectionSettings(1, 0x39);
             * // get I2cDevice (in Linux)
             * UnixI2cDevice i2cDevice = new UnixI2cDevice(i2cSettings);
             * var lightSensor = new TMD2771(i2cDevice);
             * lightSensor.init();
             */
            /////////

            /*
             * void callback(object sender, PinValueChangedEventArgs pinValueChangedEventArgs)
             * {
             *  Console.WriteLine("************Presed**************");
             * }
             */
            /////////////


            GpioController controller = new GpioController();

            controller.OpenPin(22, PinMode.Input);
            //controller.RegisterCallbackForPinValueChangedEvent(22, PinEventTypes.Rising, callback);

            controller.OpenPin(pin, PinMode.Output);

            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
            {
                controller.Dispose();
            };

            //Console.WriteLine("enter URL");
            //myURL = Console.ReadLine();
            //Console.WriteLine(myURL);
            myURL = "http://ehsankianifar-001-site1.itempurl.com/api/TempData";

            while (true)
            {
                controller.Write(pin, PinValue.High);
                Thread.Sleep(lightTimeInMilliseconds);
                controller.Write(pin, PinValue.Low);
                Thread.Sleep(dimTimeInMilliseconds);

                result = tempSensor.TryGetTemperatureAndHumidity(out temperature, out humidity);
                Console.WriteLine($"Temp in centigrad {temperature}");
                Console.WriteLine($"humidity in percent {humidity}");
                //Console.WriteLine($"result {result}");
                //Console.WriteLine($"light sensor c0 {lightSensor.ReadC0()}");
                //Console.WriteLine($"light sensor c1 {lightSensor.ReadC1()}");
                //Console.WriteLine($"light sensor id {lightSensor.ReadId()}");

                sendDataAsync();
                //TestAsync();
            }
        }