|
| 1 | +# Feature Specification: LoRaWAN Commands Management |
| 2 | + |
| 3 | +**Feature ID**: 011 |
| 4 | +**Feature Branch**: `011-lorawan-commands-management` |
| 5 | +**Created**: 2026-02-03 |
| 6 | +**Status**: Draft |
| 7 | +**Source**: Analysis from `specs/011-lorawan-commands-management/analyze.md` |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## User Scenarios & Testing |
| 12 | + |
| 13 | +### User Story 1 - Define Commands for Device Model (Priority: P1) |
| 14 | + |
| 15 | +As an IoT administrator, I need to define reusable command templates for a LoRaWAN device model so that operators can execute standardized commands on any device using that model without needing to know the technical payload details. |
| 16 | + |
| 17 | +**Why this priority**: This is the foundational capability - without command definitions, no command execution is possible. It enables the entire LoRaWAN remote control workflow. |
| 18 | + |
| 19 | +**Independent Test**: Can be fully tested by creating a device model, defining commands with hex payloads and port numbers, and verifying commands are persisted and retrievable. |
| 20 | + |
| 21 | +**Acceptance Scenarios**: |
| 22 | + |
| 23 | +1. **Given** I have a LoRaWAN device model, **When** I define a new command with name, hex frame payload, and LoRaWAN port, **Then** the command is saved and associated with that model. |
| 24 | +2. **Given** a command exists for a device model, **When** I modify the command's frame payload or port, **Then** the changes are persisted. |
| 25 | +3. **Given** I provide an invalid hex frame (odd characters, non-hex values, or >255 characters), **When** I attempt to save the command, **Then** validation errors are displayed. |
| 26 | +4. **Given** I provide a port outside the valid range (1-223), **When** I attempt to save the command, **Then** a port range error is displayed. |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +### User Story 2 - Execute Command on Device (Priority: P1) |
| 31 | + |
| 32 | +As an IoT operator, I need to execute a defined command on a specific LoRaWAN device so that I can remotely control or configure the device without physical access. |
| 33 | + |
| 34 | +**Why this priority**: Command execution is the primary business value - operators need to remotely control devices for operations, configuration changes, and troubleshooting. |
| 35 | + |
| 36 | +**Independent Test**: Can be fully tested by selecting a device, choosing a command, executing it, and observing success/failure feedback. |
| 37 | + |
| 38 | +**Acceptance Scenarios**: |
| 39 | + |
| 40 | +1. **Given** a device with a model that has defined commands, **When** I select and execute a command, **Then** the command is sent to the device and I receive confirmation. |
| 41 | +2. **Given** downlink is disabled on the device model, **When** I attempt to execute a command, **Then** the system prevents execution with an appropriate message. |
| 42 | +3. **Given** the LoRa network server is unavailable, **When** I attempt to execute a command, **Then** I receive an error message indicating the failure. |
| 43 | +4. **Given** I execute a confirmed command, **When** the device acknowledges receipt, **Then** the confirmation status is displayed. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +### User Story 3 - View Commands for Device Model (Priority: P2) |
| 48 | + |
| 49 | +As an IoT administrator, I need to view all commands defined for a device model so that I can audit existing configurations and understand available device capabilities. |
| 50 | + |
| 51 | +**Why this priority**: Visibility into existing commands is essential for ongoing management and troubleshooting, but secondary to creation and execution. |
| 52 | + |
| 53 | +**Independent Test**: Can be fully tested by navigating to a device model's command configuration and verifying the complete list is displayed. |
| 54 | + |
| 55 | +**Acceptance Scenarios**: |
| 56 | + |
| 57 | +1. **Given** a device model with multiple commands, **When** I view the model's command configuration, **Then** all commands are listed with their names, ports, and frame previews. |
| 58 | +2. **Given** a device model with no commands defined, **When** I view the command configuration, **Then** an empty state message is displayed. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### User Story 4 - Manage Built-in Commands (Priority: P3) |
| 63 | + |
| 64 | +As an IoT administrator, I need to understand that certain commands are protected as built-in commands so that I don't accidentally modify critical device functionality. |
| 65 | + |
| 66 | +**Why this priority**: Built-in command protection prevents accidental misconfiguration but is less frequently encountered than general command management. |
| 67 | + |
| 68 | +**Independent Test**: Can be fully tested by attempting to edit or delete a built-in command and verifying the action is blocked. |
| 69 | + |
| 70 | +**Acceptance Scenarios**: |
| 71 | + |
| 72 | +1. **Given** a built-in command exists for a device model, **When** I attempt to edit it, **Then** the edit is prevented and a message explains it's protected. |
| 73 | +2. **Given** a built-in command exists, **When** I attempt to delete it, **Then** the deletion is blocked with an explanation. |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### Edge Cases |
| 78 | + |
| 79 | +- What happens when a device model is deleted that has associated commands? (Commands should be cascade deleted) |
| 80 | +- How does the system handle command execution when the device is offline? (Command is queued for delivery when device reconnects) |
| 81 | +- What happens if two operators execute different commands on the same device simultaneously? (Both commands are queued and executed in order) |
| 82 | +- How are commands handled for devices that have been moved to a different model? (Device inherits new model's commands) |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Requirements |
| 87 | + |
| 88 | +### Functional Requirements |
| 89 | + |
| 90 | +- **FR-001**: System MUST allow defining commands for LoRaWAN device models with name, hex frame payload, and LoRaWAN port |
| 91 | +- **FR-002**: System MUST validate hex frame payloads contain only valid hexadecimal characters (0-9, A-F) with even character count |
| 92 | +- **FR-003**: System MUST validate hex frame payloads do not exceed 255 characters |
| 93 | +- **FR-004**: System MUST validate LoRaWAN port is within the valid range (1-223) |
| 94 | +- **FR-005**: System MUST support both confirmed and unconfirmed downlink modes for command delivery |
| 95 | +- **FR-006**: System MUST encode command payloads to Base64 format for transmission |
| 96 | +- **FR-007**: System MUST prevent modification or deletion of built-in commands |
| 97 | +- **FR-008**: System MUST only allow command execution on devices whose model has downlink enabled |
| 98 | +- **FR-009**: Users MUST be able to view all commands associated with a device model |
| 99 | +- **FR-010**: System MUST provide execution feedback indicating success or failure with error details |
| 100 | +- **FR-011**: System MUST log all command execution attempts with device ID, command name, and result |
| 101 | + |
| 102 | +### Key Entities |
| 103 | + |
| 104 | +- **DeviceModelCommand**: A command template defined at the model level containing: |
| 105 | + - Name (descriptive command identifier) |
| 106 | + - Frame (hexadecimal payload data) |
| 107 | + - Port (LoRaWAN port number 1-223) |
| 108 | + - Confirmed (boolean for delivery confirmation requirement) |
| 109 | + - IsBuiltin (boolean for system-protected commands) |
| 110 | + - DeviceModelId (association to parent model) |
| 111 | + |
| 112 | +- **Command Execution Request**: Runtime data for executing a command: |
| 113 | + - Device identifier (target device) |
| 114 | + - Command identifier (which command to execute) |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## Success Criteria |
| 119 | + |
| 120 | +### Measurable Outcomes |
| 121 | + |
| 122 | +- **SC-001**: Administrators can define a new command for a device model in under 2 minutes |
| 123 | +- **SC-002**: Operators can execute a command on a device with confirmation within 5 seconds (network dependent) |
| 124 | +- **SC-003**: 95% of command executions complete successfully on first attempt (when device is reachable) |
| 125 | +- **SC-004**: Reduce manual on-site device configuration visits by 80% through remote command execution |
| 126 | +- **SC-005**: 100% of command execution attempts are logged for audit purposes |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Traceability |
| 131 | + |
| 132 | +### Source Analysis |
| 133 | +- **Analysis Path**: `specs/011-lorawan-commands-management/analyze.md` |
| 134 | +- **Analyzed By**: excavator.specifier |
| 135 | + |
| 136 | +### Code References |
| 137 | +- LoRaWANCommandsController: Command CRUD operations |
| 138 | +- LoRaWANDevicesController: Command execution endpoint |
| 139 | +- LoRaWANCommandService: Business logic for command management |
| 140 | +- LoRaWanManagementService: Network server integration |
| 141 | + |
| 142 | +### Dependencies |
| 143 | +- **Depends On**: |
| 144 | + - 009-lorawan-device-model-management (commands are defined at model level) |
| 145 | + - 008-lorawan-device-management (commands are executed on devices) |
| 146 | +- **Depended By**: |
| 147 | + - 026-planning-command-jobs (scheduled command execution) |
0 commit comments