AIoT Sentinel
by meryambn
README.md
# š”ļø Edge-Cloud AIoT Sentinel (`aiot-mcp-agent`)
**Author:** **Benalia Meriem** (<mi.benalia@gmail.com>)
**Specialization:** Edge AI, IoT Systems, and Large Language Models
**Academic Report:** [`report/aiot_sentinel_report.tex`](./report/aiot_sentinel_report.tex) | [š Download Compiled PDF](./report/aiot_sentinel_report.pdf)
> **Hierarchical Edge-Cloud AIoT Architecture with FastMCP, Multi-Modal Telemetry Ingestion, and Gated SLM Reasoning.**
> Built as a thesis-grade and portfolio-grade engineering project demonstrating modern AIoT, edge computing trade-offs, and deterministic agent safety.
---
## š Executive Summary & Research Questions
Deploying Large Language Models directly on raw IoT sensor streams creates two catastrophic engineering failures:
1. **Network & Token Flooding:** Streaming high-frequency sensor floats (temperature, humidity, CO2, dB) consumes massive bandwidth and cloud token budgets on static, nominal data.
2. **Hallucinatory Actuator Hazards:** Unchecked LLMs can dispatch dangerous commands to physical hardware (e.g., shutting down HVAC during thermal runaway, or disabling ventilation during chemical gas leaks).
### šÆ Primary Research Questions (RQs)
- **RQ1 (Data Efficiency & Telemetry Gating):** *To what degree can on-device event-triggered deadband and rate-of-rise gradient filtering suppress redundant high-frequency IoT telemetry and LLM token overhead without attenuating critical transient anomaly transitions?*
- **RQ2 (Deterministic Actuation Safety):** *Can a standardized protocol gateway (Model Context Protocol) enforcing pre-actuation deterministic interlocks eliminate safety invariant violations when probabilistic language models control physical actuators?*
- **RQ3 (Latency & Multi-Modal Reasoning Trade-off):** *How does a tiered architecture combining edge event filtering with compact local Small Language Models (SLMs) perform relative to static heuristic baselines and monolithic cloud streaming in decision latency, cross-sensor false alarm rejection, and resource efficiency?*
**AIoT Sentinel** solves these challenges with a **three-tier hierarchical architecture**:
- **Tier 1 (Physical Edge / TinyML Gate):** Lightweight deadband & finite-difference rate-of-rise gradient filtering that eliminates **90.0% of redundant telemetry** while deterministically catching critical edge transitions.
- **Tier 2 (FastMCP Gateway & Safety Interlocks):** A Model Context Protocol (MCP) server providing typed tools, tamper-evident SHA-256 chained audit trails, and deterministic invariant checks (ISO-50001 building codes).
- **Tier 3 (Gated SLM Agent):** Correlates multi-modal sensor signals (thermal, acoustic, gas, optical, contact) to discern genuine threats from false alarms.
---
## šļø System Architecture

```
[ ESP32 Sensor Fleet ] (DHT22, MQ-135, PIR, Acoustic, Reed Contact)
ā
ā¼ (Raw Telemetry Stream)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Tier 1: TinyML Edge Filter ā
ā ⢠Deadband thresholding (Δx ≥ δ) ā
ā ⢠Rate-of-rise gradient detection (dx/dt ≥ γ) ā
ā ⢠Periodic heartbeat synchronization ā
ā āā> Discards 90.0% redundant nominal samples ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā (Escalated Event Packets Only)
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Tier 2: FastMCP Gateway (Model Context Protocol) ā
ā ⢠get_room_state(room_id) ā
ā ⢠query_safety_policy(domain) ā
ā ⢠execute_actuator_action(...) ā
ā āāā> [ Deterministic Safety Interlock Gate ] ā
ā āāā> [ Tamper-evident SHA-256 Chained Audit Trail ] ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā²
ā Tool Calls & Safety Justifications
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Tier 3: Multi-Modal SLM Reasoner (Qwen2.5 / Edge SLM) ā
ā ⢠Cross-sensor consensus reasoning ā
ā ⢠False alarm rejection (e.g. transient solar heating) ā
ā ⢠Multi-stage disaster mitigation planning ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
```
---
## š Empirical Head-to-Head Benchmark
Evaluated over **25 continuous temporal scenarios** (1,500 total ticks / 9,000 multi-sensor observations) including thermal runaway, chemical gas leaks, after-hours intrusion, HVAC energy waste, and transient solar glare:
| Architecture | Decision Accuracy | Safety Invariant Violations | Packets Transmitted | Bandwidth Saved | Avg Decision Latency | Total Tokens |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
| **Static Heuristics (Rule-based)** | 100.0% | 2 | 9,000 | 0.0% | **3.75 ms** | **0** |
| **Unfiltered Cloud LLM (Raw Stream)** | 92.0% | 1 | 9,000 | 0.0% | 485.00 ms | 63,000 |
| **Hierarchical AIoT Sentinel (Ours)** | **100.0%** | **0** | **900** | **90.0%** | **21.11 ms** | **680** |
### Key Empirical Findings:
- **Bandwidth & Token Efficiency:** The edge filtering layer reduces transmitted telemetry packets by **90.0%** and slashes token consumption by **92Ć** (from 63,000 down to 680 tokens) with **zero missed emergency anomalies**.
- **Deterministic Zero-Violation Safety:** While naive LLMs occasionally dispatch hazardous commands due to phrasing nuance, the FastMCP safety gate achieved **0 safety violations**.
- **Edge Latency:** Local SLM actuation completed in **21.11 ms**, approximately **23Ć faster** than round-trip cloud LLM streaming.
---
## š Visual Benchmark Reports
### Multi-Modal Telemetry & Edge Detection

