private static void ActionTemperatureAlert(AlarmMessage alarmMessage) { WriteHighlightedMessage( GetDeviceIdHint(alarmMessage.ioTHubDeviceID) + "[" + alarmMessage.createdAt + "]" + " TempAlert! Temp=" + alarmMessage.reading + ", Threshold=" + alarmMessage.threshold, ConsoleColor.Yellow); /* Action 1: Send Cloud-to-Device command */ C2DCommand c2dCommand = new C2DCommand(); c2dCommand.command = C2DCommand.COMMAND_TEMPERATURE_ALERT; c2dCommand.value = alarmMessage.reading; c2dCommand.time = alarmMessage.createdAt; SendCloudToDeviceCommand( _serviceClient, alarmMessage.ioTHubDeviceID, c2dCommand).Wait(); /* Action 2: Send to Web dashboard */ //string webSCResult = _webSC.PostTelemetryAlarm(alarmMessage); //Console.WriteLine(webSCResult); }
private static void ActionEnableDevice(string ioTHubDeviceID, string on, string time) { WriteHighlightedMessage( GetDeviceIdHint(ioTHubDeviceID) + " WindTurbine Enable=" + on + ", Time=" + time, ConsoleColor.Green); C2DCommand c2dCommand = new C2DCommand(); c2dCommand.command = C2DCommand.COMMAND_TURN_ONOFF; c2dCommand.value = on; c2dCommand.time = time; SendCloudToDeviceCommand( _serviceClient, ioTHubDeviceID, c2dCommand).Wait(); }
private static void ActionResetDepreciationWindows(string ioTHubDeviceID, string time) { WriteHighlightedMessage( GetDeviceIdHint(ioTHubDeviceID) + " Depreciation Reset!" + ", Time=" + time, ConsoleColor.Cyan); C2DCommand c2dCommand = new C2DCommand(); c2dCommand.command = C2DCommand.COMMAND_RESET_DEPRECIATION; c2dCommand.value = "1";// set it to 100% c2dCommand.time = time; SendCloudToDeviceCommand( _serviceClient, ioTHubDeviceID, c2dCommand).Wait(); }
private static void ProcessAlarmMessage(AlarmMessage alarmMessage) { WriteHighlightedMessage( alarmMessage.IoTHubDeviceID + " - AvgLight=" + alarmMessage.AvgLight + ", WinStartTime=" + alarmMessage.WinStartTime + ", WinEndTime=" + alarmMessage.WinEndTime, ConsoleColor.Yellow); C2DCommand c2dCommand = new C2DCommand(); c2dCommand.command = C2DCommand.COMMAND_LIGHT_WARNING; c2dCommand.value = alarmMessage.AvgLight; c2dCommand.time = alarmMessage.WinEndTime; SendCloudToDeviceCommand( _serviceClient, alarmMessage.IoTHubDeviceID, c2dCommand).Wait(); }
private static void ActionCutOutSpeedWindows(AlarmMessage alarmMessage) { WriteHighlightedMessage( GetDeviceIdHint(alarmMessage.ioTHubDeviceID) + " CutOutSpeed! Speed=" + alarmMessage.reading + ", MessageID=" + alarmMessage.messageID + ", Threshold=" + alarmMessage.threshold, ConsoleColor.Yellow); C2DCommand c2dCommand = new C2DCommand(); c2dCommand.command = C2DCommand.COMMAND_CUTOUT_SPEED_WARNING; c2dCommand.value = alarmMessage.messageID; c2dCommand.time = alarmMessage.createdAt; SendCloudToDeviceCommand( _serviceClient, alarmMessage.ioTHubDeviceID, c2dCommand).Wait(); }
private static void ActionRepairWindows(AlarmMessage alarmMessage) { WriteHighlightedMessage( GetDeviceIdHint(alarmMessage.ioTHubDeviceID) + " Repair! Depreciation=" + alarmMessage.reading + ", MessageID=" + alarmMessage.messageID + ", Threshold=" + alarmMessage.threshold, ConsoleColor.Red); C2DCommand c2dCommand = new C2DCommand(); c2dCommand.command = C2DCommand.COMMAND_REPAIR_WARNING; c2dCommand.value = alarmMessage.messageID; c2dCommand.time = alarmMessage.createdAt; SendCloudToDeviceCommand( _serviceClient, alarmMessage.ioTHubDeviceID, c2dCommand).Wait(); }
private async static Task SendCloudToDeviceCommand(ServiceClient serviceClient, String deviceId, C2DCommand command) { var commandMessage = new Message(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(command))); await serviceClient.SendAsync(deviceId, commandMessage); }