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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d1179b38adfda70b50ad49f912a1bdf0ba8fcb03c926415426c6f2acc90b7cb
|
|
| MD5 |
ad267a392bafd6eb835d55d96c82dbbb
|
|
| BLAKE2b-256 |
c48984ff5e07fade136d6e45cc5917cf71f7572d8c4e43896691f3022baef777
|
File details
Details for the file arduino_router_bridge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: arduino_router_bridge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b9e4c165e399a1d6cb5bef0984cb5ed3ec18f88451849e8a142bed9340a0e3c
|
|
| MD5 |
2d4917705e52d2d4d3d32bcfea3eb1ba
|
|
| BLAKE2b-256 |
5911c9318d02ebeea626c39bb8c175520661dc2aba4522d13d060c2b3a17f83e
|