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

Calling the microcontroller

from arduino.router_bridge import Bridge

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

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

Exposing Python functions to the microcontroller

from arduino.router_bridge import Bridge


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


Bridge.provide("get_country", get_country)

Decorator API

from arduino.router_bridge import notify, call, provide


@call("math.add", timeout=3)
def add(a: int, b: int) -> int: ...  # Body is not needed


@notify()
def set_led(color: str, status: bool): ...


@provide()
def get_status() -> str:
    return "ok"


result = add(1, 2)  # Sends the "math.add" RPC call and returns its response
set_led("green", True)  # Sends the "set_led" RPC notification

Configuration

The bridge connects to the Arduino RPC router at unix:///var/run/arduino-router.sock by default. Pass an address to the decorators to connect elsewhere; both unix://<path> and tcp://<host>:<port> addresses are supported.

Embedding frameworks can install a resolver that maps the requested address to the effective one whenever a connection is created:

import os

from arduino.router_bridge import set_address_resolver

set_address_resolver(lambda address: os.environ.get("APP_SOCKET", address))

The connection is a process-wide singleton with automatic reconnection: provided methods are re-registered transparently whenever the connection is re-established.

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())

Embedding frameworks can also inject a pre-configured logger:

from arduino.router_bridge import set_logger

set_logger(my_logger)

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.1.0.tar.gz (22.4 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.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for arduino_router_bridge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d1179b38adfda70b50ad49f912a1bdf0ba8fcb03c926415426c6f2acc90b7cb
MD5 ad267a392bafd6eb835d55d96c82dbbb
BLAKE2b-256 c48984ff5e07fade136d6e45cc5917cf71f7572d8c4e43896691f3022baef777

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arduino_router_bridge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b9e4c165e399a1d6cb5bef0984cb5ed3ec18f88451849e8a142bed9340a0e3c
MD5 2d4917705e52d2d4d3d32bcfea3eb1ba
BLAKE2b-256 5911c9318d02ebeea626c39bb8c175520661dc2aba4522d13d060c2b3a17f83e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.0 This release

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