Cut Cloud Costs by 90%: Integrate Google Coral (Edge TPU) with ASI Biont for Real-Time On-Device ML

Introduction

Running AI inference in the cloud sounds great until the latency spikes and the bill arrives. For real-time tasks like object detection on a production line, every millisecond matters. Google Coral (Edge TPU) is a USB/PCIe accelerator that runs TensorFlow Lite models locally with inference under 5 ms—no internet required. The problem? Managing the data flow, triggering actions, and connecting it to your existing automation stack still needs custom glue code. That’s where ASI Biont steps in.

ASI Biont is an AI agent that connects to any device through natural language. You describe what you need—like “monitor a camera feed via Coral and send an alert when a person is detected”—and the agent writes the integration code on the fly. No dashboard, no “add device” button. Just chat.

In this article, you’ll learn how to connect Google Coral (Edge TPU) to ASI Biont using SSH (if running on a Raspberry Pi) or via a local Python script that bridges the Coral’s output to MQTT. We’ll walk through a real use case: detecting objects on a video stream and triggering a Telegram notification—all with under 5 ms latency and 90% less cloud cost.

Why Google Coral (Edge TPU) + ASI Biont?

Cloud-based ML is great for batch processing, but it fails for edge scenarios:
- Latency: Round-trip to a cloud API often takes 200–500 ms—too slow for real-time decisions.
- Cost: Each inference costs money. A factory running 24/7 can rack up thousands of dollars monthly.
- Reliability: Internet outages kill your automation.

Google Coral solves this by running models locally on a dedicated Edge TPU chip. It supports TensorFlow Lite, PyTorch (via ONNX), and even custom models. ASI Biont adds the coordination layer: it reads the inference results, decides what to do (e.g., turn on a conveyor belt, log data), and talks to other devices via MQTT, Modbus, or a simple HTTP API.

How ASI Biont Connects to Coral

ASI Biont uses execute_python to run code on its cloud sandbox. That sandbox has no direct access to your local hardware—but it can connect to your Coral device in two ways:

Method When to use How it works
SSH Coral runs on a Linux single-board computer (Raspberry Pi, Jetson Nano) AI writes a Python script using paramiko to SSH into the board, run a Coral inference script, and fetch results.
MQTT Coral outputs data to a local broker The AI subscribes to a topic where your Coral script publishes detection events, then reacts.
HTTP API Coral serves a local REST endpoint AI uses aiohttp to poll or POST to the Coral’s API.

For most users, SSH is the simplest: you give the agent the board’s IP, username, and password, and it handles the rest.

Real Use Case: Object Detection on a Production Line

Scenario

You have a Raspberry Pi 4 with a Google Coral USB Accelerator and a USB camera monitoring a conveyor belt. When the Coral detects a defective product (e.g., a missing label), you want an immediate Telegram alert and a log entry in a local CSV.

Step 1: Hardware Setup

  • Raspberry Pi 4 (4 GB RAM)
  • Google Coral USB Accelerator
  • USB camera (or Pi Camera v2)
  • Internet connection (for Telegram API)

Step 2: Install Edge TPU Runtime on the Pi

# Official guide: https://coral.ai/docs/accelerator/get-started/
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt update
sudo apt install libedgetpu1-std python3-pycoral

Step 3: Write a Local Inference Script

Save this as coral_detect.py on the Pi. It runs a MobileNet SSD model, detects objects, and publishes results via MQTT.

import cv2
from pycoral.adapters import common, detect
from pycoral.utils.dataset import read_label_file
from pycoral.utils.edgetpu import make_interpreter
import paho.mqtt.client as mqtt
import json

# Initialize Coral
model_path = 'ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite'
label_path = 'coco_labels.txt'
interpreter = make_interpreter(model_path)
interpreter.allocate_tensors()
labels = read_label_file(label_path)

# MQTT setup
client = mqtt.Client()
client.connect('localhost', 1883, 60)  # local broker

