Skip to main content

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 ardupyrpc

Call your Arduino procedures from Python:

from ardupyrpc 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

ardupyrpc-0.2.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

ardupyrpc-0.2.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file ardupyrpc-0.2.1.tar.gz.

File metadata

  • Download URL: ardupyrpc-0.2.1.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

Hashes for ardupyrpc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7c96b94dde5e7d3e7c6dc0df37a1f570e50ad5109262c70988369867935302e8
MD5 cc389dec691150390dc21d149b594a7f
BLAKE2b-256 48482f78d10c02e6d752f92c805fce56955856bf11dd55af5108b7d893b01c0c

See more details on using hashes here.

File details

Details for the file ardupyrpc-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ardupyrpc-0.2.1-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

Hashes for ardupyrpc-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 137e9407810517dd3d22409d25b93d73291279734fdef38c0dca0e0ef76727fb
MD5 86917a5c1de0b788d82c54e076293dbf
BLAKE2b-256 34a378561b4d3a21802c5a02f18b857370945cc9ee47d6a273610da07096b731

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page