# BCMS RPC Examples
This directory contains example applications demonstrating how to integrate with BCMS for IoT data submission.
## Example: Blood Pressure Data Submission
The `rpc-example` binary demonstrates how to submit IoT data to BCMS via RPC.
### Usage
```bash
# Build the example
cargo build --release
# Run with basic parameters
./target/release/rpc-example \
--device-address "AA:BB:CC:DD:EE:FF" \
--device-name "Home Blood Pressure Monitor" \
--device-type "blood_pressure_monitor"
# Submit multiple readings with custom intervals
./target/release/rpc-example \
--device-address "11:22:33:44:55:66" \
--device-name "Patient Monitor #1" \
--device-type "medical_device" \
--count 5 \
--interval-ms 2000 \
--debug
# Connect to custom RPC server
./target/release/rpc-example \
--device-address "FF:EE:DD:CC:BB:AA" \
--device-name "Lab Equipment" \
--device-type "laboratory_monitor" \
--rpc-address "192.168.1.100:4567"
```
### Output Example
```
🩺 BCMS RPC IoT Data Submission Example
📍 Device: Home Blood Pressure Monitor (AA:BB:CC:DD:EE:FF) - Type: blood_pressure_monitor
🔗 RPC Server: 127.0.0.1:4567
📊 Generating 1 blood pressure reading(s)...
📈 Reading #1: 125mmHg / 82mmHg (timestamp: 1704067200000)
✅ Successfully submitted reading #1
📋 Submission Summary:
✅ Successful: 1
❌ Failed: 0
📊 Total: 1
🎉 Data will be automatically synced to the backend every 3 seconds!
🔍 Check the BCMS daemon logs to see backend submission status.
```
### Prerequisites
1. **BCMS Daemon Running**: Make sure `bcms-daemon` is running:
```bash
./target/release/bcms-daemon --use-device-identity --identifier your-client-id
```
2. **Network Connectivity**: Ensure the RPC client can reach the daemon.
### Command Line Options
| `--device-address` | Device MAC address | Required |
| `--device-name` | Human-readable device name | Required |
| `--device-type` | Device type identifier | Required |
| `--rpc-address` | BCMS daemon RPC address | `127.0.0.1:4567` |
| `--count` | Number of readings to generate | `1` |
| `--interval-ms` | Interval between readings (ms) | `1000` |
| `--debug` | Enable debug logging | `false` |
### Integration Notes
- **Auto-approval**: Devices submitted via RPC are automatically approved
- **Auto-registration**: Devices are automatically registered with the backend
- **Data flow**: RPC data → DataStore → Backend (every 3 seconds)
- **Error handling**: Detailed error messages for troubleshooting
### Extending the Example
To create your own integration:
1. **Copy the pattern**: Use `rpc-example.rs` as a template
2. **Change data types**: Replace `create_blood_pressure_data` with other helpers
3. **Add validation**: Implement your own data validation logic
4. **Handle errors**: Add custom error handling for your use case
### Available IoT Data Types
```rust
use bcms::iot_helpers;
// Different data types you can create
iot_helpers::create_heart_rate_data(address, 72, timestamp);
iot_helpers::create_temperature_data(address, 36.6, timestamp);
iot_helpers::create_blood_pressure_data(address, 120, 80, timestamp);
iot_helpers::create_battery_level_data(address, 85, timestamp);
iot_helpers::create_pressure_data(address, 1013.25, timestamp);
iot_helpers::create_humidity_data(address, 65.0, timestamp);
iot_helpers::create_alert_data(address, "low_battery".to_string(), timestamp);
```