### TinyML Bandwidth Reduction by Sensor Modality

### Head-to-Head Metrics Comparison

### Latency vs Token Cost Trade-off (Pareto Frontier)

---
## š ļø Repository Layout
```
aiot-mcp-agent/
āāā src/aiot/
ā āāā simulator/
ā ā āāā virtual_fleet.py # Multi-room ESP32 telemetry simulator & AR(1) drift
ā āāā edge_filter/
ā ā āāā tiny_filter.py # TinyML deadband filter & rate-of-rise gradient gate
ā āāā mcp/
ā ā āāā server.py # FastMCP Server + JSON-RPC 2.0 + SHA-256 audit log
ā āāā agent/
ā ā āāā reasoner.py # Multi-modal SLM correlation & decision agent
ā āāā benchmark/
ā āāā eval_harness.py # 25-scenario continuous temporal evaluation suite
āāā tests/ # Full Pytest test suite (11/11 passing in 0.39s)
ā āāā test_simulator.py
ā āāā test_edge_filter.py
ā āāā test_mcp_server.py
ā āāā test_agent.py
ā āāā test_benchmark.py
āāā report/
ā āāā aiot_sentinel_report.tex # Formal academic IEEE-style paper (Author: Benalia Meriem)
ā āāā aiot_sentinel_report.pdf # Compiled publication-ready PDF report
ā āāā figures/ # High-res publication charts (300 DPI)
āāā results/ # Benchmark outputs (JSON and Markdown)
āāā dashboard.py # Interactive Streamlit telemetry & live agent console
āāā pyproject.toml
āāā requirements.txt
```
---
## š Quickstart & Reproducibility
### 1. Installation
```bash
git clone https://github.com/Anish-Guntreddi/aiot-mcp-agent.git
cd aiot-mcp-agent
pip install -r requirements.txt
pip install -e .
```
### 2. Run Test Suite
```bash
pytest tests/ -v
```
### 3. Run Empirical Benchmark
```bash
python -m aiot.benchmark.eval_harness
```
### 4. Launch Live Streamlit Console
```bash
streamlit run dashboard.py
```
---
## š¬ Hardware Deployment Guide (ESP32-S3 / MicroPython)
To bind this software gateway to physical hardware, flash the following snippet onto an **ESP32-S3** board with a DHT22 and MQ-135 sensor:
```python
# firmware/main.py (MicroPython for ESP32-S3)
import time, ujson, urequests
from machine import Pin, ADC
SERVER_URL = "http://<GATEWAY_IP>:8000/telemetry"
LAST_TEMP = 0.0
def read_and_filter():
global LAST_TEMP
# Read hardware sensor...
current_temp = 22.4
if abs(current_temp - LAST_TEMP) >= 0.5 or current_temp > 40.0:
payload = {"device_id": "esp32_01", "room_id": "server_room_a", "sensor": "temperature_c", "value": current_temp}
urequests.post(SERVER_URL, json=payload)
LAST_TEMP = current_temp
while True:
read_and_filter()
time.sleep(1)
```
---
## š Citation & Academic Credit
If you use this work in academic research or engineering evaluations, please cite:
```bibtex
@article{benalia2026aiot,
title={Hierarchical Edge-Cloud AIoT Architecture: Integrating TinyML Gating, Model Context Protocol (MCP), and Gated SLM Reasoning for Safety-Critical Facilities},
author={Benalia, Meriem},
journal={Department of Computer Science & Artificial Intelligence},
year={2026}
}
```
---
## š License
MIT License. Authored by **Benalia Meriem** (2026).
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues