private async Task InvokeRebootCommandAsync() { const int delay = 1; const string rebootCommandName = "reboot"; _logger.LogDebug($"Invoke the {rebootCommandName} command on the {_digitalTwinId} digital twin." + $"\nThis will set the \"targetTemperature\" on \"Thermostat\" component to 0."); try { HttpOperationResponse <DigitalTwinCommandResponse, DigitalTwinInvokeCommandHeaders> invokeCommandResponse = await _digitalTwinClient .InvokeCommandAsync(_digitalTwinId, rebootCommandName, JsonConvert.SerializeObject(delay)); _logger.LogDebug($"Command {rebootCommandName} was invoked on the {_digitalTwinId} digital twin." + $"\nDevice returned status: {invokeCommandResponse.Body.Status}."); } catch (HttpOperationException e) { if (e.Response.StatusCode == HttpStatusCode.NotFound) { _logger.LogWarning($"Unable to execute command {rebootCommandName} on {_digitalTwinId}." + $"\nMake sure that the device sample TemperatureController located in {DeviceSampleLink} is also running."); } } }
private async Task InvokeGetMaxMinReportCommandAsync() { DateTimeOffset since = DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(2)); const string getMaxMinReportCommandName = "getMaxMinReport"; _logger.LogDebug($"Invoke the {getMaxMinReportCommandName} command on {_digitalTwinId} digital twin."); try { HttpOperationResponse <DigitalTwinCommandResponse, DigitalTwinInvokeCommandHeaders> invokeCommandResponse = await _digitalTwinClient .InvokeCommandAsync(_digitalTwinId, getMaxMinReportCommandName, JsonConvert.SerializeObject(since)); _logger.LogDebug($"Command {getMaxMinReportCommandName} was invoked. \nDevice returned status: {invokeCommandResponse.Body.Status}." + $"\nReport: {invokeCommandResponse.Body.Payload}"); } catch (HttpOperationException e) { if (e.Response.StatusCode == HttpStatusCode.NotFound) { _logger.LogWarning($"Unable to execute command {getMaxMinReportCommandName} on {_digitalTwinId}." + $"\nMake sure that the device sample Thermostat located in " + $"https://github.com/Azure-Samples/azure-iot-samples-csharp/tree/master/iot-hub/Samples/device/PnpDeviceSamples/Thermostat " + $"is also running."); } } }