Portenta X8 RPC: method not found

Hi,
I'm trying to implement Data Exchange Between Python on Linux and an Arduino Sketch (using tutorial) but getting Python exception "msgpackrpc.error.RPCError: b"'F1' method not found"
F1 is the name of the function I'm trying to run.
Of course, m4-proxy is running.

Here's the sketch that is run:

#include "RPC.h"
#include "SerialRPC.h"
#define PIN_LED     (33u)
#define LED_BUILTIN PIN_LED

int LED_state = HIGH;

void LED() {
    digitalWrite(LED_BUILTIN, LED_state);
    delay(3000);
    LED_state = (LED_state==HIGH)? LOW:HIGH;
}

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);

  RPC.bind("F1", []{ int hi = 1; Serial.println("in F1"); return hi; });
}

void loop() 
{
  LED();
}

The LED is blinking.

This is the python application from which the RPC is called:

import time
import traceback
from msgpackrpc import Address as RpcAddress, Client as RpcClient, error as RpcError

if __name__ == '__main__':
    rpc_address = RpcAddress('m4-proxy', 5005)
    rpc_client = RpcClient(rpc_address)
    try:
        while True:
            time.sleep(5)
            try:  
                res = rpc_client.call('F1')
                print(res) 

            except RpcError.TimeoutError:
                print("Timed out RPC.")

            except Exception as e: 
                traceback.print_exc()
                print("exception :(  " + str(e))

    except KeyboardInterrupt:
        print('Stopped.')

I'd be grateful for any help to figure out why F1 is not found/called.

Thanks!!

I found these two error handling, see if it helps:

Ref.: rpc error method not found - Google Search

Thanks for replying. The server is running but still same error :sleepy: :sleepy:

Hi @jordy_m,
If you don't change the configuration of the m4-proxy agent, the correct TCP port to use is 5001.

So, the code line for creating the correct rpc_address is

rpc_address = RpcAddress('m4-proxy', 5001)

Please, also check you have the following key in the service defined in your docker-compose.yml file:

    extra_hosts:
      - "m4-proxy:host-gateway"

or to add the --add-host "m4-proxy:host-gateway" parameter to your docker run command line.

The m4-proxy in those strings is actually the DNS name of the X8 as network host as seen from the container. This configuration is needed to reach the m4-proxy agent via TCP from the container because it runs as a plain Linux tool on the X8.

2 Likes

Hi @manchuino,
Thanks! that's was really helpful!
I found a mistake on the py-serialrpc docker-compose.yml

this is what it should look like:

services:
  py-serialrpc:
    build: ./serialrpc
    image: py-serialrpc
    restart: always
    tty: true
    read_only: true
    user: "0"
    ports:
    - "5005:5005"
    extra_hosts:
    - "m4-proxy:host-gateway"
    command: m4-proxy 5000

This was the difference:

 extra_hosts:
    - "m4-proxy:172.17.0.1"

So now the communication is running, not perfectly but still.

Many thanks

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.