RPC bridge from linux side to arduino on C++

While I am waiting for the order to be fulfilled, I am looking at the documentation, with special interest for the Linux/Arduino RPC communication.

The tutorial here shows how to use the Arduino library Arduino_RPClite on the MCU side of the Q, and uses the Python Bridge class in a script running on the MPU side (Linux).

All nice and fine, but I really prefer coding in C++ on the linux side, but I cannot find the documentation for how to do the same RPC calls from a C++ program running on the Linux MPU side.

Any hint on where to look?
Thanks!

Arduino_RouterBridge seems to be a wrapper around SerialTransport of Arduino_RPClite

Great. That’s what I was looking for. Now I just need the Q to arrive.
Thanks!

Now that I have time (and the Q at hand), this is not what I was asking for. Looking into the container ghcr.io/arduino/app-bricks/python-apps-base, I see that the Python Bridge class is pure Python, not a wrapper of some C++ class.
So that is unfortunate. If there's no C++ MPU-side Bridge class, I can only write a custom one, I guess...

Hi @pbosetti

It is recommended to manage all the RPC communications through the arduino-router, which is running as a system daemon on the Linux side. Of course, you can implement an RPC endpoint using any language you prefer.

Thanks, that is a starting point. Documentation is rather sparse though. I mean, there's only the repo README. I suppose one has to implement a MsgPack RPC call and channel it to the socket /var/run/arduino-router.sock according to https://github.com/arduino/arduino-router/tree/main/msgpackrpc, right?

Hey @pbosetti
I just did it. It's pretty easy and straightforward!

Open a unix socket at /var/run/arduino-router.sock and send a MsgPack according to the doc.

Let's say the function to call is set_led_state :

// Desired LED value
bool led_state = true;

// REQUEST format: [type, msgid, method, params]
int type = 0;                               // REQUEST
uint32_t msgid = 50;                        // msgid
std::string method = "set_led_state";       // method
std::vector<msgpack::type::variant> params; // params
  
params.push_back(led_state);                // arguments

// Create the data to send
std::stringstream buffer;
msgpack::pack(buffer, std::make_tuple(type, msgid, method, params));
std::string data = buffer.str();
  
// Send to socket
send(sock_fd, data.c_str(), data.size(), 0);

You can of course create a class for the MsgPack structure.

The simplest way is to use serial port Serial1 on Arduino and /dev/ttyHS1 on Linux to communicate, after deactivating Bridge service with sudo service arduino-router stop

See https://forum.arduino.cc/t/how-to-achieve-communication-between-linux-and-arduino-q-mcu/1426989

Then, on Linux side, you can use any programming language that support serial communication. You can even use simple scripts in bash with redirections to/from /dev/ttyHS1.

Thank you for pointing me in the right direction. You might find the outcome here: https://github.com/MADS-NET/arduinoQ_plugin