SimpleRPC version 3.0.0

I would like to bring the latest version of the SimpleRPC library to your attention.

Summary
The SimpleRPC library provides an easy way to export Arduino functions as remote procedure calls. The exported method definitions are communicated to the host, which is then able to generate an API interface.

For each method, only one additional line of code is needed for exporting. On the host, only one function call is needed to perform a remote procedure call.

The Arduino library is independent of any host implementation, we provide a Python API library as a reference implementation.

Features

  • Automatic parameter- and return type inference.
  • Support for all native C types and strings.
  • Support for arbitrary functions and class methods.
  • Optional function and parameter naming and documentation.
  • Support for PROGMEM’s F() macro to reduce memory footprint.
  • Support for compound data structures like Tuples, Objects (Tuples with internal structure), Vectors and arbitrary combinations of these.
  • Support for different types of I/O interfaces via plugins.
  • Support for using multiple interfaces at the same time.

Currently, the following plugins are available:

  • Hardware serial.
  • Software serial (untested).
  • Wire (untested).
  • Ethernet (untested).

Example

Simply pass any function as parameter to the interface() function.

#include <simpleRPC.h>

HardwareSerialIO io; // One of the plugins.

void setup(void) {
  Serial.begin(9600);
  io.begin(Serial);
}

void loop(void) {
  interface(io, digitalRead, "", digitalWrite, "");
}

These functions are now exposed to the host under the names method0() and method1().

>>> from simple_rpc import Interface
>>> 
>>> interface = Interface('/dev/ttyACM0')
>>> 
>>> interface.method0(8)        # Read from pin 8.
0
>>> interface.method1(13, True) # Turn on LED.

Exposed functions and parameters can be named and supplied with documentation.

interface(
  io,
  digitalRead, "digital_read: Read digital pin. @pin: Pin number. @return: Pin value.",
  digitalWrite, "digital_write: Write to a digital pin. @pin: Pin number. @value: Pin value.");

This is reflected on the host.

>>> help(interface.digital_read)
Help on method digital_read:

digital_read(pin) method of simple_rpc.simple_rpc.Interface instance
    Read digital pin.

    :arg int pin: Pin number.

    :returns int: Pin value.

>>> interface.digital_read(8)
0
>>> interface.digital_write(13, True)

Host implementations
The protocol is fully documented to facilitate implementation of host API libraries. Merge- and feature requests and are welcome.

Plugins
Contributions in the form of new plugins or testing of existing plugins are welcome.

With kind regards,
Jeroen