/// <summary> /// Initializes the ModuleClient and sets up the callback to receive /// messages containing temperature information /// </summary> static async Task Init() { AmqpTransportSettings amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only); ITransportSettings[] settings = { amqpSetting }; // Open a connection to the Edge runtime ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings); await ioTHubModuleClient.OpenAsync(); Console.WriteLine("IoT Hub module client initialized."); var moduleTwin = await ioTHubModuleClient.GetTwinAsync(); var moduleTwinCollection = moduleTwin.Properties.Desired; desiredPropertiesData = new DesiredPropertiesData(moduleTwinCollection); // callback for updating desired properties through the portal or rest api await ioTHubModuleClient.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertiesUpdate, null); // this direct method will allow to reset the temperature sensor values back to their initial state //await ioTHubModuleClient.SetMethodHandlerAsync("reset", ResetMethod, null); // Register callback to be called when a message is received by the module //await ioTHubModuleClient.SetInputMessageHandlerAsync("input1", PipeMessage, ioTHubModuleClient); // as this runs in a loop we don't await await SendSimulationData(ioTHubModuleClient); Console.WriteLine("Simulating data..."); }
private static Task OnDesiredPropertiesUpdate(TwinCollection twinCollection, object userContext) { desiredPropertiesData = new DesiredPropertiesData(twinCollection); return(Task.CompletedTask); }