NOTES¶
Overview¶
The command module provides MQTT remote control functionality for sensing operations. It allows users to control online and offline sensing through MQTT commands, enabling remote monitoring and control of sensor data acquisition.
Command Format¶
All sensing commands start with SENSE, prefix to distinguish them from other command types.
Command Structure¶
Where: - <TYPE>: ONLINE or OFFLINE - <ACTION>: Command action (e.g., F=, D=, STOP, STATUS) - <PARAMETERS>: Command-specific parameters
Online Sensing Commands¶
Start/Configure Online Sensing¶
F: Sampling frequency in Hz (float, range: 0.1 - 10000 Hz)D: Duration in seconds (float, 0 means continuous operation)
Examples: - SENSE,ONLINE,F=20,D=60 - 20 Hz sampling for 60 seconds - SENSE,ONLINE,F=1,D=0 - 1 Hz sampling, continuous operation
Stop Online Sensing¶
Immediately stops the online sensing operation.
Query Online Sensing Status¶
Returns the current status and configuration of online sensing.
Offline Sensing Commands¶
Immediate Start¶
F: Sampling frequency in Hz (float, range: 1 - 4000 Hz)D: Sampling duration in seconds (float, must be > 0)
Example: - SENSE,OFFLINE,F=100,D=10 - 100 Hz sampling for 10 seconds
Delayed Start¶
DL: Delay time in seconds (integer, >= 0)
Example: - SENSE,OFFLINE,F=100,D=10,DL=5 - Start after 5 seconds, then sample at 100 Hz for 10 seconds
Scheduled Start¶
TIME: Time formatYYMMDDHHMMSS(12 digits)YY: Year (00-99, represents 2000-2099)MM: Month (01-12)DD: Day (01-31)HH: Hour (00-23)MM: Minute (00-59)SS: Second (00-59)
Example: - SENSE,OFFLINE,F=100,D=10,TIME=251216200000 - Start at 2025-12-16 20:00:00
Stop Offline Sensing¶
Stops the offline sensing operation if it is currently running.
Query Offline Sensing Status¶
Returns the current status of offline sensing.
Response Format¶
After command execution, the device publishes a response message via MQTT:
Success Responses¶
SENSE,OK,ONLINE,F=20.00,D=60.00- Online sensing started successfullySENSE,OK,ONLINE,STOPPED- Online sensing stopped successfullySENSE,OK,OFFLINE,F=100.00,D=10.00- Offline sensing started successfullySENSE,OK,OFFLINE,SAMPLES=1000,FREQ=100.00,DUR=10.00,SD=OK- Offline sensing completed
Error Responses¶
SENSE,ERROR,ONLINE,INVALID_FREQ- Invalid frequency parameterSENSE,ERROR,OFFLINE,ALREADY_RUNNING- Offline sensing already in progressSENSE,ERROR,OFFLINE,TIME_PAST- Scheduled time is in the pastSENSE,ERROR,SENSOR_NOT_INITIALIZED- Sensor not initialized
Implementation Details¶
Command Processing Architecture¶
The command handler uses a queue-based architecture:
- Command Queue: Commands are queued for processing to avoid blocking MQTT callback
- Command Processing Task: A dedicated FreeRTOS task processes commands from the queue
- Non-blocking Operations: Long-running operations (like offline sensing) are executed in separate tasks
Parameter Parsing¶
The module includes robust parameter parsing functions:
parse_float_param(): Extracts float parameters (e.g.,F=20.5)parse_int_param(): Extracts integer parameters (e.g.,DL=5)parse_time_param(): Parses time strings inYYMMDDHHMMSSformat
Thread Safety¶
- Commands are processed sequentially through a queue
- Sensor handle is set before processing commands
- State checks prevent concurrent operations
Usage Notes¶
-
Sensor Initialization: The sensor handle must be set using
sensing_command_set_sensor_handle()before processing commands. -
MQTT Connection: MQTT must be connected for command processing and response publishing.
-
Time Synchronization: For scheduled start (
TIMEparameter), system time must be synchronized (NTP). -
Concurrent Operations: The system prevents starting offline sensing while it's already running, but online sensing can be stopped and restarted with new parameters.
-
Command Format: Commands are case-sensitive and must follow the exact format. Extra spaces are automatically trimmed.
Error Handling¶
The command handler validates:
- Command format and structure
- Parameter ranges (frequency, duration, delay)
- System state (sensor initialization, running status)
- Time validity (for scheduled operations)
All errors are reported via MQTT response messages for remote debugging.