private static void Main(string[] args)
        {
            ConsoleHelper.WriteColorMessage("Cheese Cave device app.\n", ConsoleColor.Yellow);

            // Connect to the IoT hub using the MQTT protocol.
            deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Mqtt);

            // Create an instance of the Cheese Cave Simulator
            cheeseCave = new CheeseCaveSimulator();

            // INSERT register direct method code below here
            // Create a handler for the direct method call
            deviceClient.SetMethodHandlerAsync("SetFanState", SetFanState, null).Wait();

            // INSERT register desired property changed handler code below here
            // Get the device twin to report the initial desired properties.
            Twin deviceTwin = deviceClient.GetTwinAsync().GetAwaiter().GetResult();

            ConsoleHelper.WriteGreenMessage("Initial twin desired properties: " + deviceTwin.Properties.Desired.ToJson());

            // Set the device twin update callback.
            deviceClient.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertyChanged, null).Wait();

            SendDeviceToCloudMessagesAsync();
            Console.ReadLine();
        }
Beispiel #2
0
        // This application is very similar to the simulated device applications
        // that you have worked on in the preceding labs. This version uses
        // symmetric Key authentication, sends both telemetry and logging
        // messages to the IoT Hub, and has a more complex sensor implementation.
        private static async Task Main(string[] args)
        {
            ConsoleHelper.WriteColorMessage("Cheese Cave device app.\n", ConsoleColor.Yellow);

            // Connect to the IoT hub using the MQTT protocol.
            deviceClient = DeviceClient.CreateFromConnectionString(
                deviceConnectionString,
                TransportType.Mqtt);

            // Create an instance of the Cheese Cave Simulator
            cheeseCave = new CheeseCaveSimulator();

            // Create a handler for the direct method call
            // Notice that the SetFanState direct method handler is also set
            // up by this code. As you can see, the SetMethodHandlerAsync
            // method of deviceClient takes the remote method name `"SetFanState"`
            // as an argument, along with the actual local method to call, and a
            // user context object (in this case null)

            // UNCOMMENT register direct method code below here
            //await deviceClient.SetMethodHandlerAsync("SetFanState", SetFanState, null);

            // UNCOMMENT register desired property changed handler code below here
            // // Get the device twin to report the initial desired properties.
            // Twin deviceTwin = await deviceClient.GetTwinAsync();
            // ConsoleHelper.WriteGreenMessage("Initial twin desired properties: " + deviceTwin.Properties.Desired.ToJson());

            // // Set the device twin update callback.
            // await deviceClient.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertyChanged, null);

            await SendDeviceToCloudMessagesAsync();

            Console.ReadLine();
        }
Beispiel #3
0
        private static void Main(string[] args)
        {
            ConsoleHelper.WriteColorMessage("Cheese Cave device app.\n", ConsoleColor.Yellow);

            // Connect to the IoT hub using the MQTT protocol.
            deviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Mqtt);

            // Create an instance of the Cheese Cave Simulator
            cheeseCave = new CheeseCaveSimulator();

            // INSERT register direct method code below here

            // INSERT register desired property changed handler code below here

            SendDeviceToCloudMessagesAsync();
            Console.ReadLine();
        }