Example #1
0
        // sendstatus=false;
        private async void SendDeviceToCloudMessagesAsync(string status, BMP280SensorData BMP280SensorData, MCP3008SensorData MCP3008SensorData)
        {
            ConferenceRoomDataPoint conferenceRoomDataPoint = new ConferenceRoomDataPoint()
            {
                DeviceId             = deviceName,
                Time                 = DateTime.UtcNow.ToString("o"),
                RoomTemp             = BMP280SensorData.Temperature.ToString(),
                RoomPressure         = BMP280SensorData.Pressure.ToString(),
                RoomAlt              = BMP280SensorData.Altitude.ToString(),
                LightStatus          = MCP3008SensorData.lightStatus,
                LightCDSValue        = MCP3008SensorData.cdsReadVal.ToString(),
                LightCDSVoltageValue = MCP3008SensorData.cdsVoltage.ToString(),
                RoomStatus           = status
            };

            if (status == "Occupied")
            {
                conferenceRoomDataPoint.Color = "Red";
            }
            else
            {
                conferenceRoomDataPoint.Color = "Green";
            }

            var jsonString        = JsonConvert.SerializeObject(conferenceRoomDataPoint);
            var jsonStringInBytes = new Message(Encoding.ASCII.GetBytes(jsonString));

            await deviceClient.SendEventAsync(jsonStringInBytes);

            Debug.WriteLine("{0} > Sending message: {1}", DateTime.UtcNow, jsonString);
        }
Example #2
0
        private async Task <BMP280SensorData> ReadBMP280SensorData()
        {
            var sensorData = new BMP280SensorData();

            try
            {
                //Create a constant for pressure at sea level.
                //This is based on your local sea level pressure (Unit: Hectopascal)
                const float seaLevelPressure = 1013.25f;

                sensorData.Temperature = await BMP280.ReadTemperature();

                sensorData.Pressure = await BMP280.ReadPreasure();

                sensorData.Altitude = await BMP280.ReadAltitude(seaLevelPressure);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(sensorData);
        }