Command Response Documentation
June 4, 2025 ยท View on GitHub
ESP RainMaker provides a Command Response feature (Beta) that allows you to send commands to your nodes and retrieve their responses. This is particularly useful for custom device operations that aren't covered by standard parameters.
Overview
The Command Response feature involves:
- Creating a command request with a specific command ID and data
- Sending this request to one or more nodes
- Retrieving the responses from those nodes
Commands
Creating a Command Request
esp-rainmaker-cli create_cmd_request <nodes> <cmd> <data> [--timeout <seconds>]
Where:
nodesis a comma-separated list of node IDs (up to 25)cmdis a numeric command IDdatais a JSON string containing the command data--timeout(optional) is the time in seconds until the command request expires (default: 30)
Example:
esp-rainmaker-cli create_cmd_request 686725E6AA20 4096 '{"brightness":50}' --timeout 60
The command will return:
- A request ID (used to retrieve responses)
- Initial responses indicating that the command is in progress
Getting Command Responses
esp-rainmaker-cli get_cmd_requests <request_id> [options]
Where:
request_idis the ID returned from the create_cmd_request command
Options:
--node_id- Filter responses for a specific node--start_id- Start ID for pagination--num_records- Number of records to retrieve
Example:
esp-rainmaker-cli get_cmd_requests EQPf7Rj7HFiBhFhvNMjLaB
Command Response Process in Detail
Creating a Command Request
-
Prepare your command data:
- Identify the target nodes
- Determine the command ID (this is application-specific)
- Format your command data as a JSON string
-
Send the command request:
esp-rainmaker-cli create_cmd_request 686725E6AA20 4096 '{"brightness":50}' --timeout 60 -
Note the request ID returned:
Request Id: EQPf7Rj7HFiBhFhvNMjLaB -
Check initial responses:
Responses: [{'node_ids': ['686725E6AA20'], 'response': {'status': 'success', 'description': 'in_progress'}}]
Getting Command Responses
-
Query for responses using the request ID:
esp-rainmaker-cli get_cmd_requests EQPf7Rj7HFiBhFhvNMjLaB -
Review the response data:
Requests: [{'node_id': '686725E6AA20', 'request_id': 'EQPf7Rj7HFiBhFhvNMjLaB', 'request_timestamp': 1748871366, 'response_timestamp': 1748871367, 'response_data': {'status': 'success'}, 'request_data': {'brightness': 50}, 'status': 'success', 'device_status': 0, 'expiration_timestamp': 1748871426, 'cmd': 4096}] -
Check status and response data:
status: Overall status of the commandresponse_data: Specific response from the nodedevice_status: Numeric status code from the device
Response Structure
The command response includes:
node_id: ID of the node that respondedrequest_id: ID of the original requestrequest_timestamp: Time when the request was sentresponse_timestamp: Time when the response was receivedrequest_data: Original command dataresponse_data: Response data from the nodestatus: Status of the command (success, failure, etc.)device_status: Numeric status code from the deviceexpiration_timestamp: Time when the request will expirecmd: Original command ID
Examples of Common Use Cases
Sending a Custom Command to a Light
# Set brightness to 75%
esp-rainmaker-cli create_cmd_request abcd1234 4096 '{"brightness":75}'
# Get the response
esp-rainmaker-cli get_cmd_requests <request_id_from_above>
Sending Commands to Multiple Nodes
# Turn off multiple lights
esp-rainmaker-cli create_cmd_request abcd1234,efgh5678 2048 '{"power":false}'
# Get responses for a specific node
esp-rainmaker-cli get_cmd_requests <request_id_from_above> --node_id abcd1234
Setting a Longer Timeout
# Command with 2-minute timeout for operations that take longer
esp-rainmaker-cli create_cmd_request abcd1234 8192 '{"update_config":true}' --timeout 120
Best Practices
- Use appropriate timeouts: Set timeouts based on expected operation time
- Check responses promptly: Commands might complete before the timeout expires
- Handle errors gracefully: Check status codes and response data for errors
- Unique command IDs: Use unique command IDs for different operations
- Limit batch size: Keep the number of nodes in a single request reasonable (max 25)
Notes
- This feature is currently in Beta
- Command IDs and data formats are specific to your device implementation
- The maximum timeout value is application-dependent
- Response data may vary based on the device's implementation