Go Down

Topic: New serial RPC library. (Read 515 times) previous topic - next topic

jfjlaros

I would like to bring the following 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.


Example

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

Code: [Select]

#include <simpleRPC.h>

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

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


These functions are now exposed to the host under the names method2() and method3().

Code: [Select]

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


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

Code: [Select]

interface(
  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.

Code: [Select]

>>> 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.


With kind regards,
Jeroen.

pert

It's quite unfortunate that your library is not compatible with the Arduino IDE. Only a very small percentage of Arduino users use PlatformIO. The thing is, any library that is compatible with the Arduino IDE is also compatible with PlatformIO, but the reverse is not true. I think your library would be useful to a much larger group of users if you made it compatible with the Arduino IDE. You can find the Arduino Library Specification here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification

jfjlaros

It's quite unfortunate that your library is not compatible with the Arduino IDE.
Thank you for bringing this to my attention. I have made the required changes to the library (I hope). If you have any more suggestions, please let me know.

pert

Way cool! I often get a snobby attitude from PlatformIO users "the Arduino IDE is lame and we intentionally don't want our code to work with it" (even though they will happily advertise their project as "Arduino"). It's quite refreshing to encounter someone who is open to allowing the users to choose whatever IDE works best for them. PlatformIO is great and I fully understand why a more advanced user would prefer it to the Arduino IDE. However, for the average Arduino user, it has a much steeper learning curve and may not provide any additional features they actually need.

Although I am quite capable of using PlatformIO, and do occasionally, I almost always use the Arduino IDE. The reason is that is what the users I'm providing support to are using and if I have good familiarity with it, I can do a better job helping them. Because of this, I tend to focus my contributions to libraries that are Arduino IDE compatible, since I'm not as comfortable with PlatformIO. I did take a quick look at your updated library but did not spot any of the common issues I see so often in libraries. Great work!

Thanks so much for taking the time to do that.

jfjlaros

I do not use an IDE myself, but I fully agree with you that making our work available to a larger audience is important. Especially if it does not take much effort, like in this case.

Should I now proceed to request for this library to be added to the library manager, as described here?

pert

I think that is a very good idea. It will make it very easy for Arduino IDE users to install and update your library and also make it easier for people to find.

There are two things you need to do before submitting your library for addition to the Library Manager index:
  • Update the version field in library.properties to the version number you want to use for the next release.
  • Create a tag or release for the new version.

The reason this is necessary is because at the time of the most recent tag v1.0.3 your library was still not compliant with the requirements of Library Manager. I looked over your library and it's completely compliant with the requirements, other than the need for a new tag.


jfjlaros

Thank you for the extra pointers. I have followed your advice and submitted a request for publication. 

jfjlaros

Good news. The library was added and seems to install fine via the IDE.

Go Up