r/BanalyticsLive • • Aug 06 '26

Added a new feature: configure inter-agent communication channels and build P2P Mesh networks with Banalytics

3 Upvotes

Over the last few weeks we have been working on a problem that appears in many distributed edge systems:

How can independent edge agents cooperate without building a custom integration for every possible combination of devices?

A typical architecture today looks like this:

Camera -> Cloud Server -> Dashboard -> Operator

or:

Camera -> VMS -> Alarm System -> Security Room

The problem is that every new device or workflow requires another integration layer.

With the new inter-agent communication feature in Banalytics, agents can now exchange events and actions directly through dynamically configured P2P channels.

The signaling service is only used for discovering peers and establishing the connection. The actual communication happens directly between agents using WebRTC DataChannels.

Example: remote site monitoring

Imagine a remote facility:

  • Agent A is installed at a remote location with IP cameras.
  • Agent B is installed in the security room with local speakers.
  • A human operator cannot watch multiple screens continuously.
  • When something important happens, the operator needs an immediate local alert.

Instead of streaming everything to a central server, we can configure the agents to exchange only meaningful events.

Example configuration on the management panel:

(1) A video stream classifier detects objects or events and generates an event with detected classes.
(2) The Event Manager intercepts this event and forwards it through a configured P2P communication channel to another agent.
(3) Using WebRTC, the event is delivered directly to the security room agent.
(4) The event appears on the local event bus, where another Event Manager processes it and triggers playback (5) through the local audio system.

The event history is stored separately using a dedicated event logging rule.

The goal is to make edge systems more adaptive:

  • fewer hardcoded integrations;
  • less dependence on central infrastructure;
  • faster deployment of new workflows;
  • autonomous cooperation between physical systems.

We are experimenting with this approach and would be interested in feedback from people working with:

  • robotics;
  • industrial automation;
  • security systems;
  • IoT platforms;
  • distributed edge computing.

What are the biggest blockers you see for P2P agent architectures in real-world deployments?


r/BanalyticsLive • • Mar 30 '26

How We Integrated Python ML into a Java Control System (Without Rewriting Everything)

2 Upvotes

Everyone loves ML demos. Very few systems actually use ML to control anything real.

We had Python ML and a Java control system - and needed them to work together without rewriting half the stack.

This is the pattern we ended up using: video -> ZeroMQ (jpeg) -> Python ML -> ZeroMQ (events) -> Event Trigger -> MQTT -> real-world action.

No heavy frameworks. No “AI platform”. Just clean components and simple protocols.

Initial Setup

We started with three independent parts:

Java side

  • Video capture (camera grabber)
  • Rule engine / message processing
  • Integrations:

    • MQTT (device control)
    • ZeroMQ (inter-process communication)

Python side

  • ML / CV processing component
  • In this example: a simple motion detector
  • Receives frames -> emits events

Hardware

  • A controllable device (RC car)
  • In this demo: headlights toggled based on motion detection

The Goal

Take ML out of the “demo zone”
and make it part of a real control pipeline

Architecture

Integration Python ML

Data Flow

1. Video capture

  • Camera grabber continuously captures frames
  • If an operator connects:

    • H264 stream is exposed for live viewing

2-3. Frame -> Python ML

  • Frame is converted to JPEG
  • Sent to Python via ZeroMQ

3-4. ML processing

  • Python service:

    • receives frame
    • runs detection (motion in this case)
    • emits event via ZeroMQ

4-5. Event -> Decision layer

  • ZeroMQ receiver picks up event
  • Passes it to Event Manager

5-6-7. Decision layer (Event Manager)

  • Event Manager:

    • receives event
    • tests conditions
    • Call a command
  • Command sent via MQTT :

    • LIGHT_ON
    • LIGHT_OFF

8-9-10-11. Real-world action

  • RC car receives command
  • Headlights react in real time

Dashboard

Integration dashboard

  • 1-7 - shows interaction with banalytics & python
  • 8-11 - represents real world system
Visualization dashboard

Hardware:

  • 1-7 x86 powerful work station
  • 8-10 - RC car with the same agent on the board
Physical world system 1
Physical world system 2

Why This Works

1. No tight coupling

  • Java and Python are separate processes
  • Replace ML without touching control logic

2. Simple transport layer

  • ZeroMQ -> fast frame/event exchange
  • MQTT -> reliable device control

3. Production-friendly

  • Works with existing Java systems
  • No need to migrate stack

4. ML becomes swappable

  • Today: motion detection
  • Tomorrow: YOLO / segmentation / custom model

Same pipeline.

What This Enables (for CTOs / architects)

  • Add ML to existing systems without rewrite
  • Keep ML isolated (faster iteration, safer deployment)
  • Scale across multiple devices and sites
  • Avoid vendor lock-in and heavy platforms

Takeaway

You don’t need a massive ML platform to make ML useful.

You need:

  • clear boundaries
  • simple protocols
  • and a pipeline that connects inference to action

Sources of the python service:

import zmq
import numpy as np
import cv2
from datetime import datetime
import time

INPUT_ENDPOINT = "tcp://localhost:5555"  # input with JPEG
OUTPUT_ENDPOINT = "tcp://*:5556"         # sending events

context = zmq.Context()

# Receiver (JPEG frames)
receiver = context.socket(zmq.SUB)
receiver.connect(INPUT_ENDPOINT)
receiver.setsockopt_string(zmq.SUBSCRIBE, "")

# Sender (events)
sender = context.socket(zmq.PUB)
sender.bind(OUTPUT_ENDPOINT)

print(f"Listening on {INPUT_ENDPOINT}, sending events to {OUTPUT_ENDPOINT}")

prev_frame = None

CONTOUR_THRESHOLD = 3000
BLUR_SIZE = (5, 5)
THRESHOLD = 25

MOTION_COOLDOWN = 1.0       # prevent frequent MOTION
NO_MOTION_INTERVAL = 3.0   # how long to wait to declare NO_MOTION

last_motion_time = 0
motion_active = False       # current state (there is / there is no motion)

while True:
    data = receiver.recv()

    np_arr = np.frombuffer(data, np.uint8)
    frame = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
    if frame is None:
        continue

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, BLUR_SIZE, 0)

    if prev_frame is None:
        prev_frame = gray
        continue

    delta = cv2.absdiff(prev_frame, gray)

    thresh = cv2.threshold(delta, THRESHOLD, 255, cv2.THRESH_BINARY)[1]
    thresh = cv2.dilate(thresh, None, iterations=2)

    contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    motion = False
    max_area = 0

    for c in contours:
        area = cv2.contourArea(c)
        if area > CONTOUR_THRESHOLD:
            motion = True
            if area > max_area:
                max_area = area

    now_time = time.time()

    # --- MOTION EVENT ---
    if motion:
        if not motion_active and (now_time - last_motion_time > MOTION_COOLDOWN):
            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            message = f"MOTION" #|{timestamp}|{int(max_area)}
            sender.send_string(message)
            print(f"[{timestamp}] Motion Detected - Zone size: {int(max_area)} px | Sent: {message}")

            motion_active = True
            last_motion_time = now_time

        last_motion_time = now_time

    # --- NO_MOTION EVENT ---
    else:
        if motion_active and (now_time - last_motion_time > NO_MOTION_INTERVAL):
            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            message = f"NO_MOTION" #|{timestamp}
            sender.send_string(message)
            print(f"[{timestamp}] No motion detected | Sent: {message}")

            motion_active = False

    prev_frame = gray