Hi, im using the RPC tutorial from the docs given by arduino and changed it so it works with my own variables. The problem is that the data is mismatching with the values i'm receiving.
Here is my C++ side:
void setup() {
Serial.begin(115200);
RPC.begin();
RPC.bind("temperatures", [] { return device.temperatures.empty() ? std::vector<double>() : device.temperatures; });
RPC.bind("faulty", [] { return device.faultyThermocouples.empty() ? std::vector<int>() : device.faultyThermocouples; });
RPC.bind("avg", [] { return device.getAverageTemperature(); });
RPC.bind("status", [] { return device.getStatus(); });
RPC.bind("proc", [] { return device.getProcedure(); });
RPC.bind("proces", [] { return device.getProces(); });
RPC.bind("stemp", [] { return device.getStrifeTemp(); });
RPC.bind("set_action", setAction);
RPC.bind("set_preset_data", extractPresetValues);
}
Python application function for calling the data:
def get_data_from_m4():
rpc_address = RpcAddress(m4_proxy_address, m4_proxy_port)
data = ()
try:
rpc_client = RpcClient(rpc_address)
temperatures = rpc_client.call('temperatures')
rpc_client = RpcClient(rpc_address)
faulty = rpc_client.call('faulty')
rpc_client = RpcClient(rpc_address)
avg = rpc_client.call('avg')
rpc_client = RpcClient(rpc_address)
status = rpc_client.call('status')
rpc_client = RpcClient(rpc_address)
proc = rpc_client.call('proc')
rpc_client = RpcClient(rpc_address)
proces = rpc_client.call('proces')
rpc_client = RpcClient(rpc_address)
stemp = rpc_client.call('stemp')
data = temperatures, faulty, avg, status, proc, proces, stemp
except Exception as e:
print(f"Error fetching data from M4: {e}")
return None
return data
Main loop message to a websocket:
if len(data) > 0 and ws_handler.has_sent_verification:
message = {
"temperatures": data[1],
"faulty": data[2],
"avg": data[3],
"status": data[4],
"proc": data[6],
"proces": data[5],
"stemp": data[0],
"time": elapsed_time
}
await ws_handler.send_message(json.dumps(message))
await asyncio.sleep(publish_interval)
Now as you can see the way i'm sending the message it's not from 0 to 6 in order. This is because the order is changing everytime im restarting the C++ side. Is there a way to ensure im receiving the data in the correct order? call by Key?