Errors running m4-proxy

Hello, I would like to know if someone else had these problems. I was trying to follow this tutorial 4. Python-Arduino-Data-Exchange but when trying to use sudo docker build . -t py-serialrpc I ran into an error when using compose. The error said it couldn't find a module named "backports" for an import of "backports.ssl_match_hostname" so I added the latter to the requirements file. Ok, so now it at least ran i think. But after a few seconds the container exits with code 137, I only realized this by removing the -d flag in the docker compose command. Also something to note, everytime it tries to pull py-serialrpc it encounters an error and starts building it again. Does anybody know what I could do?.

Hello there,

managed to get the serialrpc to work but you need modify some files:

First in the Dockerfile

FROM python:3.9-alpine AS Build    # <- set the container to fixed image version

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY src/ .

ENTRYPOINT [ "python", "serialrpc.py" ]

then the docker-compose.yml

services:
  py-serialrpc:
    build: ./serialrpc
    image: py-serialrpc
    restart: unless-stopped
    environment:
      - PYTHONUNBUFFERED=1
    volumes:
      - /var/run/secrets:/app/config/
    extra_hosts:
      - "m4-proxy:host-gateway"
    ports:
      - "5005:5005"
    command: m4-proxy 5000

My test code for the M4:

#include <RPC.h>
#include <SerialRPC.h>

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

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println("ON");
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  Serial.println("OFF");
  delay(1000);
}

Hey astrophil, your modified files finally made my serialrpc stay up and running instead of crashing with the above mentioned error codes.
However even with that running the serial output wont show up in the serial monitor in the arduino IDE. Am I doing something wrong? or should the output be received some other way than the serial monitor?

I also use the same code on the M4 as you are using and the LED is flashing red, just the output doesn't show up.

We have the same issue here. Please Arduino Team provide help.

1 Like

How I use this...
The debug output doesn't make it back to the IDE. Bring up a terminal and "ssh" to the portenta-x8. Build the container as shown but don't put the running container in the background. In the terminal run "docker compose up" and the container will run in the foreground displaying the log messages from the arduino side.

Also, I changed the python to the following which provides a much cleaner log text:

import msgpackrpc
import sys
from time import time
from datetime import datetime

server = sys.argv[1]
port = int(sys.argv[2])

print(f'server: {server}, port: {port}')
print("version 1")

client = msgpackrpc.Client(msgpackrpc.Address(server, port))
result = client.call('register', 5005, ['tty'])

class Server(object):
    def tty(self, msg):
        m = msg.decode().rstrip()
        if m != "":
          now = datetime.now()
          dt = now.strftime("%Y-%m-%d %H:%M:%S.%f")
          print("[",dt,"]",m)
        return lenght(msg)


rpc_server = msgpackrpc.Server(Server())
rpc_server.listen(msgpackrpc.Address("localhost", 5005))
rpc_server.start()