This project implements a BLE-based network monitoring and anomaly detection system using an ESP32 microcontroller and a Raspberry Pi. The ESP32 operates in promiscuous mode to passively sniff Wi-Fi traffic and transmits metadata via BLE to a Raspberry Pi, which further logs, processes, and analyzes the data using InfluxDB. The goal is to simulate a lightweight IDS/IPS-like solution capable of detecting suspicious activity in a home or lab network, such as DoS attempts, MAC spoofing, and out-of-hours access.
Optional integration with Home Assistant allows security alerts to be routed to multiple channels (e.g., email, mobile push) based on severity.
Block Diagram
The ESP32 module is configured in promiscuous mode to capture 802.11 beacon and probe request frames. It collects metadata including MAC addresses, RSSI, and timestamps. These packets are periodically sent via BLE to a Raspberry Pi acting as a BLE server. The Pi parses incoming data, stores it in InfluxDB, and runs basic anomaly detection logic based on:
Alerts are generated based on thresholds and logged events. Higher severity events may trigger multi-channel notifications via Home Assistant integrations.
ESP32 DevKit (ESP-WROOM-32)
Raspberry Pi 4B (or similar with BLE support)
Breadboard, USB power supplies
Optional: LEDs for visual status indication
Physical Setup: The ESP32 is deployed in a fixed location within Wi-Fi range, while the Raspberry Pi operates as a static gateway and logging processor.
Arduino IDE / PlatformIO (ESP32 firmware)
BLEDevice.h, esp_wifi.h (ESP32 sniffing & BLE)
BlueZ / Python-BLE / bleak (Raspberry Pi BLE server)
InfluxDB 2.0 (time-series database)
Home Assistant/Slack (optional) (for alert forwarding)
ESP32 BLE Sniffer Loop
void sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) { const wifi_promiscuous_pkt_t *pkt = (wifi_promiscuous_pkt_t *)buf; if (type == WIFI_PKT_MGMT) { int rssi = pkt->rx_ctrl.rssi; uint8_t *mac = pkt->payload + 10; if (rssi > RSSI_THRESHOLD) { // Format payload sendBLE(mac, rssi, pkt->rx_ctrl.channel); } }
}
Raspberry Pi - BLE Receive Handler
def on_ble_receive(data): mac, rssi, ch, ts = parse_payload(data) influx.write({ "measurement": "wifi_activity", "tags": {"mac": mac, "channel": ch}, "fields": {"rssi": rssi}, "time": ts }) check_anomalies(mac, rssi, ts)