/// <summary> /// Sends a command to the provided device and updates the command history of the device /// </summary> /// <param name="device">Device to send the command to</param> /// <param name="commandName">Name of the command to send</param> /// <param name="parameters">Parameters to send with the command</param> /// <returns></returns> private async Task <dynamic> SendCommandAsyncWithDevice(dynamic device, string commandName, dynamic parameters) { string deviceId; if (device == null) { throw new ArgumentNullException("device"); } bool canDevicePerformCommand = CommandSchemaHelper.CanDevicePerformCommand(device, commandName); deviceId = DeviceSchemaHelper.GetDeviceID(device); if (!canDevicePerformCommand) { throw new UnsupportedCommandException(deviceId, commandName); } dynamic command = CommandHistorySchemaHelper.BuildNewCommandHistoryItem(commandName); CommandHistorySchemaHelper.AddParameterCollectionToCommandHistoryItem(command, parameters); CommandHistorySchemaHelper.AddCommandToHistory(device, command); await _iotHubRepository.SendCommand(deviceId, command); await _deviceRegistryCrudRepository.UpdateDeviceAsync(device); return(command); }
private static void AssignTelemetry(dynamic device) { dynamic telemetry = CommandSchemaHelper.CreateNewTelemetry("Temperature", "Temperature", "double"); CommandSchemaHelper.AddTelemetryToDevice(device, telemetry); telemetry = CommandSchemaHelper.CreateNewTelemetry("Humidity", "Humidity", "double"); CommandSchemaHelper.AddTelemetryToDevice(device, telemetry); }
protected virtual void InitDeviceInfo(InitialDeviceConfig config) { dynamic initialDevice = SampleDeviceFactory.GetSampleSimulatedDevice(config.DeviceId, config.Key); DeviceProperties = DeviceSchemaHelper.GetDeviceProperties(initialDevice); Commands = CommandSchemaHelper.GetSupportedCommands(initialDevice); HostName = config.HostName; PrimaryAuthKey = config.Key; }
async Task SendCommand(string commandName) { var command = CommandSchemaHelper.CreateNewCommand(commandName); foreach (var partitionKey in this.PartitionKeys()) { await this.iotHubRepository.SendCommand(partitionKey, command); } }
async Task SendCommand(string commandName) { var command = CommandSchemaHelper.CreateNewCommand(commandName); foreach (var partitionKey in _deviceService.GetDeviceIds()) { await _iotHubRepository.SendCommand(partitionKey, command); } }
/// <summary> /// Generates a DeviceInfo packet for a simulated device to send over the wire /// </summary> /// <returns></returns> public virtual dynamic GetDeviceInfo() { dynamic device = DeviceSchemaHelper.BuildDeviceStructure(DeviceID, true); device.DeviceProperties = DeviceSchemaHelper.GetDeviceProperties(this); device.Commands = CommandSchemaHelper.GetSupportedCommands(this); device.Version = SampleDeviceFactory.VERSION_1_0; device.ObjectType = SampleDeviceFactory.OBJECT_TYPE_DEVICE_INFO; return(device); }
private static void AssignCommands(dynamic device) { dynamic command = CommandSchemaHelper.CreateNewCommand("PingDevice"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("StartTelemetry"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("StopTelemetry"); CommandSchemaHelper.AddCommandToDevice(device, command); }
/// <summary> /// Generates a DeviceInfo packet for a simulated device to send over the wire /// </summary> /// <returns></returns> public virtual dynamic GetDeviceInfo() { dynamic device = DeviceSchemaHelper.BuildDeviceStructure(DeviceID, true, null); device.DeviceProperties = DeviceSchemaHelper.GetDeviceProperties(this); device.Commands = CommandSchemaHelper.GetSupportedCommands(this); device.Version = SampleDeviceFactory.VERSION_1_0; device.ObjectType = SampleDeviceFactory.OBJECT_TYPE_DEVICE_INFO; // Remove the system properties from a device, to better emulate the behavior of real devices when sending device info messages. DeviceSchemaHelper.RemoveSystemPropertiesForSimulatedDeviceInfo(device); return(device); }
private static void AssignTelemetry(dynamic device) { dynamic telemetry = CommandSchemaHelper.CreateNewTelemetry("Temperature", "Temperature", "double"); CommandSchemaHelper.AddTelemetryToDevice(device, telemetry); telemetry = CommandSchemaHelper.CreateNewTelemetry("Speed", "Speed", "double"); CommandSchemaHelper.AddTelemetryToDevice(device, telemetry); telemetry = CommandSchemaHelper.CreateNewTelemetry("CameraStatus", "CameraStatus", "bool"); CommandSchemaHelper.AddTelemetryToDevice(device, telemetry); telemetry = CommandSchemaHelper.CreateNewTelemetry("DeviceIp", "DeviceIp", "string"); CommandSchemaHelper.AddTelemetryToDevice(device, telemetry); }
private static void AssignCommands(dynamic device) { dynamic command = CommandSchemaHelper.CreateNewCommand("PingDevice"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("SendBuzzer"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("SendWaypoints"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "data", "string"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("EmergencyStop"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("SetLights"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "data", "boolean"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("SetCameras"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "data", "boolean"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("StartTelemetry"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("StopTelemetry"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("DemoRun"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "data", "int"); CommandSchemaHelper.AddCommandToDevice(device, command); /*command = CommandSchemaHelper.CreateNewCommand("ChangeSetPointTemp"); * CommandSchemaHelper.DefineNewParameterOnCommand(command, "SetPointTemp", "double"); * CommandSchemaHelper.AddCommandToDevice(device, command); * * command = CommandSchemaHelper.CreateNewCommand("DiagnosticTelemetry"); * CommandSchemaHelper.DefineNewParameterOnCommand(command, "Active", "boolean"); * CommandSchemaHelper.AddCommandToDevice(device, command); * * command = CommandSchemaHelper.CreateNewCommand("ChangeDeviceState"); * CommandSchemaHelper.DefineNewParameterOnCommand(command, "DeviceState", "string"); * CommandSchemaHelper.AddCommandToDevice(device, command);*/ }
private static void AssignCommands(dynamic device) { dynamic command = CommandSchemaHelper.CreateNewCommand("PingDevice"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("StartTelemetry"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("StopTelemetry"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("ChangeSetPointTemp"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "SetPointTemp", "double"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("DiagnosticTelemetry"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "Active", "boolean"); CommandSchemaHelper.AddCommandToDevice(device, command); command = CommandSchemaHelper.CreateNewCommand("ChangeDeviceState"); CommandSchemaHelper.DefineNewParameterOnCommand(command, "DeviceState", "string"); CommandSchemaHelper.AddCommandToDevice(device, command); }