예제 #1
0
        private static async void ThreadBody(ModuleClient moduleClient)
        {
            var dht = new DHT(Pi.Gpio.Pin07, DHTSensorTypes.DHT11);

            //int messageCount = 0;
            while (true)
            {
                try
                {
                    var htData   = dht.ReadData();
                    var tempData = new MessageBody
                    {
                        Temperature = htData.TempCelcius,
                        Humidity    = htData.Humidity,
                        TimeCreated = DateTime.UtcNow,
                        Identifier  = "HmtSensor"
                    };

                    string dataBuffer   = JsonConvert.SerializeObject(tempData);
                    var    eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer));
                    eventMessage.Properties.Add("batchId", Guid.NewGuid().ToString());
                    Console.WriteLine($"Sending message - Body: [{dataBuffer}]");

                    await moduleClient.SendEventAsync("temperatureOutput", eventMessage);
                }
                catch (DHTException)
                {
                }

                await Task.Delay(10000);

                //messageCount++;
            }
        }
        public ActionResult <string> Get(int id)
        {
            //Sensor TH DHT11
            var dht = new DHT(22);

            var readFromDHT11   = dht.ReadData();
            var currentDateTime = DateTime.Now;

            return(Ok($"Temp= {readFromDHT11.TempCelcius} and Hum= {readFromDHT11.Humidity} , DateTime= {currentDateTime}"));
        }
예제 #3
0
        public Condition Get()
        {
            //DHT11 sensor initialize at GPIO 17
            var dhtLocalLivingRoom = new DHT(Pi.Gpio[P1.Gpio18], DHTSensorTypes.DHT11);
            var sensorData         = dhtLocalLivingRoom.ReadData();

            return(new Condition {
                SensorName = "LivingRoom1", Temperature = sensorData.TempCelcius, Humidity = sensorData.Humidity, TimeStamp = DateTime.Now
            });
        }
        public IActionResult Get()
        {
            var dhtLocalLivingRoom = new DHT(Pi.Gpio[P1.Gpio18], DHTSensorTypes.DHT11);
            var sensorData         = dhtLocalLivingRoom.ReadData();
            var lvRoomSensor1      = new Condition
            {
                SensorName  = "LivingRoom1",
                Temperature = sensorData.TempCelcius,
                Humidity    = sensorData.Humidity,
                TimeStamp   = DateTime.Now
            };

            _conditionRepository.insertCondition(lvRoomSensor1);

            return(Ok(StatusCode(200)));
        }
예제 #5
0
        static void Main(string[] args)
        {
            _programName = AppDomain.CurrentDomain.FriendlyName;

            Console.WriteLine($"Starting {_programName}.\n");
            WriteToLogFile($"Starting {_programName}.");


            try
            {
                var dht = new DHT(Pi.Gpio.Pin07, DHTSensorTypes.DHT11);
                while (true)
                {
                    try
                    {
                        var d = dht.ReadData();
                        Console.WriteLine(DateTime.UtcNow);
                        Console.WriteLine(" temp: " + d.TempCelcius);
                        Console.WriteLine(" hum: " + d.Humidity);
                    }
                    catch (DHTException)
                    {
                    }
                    Thread.Sleep(10000);
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message + " - " + e.StackTrace);
            }


            //GetConfigurationSettings();

            //CreateDatabaseAndTables();

            //SetupPin00AsTippingListener();

            //Console.WriteLine("\nPress any key to exit ...");
            //Console.ReadKey();

            Console.WriteLine($"\nEnding {_programName}.");
            WriteToLogFile($"Ending {_programName}.");
        }