MEASUREMENT MODULE¶
Overview
The TinySHM Measurement Module provides comprehensive sensor data acquisition functionality for structural health monitoring and IoT applications. Four major components are:
- Online Sensing: Real-time continuous data streaming with MQTT, serial, and LCD output
- Offline Sensing: High-frequency batch data collection with memory buffer and SD card storage
- Real-Time Processing: On-device computation and feature extraction with three architecture options
- Command Control: MQTT-based remote control and monitoring
The module features flexible sampling rates, multiple storage options, and remote control capabilities.
Core Features¶
Online Sensing¶
The online sensing module provides continuous, real-time sensor data acquisition and transmission.
Key Features:
- Configurable sampling rate: 0.1 - 300 Hz (practical limit: ~200 Hz)
- Multiple output channels: MQTT, Serial, and optional LCD display
- High-precision timing: ESP timer-based with microsecond accuracy
- Runtime configuration: Update sampling frequency without restart
- Automatic data formatting: Compact CSV format for efficient transmission
- Thread-safe operation: Safe for concurrent access
- Auto-stop support: Optional duration-based automatic stopping
Applications: Real-time monitoring, live data visualization, continuous surveillance
Offline Sensing¶
The offline sensing module provides high-frequency, time-stamped data collection with reliable storage.
Key Features:
- High-frequency sampling: Up to 4000 Hz (limited by sensor ODR, e.g., ADXL355)
- Configurable duration: 0.1 - 3600 seconds (limited by PSRAM memory)
- Memory constraints: Duration limited by PSRAM size
- At 4000 Hz: ~87 seconds theoretical limit (tested up to 80 seconds)
- At 100 Hz: ~3480 seconds (~58 minutes) theoretical limit
- Multiple storage options:
- Memory buffer (PSRAM-based for large datasets)
- SD card storage (CSV format with automatic naming)
- MQTT report after completion
- Precise timing: ESP timer with microsecond timestamp accuracy
- Delayed and scheduled start: Support for countdown and absolute time scheduling
- Automatic file naming: Timestamp and parameter-based filenames
- Memory pre-check: Validates available memory before starting
Applications: High-frequency vibration analysis, transient event capture, detailed waveform recording
Real-Time Sensing and Processing¶
The real-time sensing and processing module provides sensor data acquisition with real-time computation and feature extraction. This module enables on-device processing during data acquisition, making it ideal for edge AI applications and real-time detection scenarios.
Key Features:
- Three Architecture Options:
- Architecture 1 (Producer-Consumer): Simple queue-based architecture with circular buffer (0.1 - 1000 Hz, recommended: 100 Hz - 1 kHz)
- Architecture 2 (DMA + Double Buffer): DMA-accelerated double buffering with multi-task support (0.1 - 10000 Hz, recommended: 1 kHz - 10 kHz)
- Architecture 3 (DMA + Dual Core): Dual-core parallel processing with DMA acceleration (0.1 - 10000 Hz, highest performance)
- Compile-time Architecture Selection: Select architecture via
RT_PROCESS_ARCH_TYPEmacro - Real-time Data Processing: Feature extraction and computation during acquisition
- Unified API Interface: Same API for all architectures, easy to switch
- Performance Statistics: Comprehensive monitoring (acquisition time, processing time, dropped samples)
- Configurable Sampling Frequency: Runtime frequency updates supported
- Multiple Output Channels: MQTT, Serial, LCD (with acceleration detection feedback)
- Acceleration Detection: Real-time condition detection with LCD visual feedback
Applications: Real-time feature extraction, on-device computation, edge AI processing, real-time anomaly detection
Relationship with Other Modules:
-
vs Online Sensing: Adds real-time processing capability; Online Sensing focuses on raw data streaming
-
vs Offline Sensing: Real-time processing vs batch collection; Offline Sensing is for post-processing analysis
Remote Command Control¶
The command module provides MQTT-based remote control and monitoring functionality.
Key Features:
- Unified command interface: Simple
SENSE,ONLINE/SENSE,OFFLINEformat - Online sensing control:
- Start/stop with configurable frequency and duration
- Status query and runtime parameter updates
- Auto-stop after specified duration
- Offline sensing control:
- Immediate, delayed, or scheduled start
- Time-based scheduling (YYMMDDHHMMSS format)
- Real-time status monitoring
- Queue-based processing: Non-blocking command handling
- Comprehensive error reporting: Detailed MQTT response messages
Applications: Remote monitoring, automated data collection, IoT deployments
Architecture¶
Module Architecture Overview¶
The measurement module consists of four main components, each optimized for different use cases:
- Online Sensing: Timer-driven, single-task architecture for real-time streaming
- Offline Sensing: Timer-driven, two-phase architecture (collection then storage)
- Real-Time Processing: Multi-task architectures with three options for different performance needs
- Command Control: Queue-based, non-blocking command processing
Timer-Driven Design¶
- ESP Timer: Hardware-accelerated, high-precision timing with microsecond accuracy
- Event-Based: Efficient, interrupt-driven sampling
- Minimal Overhead: Optimized callback execution
- Used By: Online Sensing, Offline Sensing, Real-Time Processing (timer triggers)
Multi-Task Architectures¶
- Producer-Consumer Pattern: Decoupled acquisition and processing (Architecture 1)
- Double Buffer (Ping-Pong): Parallel acquisition and processing (Architecture 2)
- Dual Core Division: True parallelism with core pinning (Architecture 3)
- Synchronization: Mutexes, semaphores, and queues for thread-safe operation
Storage Options¶
- PSRAM Support: Large memory buffers for high-frequency sampling
- SD Card Integration: Reliable file-based storage
- MQTT Streaming: Real-time data transmission
- Circular Buffers: Historical data access for real-time processing
Hardware Integration¶
- Sensor-Independent API: Supports integration with different sensors
- Driver Interface: Standardized sensor communication
- Current Support: ADXL355 accelerometer (example implementation)
- DMA Support: Automatic DMA for SPI transfers (Architecture ⅔)
Technical Specifications¶
| Feature | Online Sensing | Offline Sensing | Real-Time Processing |
|---|---|---|---|
| Sampling Frequency | 0.1 - 300 Hz | 1 - 4000 Hz | Architecture 1: 0.1 - 1000 Hz Architecture ⅔: 0.1 - 10000 Hz |
| Practical Limit | ~200 Hz (MQTT constrained) | 4000 Hz (sensor ODR) | Architecture 1: 1 kHz Architecture ⅔: 10 kHz |
| Default Frequency | 1.0 Hz | 100 Hz | 100 Hz |
| Duration Range | 0 (continuous) - unlimited | 0.1 - 3600 seconds (limited by PSRAM: ~87s at 4000Hz) | Continuous (no duration limit) |
| Storage | Real-time streaming | Memory buffer + SD card | Real-time processing + output |
| Processing | None | None (post-processing) | Real-time computation |
| Architecture Options | Single (timer-based) | Single (timer-based) | Three (Producer-Consumer, DMA+Double Buffer, DMA+Dual Core) |
| Timing Accuracy | Microsecond precision | Microsecond precision | Microsecond precision |
| Output Format | CSV (compact) | CSV (with headers) | Processed data + features |
| Output Channels | MQTT, Serial, LCD | MQTT report, SD card | MQTT, Serial, LCD |
| Remote Control | MQTT commands | MQTT commands | Runtime API |
Use Cases¶
Structural Health Monitoring¶
- Continuous vibration monitoring (Online Sensing)
- High-frequency impact detection (Offline Sensing)
- Real-time anomaly detection (Real-Time Processing)
- Scheduled periodic measurements (Command Control)
IoT Data Collection¶
- Real-time sensor streaming to cloud platforms (Online Sensing)
- Batch data collection for analysis (Offline Sensing)
- Edge AI processing with real-time feedback (Real-Time Processing)
- Remote configuration and control (Command Control)
Research and Development¶
- Flexible sampling rate for various experiments
- Precise timing for signal analysis
- Reliable data storage for post-processing
- Real-time algorithm development and testing
Important Notes¶
Hardware Dependency
The measurement module depends on specific hardware sensors. In this project, we use the ADXL355 accelerometer as an example, which requires the corresponding driver (node_acc_adxl355). When developing your own measurement system, you can adjust the hardware and drivers according to your specific requirements. The measurement module is designed to be hardware-agnostic at the API level, but you will need to:
- Initialize your sensor hardware
- Provide the sensor handle to the measurement module
- Ensure the sensor driver implements the required interface (e.g.,
adxl355_read_accelerations(),adxl355_read_temperature())
The current implementation is tailored for ADXL355, but the architecture allows for adaptation to other sensors with similar interfaces.
Current Version Limitations
The current version does not support multi-sensor synchronous acquisition. Only single-sensor acquisition functionality is currently available.
Performance Optimization
For optimal online sensing performance (approaching 200 Hz), consider: - Disabling unnecessary outputs (serial, LCD) - Using stable MQTT connection - Ensuring sufficient network bandwidth
Documentation¶
- Online Sensing: Detailed documentation for real-time data streaming
- Offline Sensing: High-frequency batch collection guide
- Real-Time Sensing and Processing: Real-time acquisition with processing
- Command Control: MQTT remote control reference
- Header Files: API documentation and code examples