Skip to main content

IoT Connector

The Savitri IoT Connector enables Internet-of-Things devices to submit sensor data on-chain. It provides device management, data ingestion, edge processing, batch optimization, and enterprise-grade security.

Architecture

IoT Devices (sensors, actuators, gateways)


Protocol Handlers (MQTT, CoAP)
│ parse, validate, authenticate

Edge Processing Engine
│ rules engine, anomaly detection, aggregation

Batch Processor
│ compress, aggregate, schedule

Blockchain Interface (savitri_sendRawTransaction)
│ submit batch as IoT TX (0.00005 SAVT fee)

On-chain Oracle Feed

Device Management

Device Types

TypeDescriptionExample
SensorRead-only data producerTemperature sensor
ActuatorControllable deviceSmart valve
GatewayEdge aggregation pointRaspberry Pi hub
EdgeNodeLocal processing unitEdge ML server
MobileMobile deviceSmartphone
IndustrialIndustrial equipmentPLC/SCADA

Device Registration

pub struct Device {
pub id: DeviceId,
pub owner: [u8; 32], // owner address
pub public_key: [u8; 32], // device signing key
pub device_type: DeviceType,
pub capabilities: Vec<String>,
pub status: DeviceStatus,
pub metadata: HashMap<String, String>,
}

Devices are registered on-chain with their public key for authentication. Groups of devices can be managed collectively.

Device Status

StatusDescription
ActiveNormal operation
InactiveTemporarily offline
SuspendedSuspended by owner/governance
BannedPermanently revoked

Data Ingestion

Protocol Support

ProtocolHandlerUse Case
MQTTMQTTHandlerLow-power sensors, pub/sub
CoAPCoAPHandlerConstrained devices, UDP

Both implement the ProtocolHandler trait:

pub trait ProtocolHandler: Send + Sync {
async fn handle_connection(&self, stream: TcpStream) -> Result<()>;
fn parse_data(&self, raw: &[u8]) -> Result<IoTData>;
fn validate_device(&self, device_id: &str, signature: &[u8]) -> Result<bool>;
}

IoT Data Format

pub struct IoTData {
pub device_id: String,
pub timestamp: u64,
pub data_type: String, // "temperature", "humidity", etc.
pub value: DataValue,
pub unit: String, // "celsius", "percent", etc.
pub quality: f64, // 0.0-1.0 (data quality score)
pub metadata: HashMap<String, String>,
}

pub enum DataValue {
Float(f64),
Integer(i64),
Boolean(bool),
String(String),
Binary(Vec<u8>),
Struct(HashMap<String, DataValue>),
Array(Vec<DataValue>),
}

Edge Processing

The edge processing engine filters, transforms, and aggregates data before submission.

Rules Engine

// Example rule: alert if temperature > 40
Rule {
condition: Condition::GT("temperature", 40.0),
action: ProcessingAction::CriticalAlert,
}

// Logical operators
Condition::AND(vec![
Condition::GT("temperature", 35.0),
Condition::LT("humidity", 20.0),
])

Operators: EQ, NEQ, GT, LT, GTE, LTE, CONTAINS, IN, AND, OR.

Anomaly Detection

The edge processor runs anomaly detection on incoming data:

  • Statistical outlier detection
  • Pattern recognition
  • ML model inference (local models)

Anomalies trigger automatic submission regardless of batch schedule.

Data Aggregation

StrategyDescription
AverageMean of values in window
SumTotal of values
Min / MaxExtremes
MedianMiddle value
Percentile(p)P-th percentile

Batch Processing

Individual sensor readings are batched to reduce transaction costs:

pub struct BatchProcessor {
pub batch_size: usize, // max readings per batch
pub max_delay_ms: u64, // max time before forced submit
pub compression: bool, // compress batch payload
pub aggregation: bool, // aggregate before submit
}

Batch Triggers

TriggerDescription
Size reachedbatch_size readings accumulated
Max delaymax_delay_ms elapsed since first reading
Critical priorityAnomaly or critical alert detected

Batching reduces blockchain transactions by up to 90% compared to per-reading submission.

Security

Authentication

Three authentication methods, combinable:

MethodDescription
CertificateX.509 certificate chain validation
TokenAPI token with expiry
BiometricDevice biometric verification

Data Encryption

  • AES-256 encryption for data in transit and at rest
  • Integrity hashing for tamper detection
  • Certificate revocation checking

Connector Configuration

pub struct ConnectorConfig {
pub max_requests_per_second: u32,
pub timeout_ms: u64,
pub retry_attempts: u32,
}

On-Chain Integration

IoT data is submitted as transactions with the IoT fee rate:

let tx = TransactionBuilder::new()
.oracle_call(
"iot_oracle_address",
"submit_sensor_data",
&batch_payload,
)
.nonce(nonce)
.fee(50_000_000_000_000) // 0.00005 SAVT (IoT rate)
.build_and_sign(&device_wallet)?;

Oracle Feed Integration

Submitted IoT data becomes available as oracle feeds:

// Request latest sensor reading
let tx = oracle.request_data(
&iot_oracle_address,
"temperature",
b"sensor_001",
).await?;

Connector Metrics

pub struct ConnectorMetrics {
pub requests_served: u64,
pub errors_count: u64,
pub average_response_time: f64,
}