Sensor Fusion + AI Inference with ASI Biont: Real-Time Edge Intelligence Without the Cloud

Introduction

In the era of Industry 4.0 and predictive maintenance, raw sensor data is worthless without intelligent processing. Sensor fusion — combining accelerometer, gyroscope, and magnetometer readings — provides rich context about motion, orientation, and vibration. But the real value emerges when you run neural inference directly on edge hardware (like an ESP32 or Raspberry Pi) and connect it to an AI agent that can analyze, alert, and act. ASI Biont bridges this gap: you describe your sensor fusion setup in plain English, and the AI writes the integration code on the fly — no dashboards, no waiting for developer updates.

Why Connect Sensor Fusion to an AI Agent?

Edge devices with sensor fusion (e.g., MPU9250, BNO055, LSM9DS1) generate high-frequency data — often 100–1000 samples per second. Sending everything to the cloud introduces latency, bandwidth costs, and privacy risks. Running on-device machine learning (on-device ML) for inference (anomaly detection, vibration prediction) keeps decisions local. ASI Biont orchestrates this by:
- Reading fused data via MQTT or serial bridge
- Running inference with onnxruntime or scikit-learn (inside execute_python)
- Triggering actions (alerts, actuator control) without round-trips to the cloud

Architecture Overview

The integration uses a hybrid edge‑to‑agent model:

Component Role Connection to ASI Biont
ESP32 / Raspberry Pi Collects accelerometer, gyroscope, magnetometer data; runs lightweight inference MQTT (paho-mqtt) or Hardware Bridge (serial)
ASI Biont (cloud) Receives sensor data, executes Python scripts for analysis, stores history execute_python sandbox with paho-mqtt / paramiko
User’s PC (bridge.py) Optional: connects to local COM ports if using serial Hardware Bridge (HTTP long polling)

Concrete Use Case: ESP32 + MPU9250 → Vibration Anomaly Detection

Step 1: Hardware Setup

  • Microcontroller: ESP32 (or Raspberry Pi Pico)
  • Sensor: MPU9250 (9‑axis IMU) connected via I2C
  • Connection to ASI Biont: MQTT (ESP32 publishes JSON to broker)

Step 2: User Describes the Task in Chat

“Connect to an ESP32 publishing MPU9250 data via MQTT at broker.example.com:1883, topic sensor/fusion. Subscribe, collect accelerometer data for 10 seconds, compute RMS, and detect anomalies if RMS exceeds 2.5 g. Publish an alert to topic alerts/anomaly.”

ASI Biont’s AI agent then writes and executes the Python script inside its sandbox (execute_python). No manual coding required.

Step 3: AI-Generated Code (Sandbox Side)

import paho.mqtt.client as mqtt
import json
import time
import math

# Configuration from chat
BROKER = "broker.example.com"
PORT = 1883
TOPIC_SUB = "sensor/fusion"
TOPIC_ALERT = "alerts/anomaly"
THRESHOLD = 2.5  # g

samples = []

def on_message(client, userdata, msg):
    global samples
    try:
        data = json.loads(msg.payload)
        # Expecting {"ax":1.2, "ay":0.3, "az":9.8, ...}
        accel_mag = math.sqrt(data["ax"]**2 + data["ay"]**2 + data["az"]**2)
        samples.append(accel_mag)
        if len(samples) >= 100:  # 10 seconds at 10 Hz
            rms = math.sqrt(sum(x*x for x in samples) / len(samples))
            if rms > THRESHOLD:
                alert = {"rms": round(rms, 2), "threshold": THRESHOLD, "timestamp": time.time()}
                client.publish(TOPIC_ALERT, json.dumps(alert))
                print(f"Anomaly detected: RMS = {rms:.2f}g")
            samples = []
    except Exception as e:
        print(f"Error: {e}")

client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe(TOPIC_SUB)
client.loop_start()
time.sleep(30)  # Sandbox timeout: 30 seconds max
client.loop_stop()

Step 4: ESP32 Side (MicroPython Example)

import network
import time
import json
from machine import I2C, Pin
import mpu9250

# Connect to Wi-Fi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("SSID", "PASSWORD")
while not wlan.isconnected():
    time.sleep(0.5)

# MQTT setup
from umqtt.simple import MQTTClient
client = MQTTClient("esp32_sensor", "broker.example.com")
client.connect()

# Sensor init
i2c = I2C(scl=Pin(22), sda=Pin(21))
sensor = mpu9250.MPU9250(i2c)

while True:
    accel = sensor.acceleration
    gyro = sensor.gyro
    mag = sensor.magnetic
    payload = {
        "ax": accel[0], "ay": accel[1], "az": accel[2],
        "gx": gyro[0], "gy": gyro[1], "gz": gyro[2],
        "mx": mag[0], "my": mag[1], "mz": mag[2]
    }
    client.publish(b"sensor/fusion", json.dumps(payload))
    time.sleep(0.1)  # 10 Hz

Why This Integration Works

  • Zero‑code setup: User only describes the device and desired logic.
  • Real‑time edge inference: ASI Biont can run onnxruntime or scikit‑learn models in the sandbox, processing data as it arrives.
  • Autonomous operation: No cloud dependency for inference — the AI agent triggers alerts locally via MQTT.
  • Low latency: Inference happens within the sandbox (sub‑second); alerts propagate via MQTT in milliseconds.

Advanced Scenarios Enabled

Scenario How ASI Biont Handles It
Predictive maintenance Collects vibration RMS over weeks; runs scikit‑learn Isolation Forest to detect degradation
Gesture recognition Sends raw gyro + accel sequences to an ONNX model (trained offline) via onnxruntime
Multi‑sensor fusion Combines data from multiple ESP32 nodes via MQTT topics, correlates anomalies
Automated actuator response If anomaly detected → publish command topic to ESP32 to engage brake or adjust motor

Conclusion

Sensor fusion combined with AI inference on the edge is no longer a research prototype — it’s a practical architecture for predictive maintenance, robotics, and smart manufacturing. ASI Biont makes it accessible to anyone: describe your sensor fusion device in plain language, and the AI agent writes the Python integration in seconds. No pre‑built connectors, no dashboards, no waiting.

Try it yourself: head to asibiont.com, describe your MPU9250 or any sensor fusion setup, and watch the AI agent connect, collect, and analyze — all in real time.

← All posts

Comments