/// <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 ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings); await ioTHubModuleClient.OpenAsync(); var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); await IoTDevice.InitDevice(ioTHubModuleClient, loggerFactory); }
public async static Task <IoTDevice> InitDevice(ModuleClient client, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger("DeviceLogger"); var device = new IoTDevice(client, logger); logger.LogInformation("IoT Hub module client initialized."); await client.SetMethodHandlerAsync("reset", device.ResetMethod, null); await client.SetMethodHandlerAsync("takephoto", device.TakePhoto, null); await device.SendDeviceData(client); return(device); }