Python client for an Arduino RPC bridge using MsgPack over serial.
Project description
pyrpc
A tiny RPC bridge between Arduino and Python using MsgPack over serial.
It lets you expose C++ functions on an Arduino board and call them directly from Python, with automatic (de)serialization of basic types, containers, and structs.
Arduino side
Install pyrpc from the Arduino Library Manager.
#include <pyrpc.h>
double sum(int i, float d) {
return i + d;
}
void setup() {
Serial.begin(115200);
pyrpc::begin();
pyrpc::register_rpc(
"sum",
sum,
F("@brief sum two numbers @return double @arg i integer @arg d float")
);
}
void loop() {
pyrpc::process(); // handle incoming RPC calls
}
Upload this sketch to your Arduino (baudrate must match the Python side).
Python side
Install the Python package:
pip install pyrpc
Call your Arduino procedures from Python:
from pyrpc import Rpc
rpc = Rpc("/dev/ttyACM0", baudrate=115200)
print(rpc.help) # shows all available remote procedures
result = rpc.call("sum", 3, 1.5)
print("sum result:", result)
rpc.close()
A more complete example is available in the examples/ folder.
Current limitations
When STL containers are not supported, there is a limation of 128 bytes for the serialized data. This means that complex nested structures may not work as expected and the help command may fail to retrieve the full documentation.
Project details
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 ardupyrpc-0.2.0.tar.gz.
File metadata
- Download URL: ardupyrpc-0.2.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf5422bd9d71501ddd7ea12e95cf204a0e11e6473b9f173fd5d34f8754fbbfdd
|
|
| MD5 |
7897ca13c10af84fe9e9123dfa102e61
|
|
| BLAKE2b-256 |
dc67da423609946ed58b8dca113aff3f8a76d2ec8e4fa1cbdf98aa4b22370b66
|
File details
Details for the file ardupyrpc-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ardupyrpc-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a90aba4e33f83ed6d4950fd05d8b6932237e1297bd09a503b2cf24ec85962a8
|
|
| MD5 |
114627cf17d015b2d5a2458d96c41f90
|
|
| BLAKE2b-256 |
473694db15ef54b34ada7523a3df89fa40691fa8db050be60b20b99bcbaef42e
|