Ejemplo n.º 1
0
        private static void SensorTimerTick(object state)
        {
            // Read sensor data: al
            double al = apds.ReadAmbientLight();

            // Read sensor data: bme
            double derece  = bme.ReadTemperature();
            double nem     = bme.ReadHumidity();
            double basinc  = bme.ReadPressure();
            double UVIndex = veml.Calculate_Average_UV_Index();

            // Create telemetry instance to store sensor data
            Telemetry telemetry = new Telemetry();

            telemetry.AmbientLight = Math.Round(al, 2);
            telemetry.Temperature  = Math.Round(derece, 2);
            telemetry.Humidity     = Math.Round(nem, 2);
            telemetry.Pressure     = Math.Round(basinc, 2);
            telemetry.UVIndex      = Math.Round(UVIndex, 2);

            // Set Measurement Time
            DateTime localDate = DateTime.Now;

            //string utcFormat = localDate.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
            telemetry.DateTime = TimeZoneInfo.ConvertTime(localDate.ToUniversalTime(), TimeZoneInfo.Local).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");

            // Ex: Get GTB Standard Time zone - (GMT+02:00) Athens, Istanbul, Minsk
            //TimeZoneInfo SystemTimeZoneId = TimeZoneInfo.FindSystemTimeZoneById("GTB Standard Time");
            //DateTime LocalTime = TimeZoneInfo.ConvertTime(localDate, TimeZoneInfo.Local, SystemTimeZoneId);
            //Debug.WriteLine("LocalTime: " + LocalTime);

            // Write sensor data to output / immediate window
            Debug.WriteLine("Date Time: " + telemetry.DateTime);
            Debug.WriteLine("Ambient Light: " + telemetry.AmbientLight.ToString());
            Debug.WriteLine("Temperature: " + telemetry.Temperature.ToString());
            Debug.WriteLine("Humidity: " + telemetry.Humidity.ToString());
            Debug.WriteLine("Pressure: " + telemetry.Pressure.ToString());

            Debug.WriteLine("- - - - - - - - - - - - -");

            // Write sensor data to output / immediate window
            Debug.WriteLine("UVA........: " + veml.Read_RAW_UVA().ToString());
            Debug.WriteLine("UVB........: " + veml.Read_RAW_UVB().ToString());
            Debug.WriteLine("UVA Index..: " + veml.Calculate_UV_Index_A().ToString());
            Debug.WriteLine("UVB Index..: " + veml.Calculate_UV_Index_B().ToString());
            Debug.WriteLine("UV Index...: " + telemetry.UVIndex.ToString());
            count = count + 1;
            Debug.WriteLine("Sıra: " + count);
            Debug.WriteLine("--------------------------");

            // Convert telemetry JSON to string
            string telemetryJSON = JsonConvert.SerializeObject(telemetry);

            // Send data to IoT Hub
            SendDeviceToCloudMessageAsync(telemetryJSON);
        }
Ejemplo n.º 2
0
 private static void SensorTimerTick(object state)
 {
     // Write sensor data to output / immediate window
     Debug.WriteLine("UVA........: " + veml.Read_RAW_UVA().ToString());
     Debug.WriteLine("UVB........: " + veml.Read_RAW_UVB().ToString());
     Debug.WriteLine("UVA Index..: " + veml.Calculate_UV_Index_A().ToString());
     Debug.WriteLine("UVB Index..: " + veml.Calculate_UV_Index_B().ToString());
     Debug.WriteLine("UV Index...: " + veml.Calculate_Average_UV_Index().ToString());
     Debug.WriteLine("-----");
 }
Ejemplo n.º 3
0
        static void SensorTimerTick(object state)
        {
            // BME280 Sensöründen sıcaklığı oku
            double sicaklik = bme.ReadTemperature();

            // Sıcaklığı yaz
            Debug.WriteLine(sicaklik.ToString("0.000"));

            // VEML6075 Sensöründen UV Index'ini oku
            double uvindex = veml.Calculate_Average_UV_Index();

            // UV Index'i yaz
            Debug.WriteLine(uvindex.ToString("0.000"));
        }
Ejemplo n.º 4
0
        static async void SensorTimerTick(object state)
        {
            // BME280 Sensöründen sıcaklığı oku
            double sicaklik = bme.ReadTemperature();

            // Sıcaklığı yaz
            Debug.WriteLine(sicaklik.ToString("0.000"));

            // VEML6075 Sensöründen UV Index'ini oku
            double uvindex = veml.Calculate_Average_UV_Index();

            // UV Index'i yaz
            Debug.WriteLine(uvindex.ToString("0.000"));

            // 4. Giriş / Çıkış Portundan analog girişi oku
            double toprakNemi = gc.ReadAnalogInput(4, false);

            // Analog değeri yaz
            Debug.WriteLine(toprakNemi.ToString("0.000"));

            // Toprak nemine göre su pompasını aç ya da kapat
            if (toprakNemi > 0.5) // Toprak kuruysa
            {
                // Röleyi aktifleştir: Pompa çalışır.
                role.SetRelay(2, true);
            }
            else // Toprak nemliyse
            {
                // Röleyi pasifleştir: Pompa çalışmaz.
                role.SetRelay(2, false);
            }

            // Azure IoT Hub'a gönderilecek verileri saklayan Telemetri sınıfını oluştur
            Telemetri telemetri = new Telemetri();

            telemetri.toprakNemi = toprakNemi;
            telemetri.sicaklik   = sicaklik;
            telemetri.uvindex    = uvindex;

            // Telemetri sınıfını JSON cümlesine çevir
            string telemetriJSON = JsonConvert.SerializeObject(telemetri);

            // Verileri Azure IoT Hub'a gönder
            await AzureIoTHub.SendDeviceToCloudMessageAsync(telemetriJSON);
        }