Skip to main content

Arduino Router Bridge

A MessagePack-RPC bridge that lets Python applications call methods on an Arduino microcontroller, and expose Python functions the microcontroller can call back. Requires a Unix or TCP socket managed by the Arduino Router and a compatible board such as the Arduino UNO Q or VENTUNO Q.

Installation

pip install arduino-router-bridge

Usage

Create a Bridge, connect it, and use it for as long as you need:

from arduino.router_bridge import Bridge

bridge = Bridge()
bridge.connect(timeout=5)  # Waits until connected; True if connected, False on timeout

# Fire-and-forget notification
bridge.notify("set_led", "green", True)

# Blocking call with response
temperature = bridge.call("get_temperature", "sensor1", timeout=5)

bridge.disconnect()

It can also be used as a context manager:

with Bridge() as bridge:
    bridge.call("get_temperature", "sensor1")

Exposing Python functions to the microcontroller

def get_country(lon: str, lat: str) -> str:
    return lookup_country(lon, lat)


bridge.provide("get_country", get_country)

A provided method can be withdrawn with bridge.unprovide("get_country").

Handlers can be provided before or after connecting: they are registered with the router as soon as the connection is available and re-registered transparently whenever it is re-established. Handlers run sequentially on a dedicated thread. A handler may send notifications, but must not call back into the bridge with call(): the peer may be blocked waiting for the handler's own response, so nested calls risk deadlocks and request loops and are rejected with a RuntimeError.

Configuration

The bridge connects to the Arduino RPC router at unix:///var/run/arduino-router.sock by default. Pass an address to the constructor to connect elsewhere.

unix://<path> is the standard transport. It is only available on Linux, where the router runs and manages the socket; constructing a bridge with a unix:// address on a platform without unix socket support raises ValueError. tcp://<host>:<port> is meant for development and debugging only: it is unauthenticated and unencrypted (see the security model below), and by default the router does not expose it to external hosts.

Instances are independent: create one per router you need to talk to. How an instance is shared is the caller's concern; an embedding runtime that needs a process-wide bridge creates one instance at startup and exposes it itself:

from arduino.router_bridge import Bridge

bridge = Bridge()  # Uses the default address unix:///var/run/arduino-router.sock
bridge.connect()

connect() waits until the connection is established, indefinitely unless a timeout is given, and returns whether it succeeded; on timeout the bridge keeps connecting in the background. A lost connection is re-established automatically. Disconnect explicitly (or use a context manager) when done; as a safety net, a garbage-collected bridge disconnects automatically.

Security model

The router socket is the trust boundary: any process that can connect to it can invoke the provided methods and forge RPC responses. Unix sockets are protected by file permissions, managed by the Arduino Router. tcp:// connections carry no authentication or encryption: use them only on localhost or an isolated, trusted network, and never expose them to untrusted hosts.

Handler exceptions are reported to the caller by exception type only; full details, including the traceback, stay in the local log. To bound memory usage, incoming messages are capped at 1 MiB and pending handler executions at 1024 by default; both limits are configurable per Bridge (max_message_size, max_pending_handlers).

Logging

The library logs through the standard logging module under the arduino.router_bridge namespace and emits nothing unless the application configures a handler:

import logging

logging.getLogger("arduino.router_bridge").addHandler(logging.StreamHandler())

License

MPL-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arduino_router_bridge-0.4.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arduino_router_bridge-0.4.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file arduino_router_bridge-0.4.0.tar.gz.

File metadata

  • Download URL: arduino_router_bridge-0.4.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for arduino_router_bridge-0.4.0.tar.gz
Algorithm Hash digest
SHA256 1fc7703c2dce429fa6af963795bcc3c26059e85237fba51b532399557a0caa01
MD5 6e8bdc563342836519cf90cb19924c07
BLAKE2b-256 1326844fc0056e1d5d431a3547bd39bc315fd956dbff68ee8b1888148987e88e

See more details on using hashes here.

Provenance

The following attestation bundles were made for arduino_router_bridge-0.4.0.tar.gz:

Publisher: publish.yml on arduino/arduino-router-bridge-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arduino_router_bridge-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for arduino_router_bridge-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0950ca1cf71e94f88069f028d670eb1eab2cce34e96b47b03dd98b4a175b5bf2
MD5 0e5fcb34f41b9612a9e1a25ea893b9ff
BLAKE2b-256 12cc296006ea706c5c2dd8d53bed59387bec4e6406189af6f3120e547f0a3407

See more details on using hashes here.

Provenance

The following attestation bundles were made for arduino_router_bridge-0.4.0-py3-none-any.whl:

Publisher: publish.yml on arduino/arduino-router-bridge-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.0

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page