# Camera
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    # Run inference
    _, scale = common.set_resized_input(interpreter, (320, 320), lambda size: cv2.resize(frame, size))
    interpreter.invoke()
    objects = detect.get_objects(interpreter, score_threshold=0.5, scale=scale)

    for obj in objects:
        label = labels.get(obj.id, 'unknown')
        if label == 'bottle' and obj.score > 0.7:
            # Publish detection event
            payload = {
                'label': 'bottle',
                'score': round(obj.score, 2),
                'bbox': [obj.bbox.xmin, obj.bbox.ymin, obj.bbox.xmax, obj.bbox.ymax]
            }
            client.publish('coral/detection', json.dumps(payload))
            print(f"Detected {label} with score {obj.score:.2f}")

cap.release()

Step 4: Connect ASI Biont via SSH

In the ASI Biont chat, simply say:

“Connect to my Raspberry Pi at 192.168.1.100 via SSH (user: pi, pass: raspberry). Run python3 coral_detect.py in background. Subscribe to MQTT topic coral/detection. When a detection occurs, send me a Telegram message with the label and score. Also log each detection to a file /home/pi/detections.csv.”

The AI agent will generate and execute a Python script that:
1. SSH into the Pi using paramiko.
2. Start the Coral script in a screen session.
3. Subscribe to the local MQTT broker using paho-mqtt.
4. On each message, send a Telegram alert via requests and append to a CSV file.

Here’s what the generated code looks like (simplified):

import paramiko
import paho.mqtt.client as mqtt
import json
import requests
from datetime import datetime

# SSH to Pi and start the Coral script
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.1.100', username='pi', password='raspberry')
stdin, stdout, stderr = ssh.exec_command('screen -dmS coral python3 /home/pi/coral_detect.py')

# Telegram config
TELEGRAM_BOT_TOKEN = 'your_bot_token'
TELEGRAM_CHAT_ID = 'your_chat_id'

# MQTT callback
def on_message(client, userdata, msg):
    data = json.loads(msg.payload.decode())
    label = data['label']
    score = data['score']

    # Telegram alert
    text = f"⚠️ Detection: {label} (score: {score})"
    requests.post(f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage',
                  json={'chat_id': TELEGRAM_CHAT_ID, 'text': text})

    # Log to CSV
    with open('/home/pi/detections.csv', 'a') as f:
        f.write(f"{datetime.now()},{label},{score}\n")

mqtt_client = mqtt.Client()
mqtt_client.on_message = on_message
mqtt_client.connect('192.168.1.100', 1883, 60)
mqtt_client.subscribe('coral/detection')
mqtt_client.loop_forever()

Important: The ASI Biont sandbox has a 30-second timeout, so we use loop_forever only in the SSH-launched script. The integration script itself is event-driven and runs indefinitely.

Step 5: Test It

  • Place an object in front of the camera.
  • Check Telegram—you’ll get an alert within seconds.
  • Check /home/pi/detections.csv for the log.

Pitfalls to Avoid

  1. Coral USB power: The USB Accelerator draws up to 2.5W. Use a powered USB hub if connected to a Pi 4’s USB 3.0 port (it can supply 1.2A max).
  2. Model compatibility: Not all TensorFlow Lite models run on Edge TPU. Only those with full int8 quantization work. Use the models from coral.ai/models.
  3. MQTT broker: Install Mosquitto on the Pi (sudo apt install mosquitto mosquitto-clients) and allow local connections only.
  4. SSH key vs password: For production, use SSH keys. ASI Biont supports both, but passwords are simpler for testing.
  5. Sandbox timeout: The execute_python environment runs for max 30 seconds. For long-running tasks like MQTT subscription, the AI uses industrial_command or launches a persistent script via SSH.

Why This Beats Manual Coding

Without ASI Biont, you’d have to:
- Write the MQTT subscriber yourself.
- Handle Telegram API calls.
- Manage CSV logging.
- Handle errors and reconnections.

With ASI Biont, you just describe the flow in natural language. The agent writes production-ready Python code, handles imports, error handling, and even suggests improvements. You get a working integration in under 60 seconds.

Conclusion

Google Coral (Edge TPU) brings low-latency ML inference to the edge. ASI Biont brings the intelligence to orchestrate that inference with your existing systems—whether it’s Telegram alerts, database logging, or PLC control. Together, they slash cloud costs by up to 90% while keeping response times under 5 ms.

Ready to try it? Head over to asibiont.com, start a chat, and describe your Coral setup. The AI will connect it in seconds.

← All posts

Comments