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); }
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("-----"); }