/// <summary>
        /// Initializes the ModuleClient and sets up the callback to receive
        /// messages containing temperature information
        /// </summary>
        static async Task Init()
        {
            MqttTransportSettings mqttSetting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);

            ITransportSettings[] settings = { mqttSetting };

            // Open a connection to the Edge runtime
            grovePiPlus           = new GrovePiPlus(1);
            ledButtonDevice       = new GrovePiPlusBlueLEDButton(grovePiPlus, 4, 5);
            barometerSensorDevice = new BarometerBME280(1);
            barometerSensorDevice.Initialize();
#if USE_LIGHT_SENSE
            lightSensor = new GrovePiLightSensor(grovePiPlus, 0);
#endif
#if USE_CO2_SENSE
            co2Sensor = new CO2SensorMHZ19B();
#endif
            Console.WriteLine("Sensing Device Initialized");

            iotHubConnector     = new ModuleClientConnector(settings, "command-input", "telemetry-output");
            sensingDeviceClient = new EnvironmentSensingDeviceClient(iotHubConnector, barometerSensorDevice, ledButtonDevice, lightSensor, co2Sensor);

            var tokenSource = new CancellationTokenSource();
            var ct          = tokenSource.Token;
            await sensingDeviceClient.Initialize(ct);

            Console.WriteLine("IoT Hub module client initialized.");
        }
예제 #2
0
        public EnvironmentSensingDeviceClient(EG.IoT.Utils.IoTHubConnector connector, BarometerBME280 sensor, GrovePiPlusBlueLEDButton ledButton, GrovePiLightSensor lightSensor, CO2SensorMHZ19B co2Sensor)
        {
            iothubClient      = connector;
            envSensorDevice   = sensor;
            ledButtonDevice   = ledButton;
            lightSensorDevice = lightSensor;
            co2SensorDevice   = co2Sensor;

            telemetryConfig = new TelemetryConfig()
            {
                telemetryCycleMSec   = 1000,
                temperatureAvailable = true,
                humidityAvailable    = true,
                pressureAvailable    = true,
                lightSenseAvailable  = (lightSensor != null),
                co2SensorAvailable   = (co2Sensor != null)
            };
        }