l

On‑Device Anomaly Detection for Telemetry

On‑Device Anomaly Detection for Telemetry

Intro

Devices in the field continuously send motion, temperature, and power data. In connected pet‑tech products like those at Hoomanely, spotting unusual patterns right on the device can prevent bigger issues - like a dog’s collar overheating or a tracker battery draining too quickly. Local anomaly detection lets us react in seconds without waiting for the cloud or wasting data bandwidth.

The ESP32 runs small machine learning models such as Isolation Forests (IF), which use simple comparisons instead of heavy math. More powerful hubs like the Raspberry Pi CM4 can run compact autoencoders, which learn what “normal” looks like and flag anything different. Together they form a fast, reliable, and privacy‑friendly detection system.


Why Isolation Forest

Isolation Forest works by randomly dividing data and checking how easily each reading can be “isolated.” Values that separate quickly are likely unusual. This makes it ideal for small processors - the model is just a few decision rules that can run in a few milliseconds.

Benefits for devices:

  1. Predictable speed - every tree makes the same few checks.
  2. Small size - only a few kilobytes of memory.
  3. Easy to explain - each rule compares a feature to a number.
  4. Reliable - consistent results without complex math.

How Isolation Forest Detects Anomalies


Data & Feature Preparation

Each second of sensor data is summarized into a few key numbers:

  • Motion: overall strength of movement and vibration patterns.
  • Temperature: how quickly the reading rises or falls.
  • Power: how much voltage drops when the device is active.

These short summaries (about 30 numbers) are small enough to process on microcontrollers.

Training Steps

  1. Collect a few minutes of normal behavior.
  2. Create the same summary features in Python.
  3. Train an Isolation Forest on this data.
  4. Save the model’s rules as small arrays that fit on the ESP32.

Edge Inference on ESP32‑S3

Each Isolation Forest is stored as simple tables of numbers:

typedef struct {
  int8_t feature_idx;
  float threshold;
  int16_t left;
  int16_t right;
} Node;

The device checks each feature against the stored thresholds. The fewer steps it takes to isolate a reading, the more likely it’s an anomaly.

Edge Inference Flow

Typical performance on ESP32‑S3:

  • Model size: ~10 KB
  • RAM used: 15–20 KB
  • Inference time: under 0.5 ms per check

Autoencoder on CM4 - Smarter Hub Detection

While the ESP32‑S3 handles quick rule checks, the CM4 hub can run a slightly larger autoencoder model. An autoencoder learns to rebuild normal signals. When something looks odd, its reconstruction error increases — that’s your anomaly.

Autoencoder in Action

This works well for long‑term drifts - like temperature creeping up over hours - that are too subtle for rule‑based models. But on smaller chips like ESP32, autoencoders are often too heavy, needing more memory and math. That’s why they’re best used on hubs such as CM4, not on every device.


Handling Drift & Thresholds

To keep results stable over time:

  • The threshold adjusts automatically using recent data averages.
  • Alerts only trigger after several unusual readings in a row.
  • Models and calibration data can be updated safely over the air.

Adaptive Threshold Example


Field Results

During internal bench testing and early field trials, the setup behaved consistently with expectations:

  • The ESP32‑S3 could flag sudden movement spikes or voltage drops almost instantly, showing that simple threshold‑based IF models react within milliseconds even under noisy data.
  • On the CM4, the autoencoder consistently identified slower, progressive changes such as gradual heating or long‑term drift that weren’t obvious from raw sensor readings.
  • When configured to send only short event packets instead of full data streams, network traffic and cloud processing dropped to a fraction of normal levels - demonstrating that most insight can be extracted locally before upload.

These observations confirm that combining fast IF checks on the device and adaptive AE validation on the hub gives a practical and scalable balance between responsiveness, cost, and reliability.


Takeaways

  • Use IF for small devices: fast and easy to run.
  • Use autoencoders on hubs: better for slow or complex patterns.
  • Together: quick local reactions with smart central verification.
  • Result: reliable, low‑latency monitoring that saves battery and bandwidth.

Combining Isolation Forests on the edge with autoencoders on the hub helps detect real‑world issues early - keeping devices efficient and users’ pets safe.

Read more