Callback issues while remote controlling


I have some strange behavior on my OpenMV board when trying to play with remote controlling and callbacks by being inspired by provided examples. I might not have well understood how it works so I tried to oversimplify my script in order to check the basis.

Here is the code on the PC side:

import rpc
interface = rpc.rpc_usb_vcp_master('COM5')
result ="two")

And on the board side I have this one:

import network, omv, rpc
interface = rpc.rpc_usb_vcp_slave()
def two():
    return "2".encode()

I would have expected to be able to decode result pretty easily, but instead returns None. Did I miss something obvious there?

Fw version: 3.6.8

Thanks for your help!

None means the calls back failed. So, you have to try again in a loop until it succeeds. The method does try repeatedly for 1 second before giving up.

Was the openmv cam running before you ran the PC side?

Thanks for your help.

I modified the code in order to be able to run several times the call until it succeeds but still after 150+ attempts, it doesn’t work.

The camera is plugged to the computer and powered, main is saved on the drive and camera has been reset. It looks like there is something preventing the camera to run the properly. It drives me hazy.

Here is the modified code (PC side), just in case

import rpc
interface = rpc.rpc_usb_vcp_master('COM5')
result = None
i = 0
while result is None:
    result ="two")
    i += 1
    if i%10 == 0:

I don’t know if it can help, but it might be linked to the above mentioned issue. When connecting to the camera via Putty, in order to access the interpreter, I have need to press enter key and I got the following error (then it comes back to the python interpreter):

Traceback (most recent call last):
  File "<stdin>", line 1
SyntaxError: invalid syntax

I’ve been suspecting a dumb syntax errors (tabs, indentation erros or so), but on such a small code, it’s hard to miss anything…

Mmm, something is broken. I can’t get your example to work either. I do notice that the camera led flashes red after the computer connects which implies an exception happened. If you were able to view the exception message then it would be easy to fix.

The last time I got this working I had to debug with a usb protocol analyzer. Using the VCP port is a real pain. I would suggest using the COM port over hardware serial and only switching to VCP once the code is fully debugged.

Oddly, image streaming works fine with our default example script.

There might be some issue with not starting the camera. Can you start from the jpg image streaming example script and work backwards from there?

If you find the issue please post how you fixed it.

Figured it out, two needs an argument. Even if you don’t use it the Rpc lib can’t call a method without an argument slot.

I’m not certain if this is your only issue, but you need to have a memoryview object defined in the definition of your fcn even if you aren’t using it. It appears to be an Openmv rpc requirement. Try the following and let us know if that resolves your issue.

def two(data):
    return "2".encode()

The docs offer the following on the topic: “The call back should take one argument which will be a memoryview object and it should return a bytes() like object as the result. The call back should return in less than 1 second if possible”

@kwagyeman, I think it might be nice to add this requirement to rpc — rpc library — MicroPython 1.13 documentation

EDIT: Realizing @kwagyeman answered the same thing before I posted.

Thanks for your help! Indeed the argument issue was the one blocking the callback from being executed.
Now I got it working. Let’s build something more serious with scheduled callbacks then. :wink: