How To Return Struct To RPC Call On Arduino Giga

Hello everyone, would anyone know how to return multiple pieces of data from an RPC call function between two cores on the Arduino Giga. I'm trying to figure out how to eventually return multiple sensor data points in one request to the main core. My attempt so far is below. Thanks in advance to anyone who can help me! :slight_smile:

PS the error I'm getting is: "error: 'const struct FOO' has no member named 'msgpack_object' "

#include "Arduino.h"
#include "RPC.h"

struct FOO{
  int i;
  int j;
};

void setup() { 
  RPC.begin(); //Boots the M4 core
  Serial.begin(9600);
  while(!Serial){};
  if (currentCPU() == "M4") {
    startM4();
  }

  if (currentCPU() == "M7") {
    startM7();
  }
}

void loop() {

}

String currentCPU() {
  if (HAL_GetCurrentCPUID() == CM7_CPUID) {
    return "M7";
  } else {
    return "M4";
  }
}
#include "Arduino.h"
#include "RPC.h"

void startM7() {
  setupM7();
  loopM7();
}

void setupM7() {
  
}

void loopM7() {
  for (;;) {
    delay(1000);
    long time = micros();
    auto result = RPC.call("getI").as<FOO>();
    long time2 = micros();
    Serial.println(time2 - time);
    Serial.println(result.i);
    Serial.println(result.j);
    Serial.println("");
  }
}
#include "Arduino.h"
#include "RPC.h"

int i = 0;

void startM4(){
  setupM4();
  loopM4();
}

void setupM4(){
  RPC.bind("getI", getI);
}

void loopM4(){
  for(;;){
    i++;
    delay(1000);
  }
}

FOO getI(){
  FOO data;
  data.i = i;
  data.j = i+1;
  return data;
}

The error you are seeing is related to the fact that you are not returning anything from the getI() function. In order to return the FOO struct from this function, you need to add a return statement to the end of the function like this:

kotlinCopy code

FOO getI(){
  FOO data;
  data.i = i;
  data.j = i+1;
  return data;
}

Z

sorry my mistake, I deleted that just before posting this, same error. Original post updated to include missing line. Any other ideas?

Here is the solution: How to return multiple pieces of data from an RPC.call/RPC.bind

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