Beispiel #1
0
        static void InitializeObjects()
        {
            AppConfigData config = new AppConfigData();

            lcdScreen = new LcdScreen(config.LcdRsPinNumber, config.LcdEPinNumber,
                                      config.LcdData0PinNumber,
                                      config.LcdData1PinNumber,
                                      config.LcdData2PinNumber,
                                      config.LcdData3PinNumber,
                                      config.LcdData4PinNumber,
                                      config.LcdData5PinNumber,
                                      config.LcdData6PinNumber,
                                      config.LcdData7PinNumber
                                      );

            alarm = new Alarm(new Diode(config.DiodePinNumber),
                              new Buzzer(config.BuzzerPinNumber),
                              new Button(config.ButtonPinNumber));

            thermometer = new Thermometer(config.DevicesDirectoryPath,
                                          config.ThermometerAddress,
                                          config.ContentFileName);

            dhtSensor            = new DHT(config.DHTSensorPinNumber);
            dhtData              = new DHTData();
            temperatureThreshold = config.TemperatureThreshold;
        }
Beispiel #2
0
 static void ReadSensorsData()
 {
     try
     {
         thermometerTemperature = thermometer.ReadTemperature();
         dhtData = dhtSensor.GetData();
     }
     catch (Exception) { } //reading from DHT sensor randomly throws exceptions...
 }
Beispiel #3
0
        private async void MainPollDHT(GpioPin gpioPin, string Sensor)
        {
            Dht22      dht22   = new Dht22(gpioPin, GpioPinDriveMode.Input);
            DhtReading reading = await dht22.GetReadingAsync().AsTask();

            Debug.WriteLine(string.Format("{0} DHT Valid {1}", Sensor, reading.IsValid));

            if (reading.IsValid)
            {
                Debug.WriteLine(string.Format("{0} DHT Reading:", Sensor));
                Debug.WriteLine(reading.Temperature);
                Debug.WriteLine(reading.Humidity);
                if (Sensor == "Intake")
                {
                    intakeDHTData = (new DHTData()
                    {
                        Temp = reading.Temperature,
                        Hum = reading.Humidity
                    });
                }
                else if (Sensor == "Outtake")
                {
                    outtakeDHTData = (new DHTData()
                    {
                        Temp = reading.Temperature,
                        Hum = reading.Humidity
                    });
                }
                else if (Sensor == "Main")
                {
                    mainDHTData = (new DHTData()
                    {
                        Temp = reading.Temperature,
                        Hum = reading.Humidity
                    });
                }

                System.Threading.Thread.Sleep(1000);
                string cmdString = "INSERT INTO [dbo].[sensorReadings] ([timestamp],[sensor],[temp], [hum], [retryCount]) ";
                cmdString += "VALUES('" + DateTime.Now + "','" + Sensor + "', '" + reading.Temperature + "', '" + reading.Humidity + "', '" + reading.RetryCount + "');";
                cmd        = new SqlCommand(cmdString, myConnection);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException e)
                {
                    Debug.WriteLine(string.Format("Failed SQL- {0}", e.Message.ToString()));
                }
                catch (NullReferenceException e)
                {
                    Debug.WriteLine(string.Format("Failed Bullshit- {0}", e.Message.ToString()));
                }
                catch (InvalidOperationException e)
                {
                    Debug.WriteLine(string.Format("Failed Bullshit- {0}", e.Message.ToString()));
                }
            }
            else
            {
                //Error something here
            }
        }