/// <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."); }
static void Main(string[] args) { //Console.Write(DateTime.Now.ToString("yyyy/MM/dd")); //Console.ReadLine(); //return; IoTHubConnector connector = new IoTHubConnector(); connector.StartService(); Console.ReadLine(); connector.StopService(); }
private async void Timer_Tick(object sender, object e) { //CurrentTemperature = IoTPiHelper.GetInstance().GetTemperature(); await IoTHubConnector.GetInstance().SendDataToAzure(new Model.RealTimeUnit() { DeviceID = "1", SensorName = "AmbientTemperature", SensorValue = CurrentTemperature, Timestamp = DateTime.Now }); //CurrentHumidity = IoTPiHelper.GetInstance().GetHumidity(); await IoTHubConnector.GetInstance().SendDataToAzure(new Model.RealTimeUnit() { DeviceID = "1", SensorName = "AmbientHumidity", SensorValue = CurrentHumidity, Timestamp = DateTime.Now }); }