Canbus over Wifi

Hi im sniffing packets from canbus and sending the packets to my phone using Access Point. But its really slow since the vehicle sends out around 600 packets/second and the app only recieves 65packets/second.

I tried cleaning the code which helped a bit, went from 37 > 65 packets/second?

Is this because of my hardware or just by using tcp?

What happens with all the lost packets?

Im using r4wifi & mcp2515

void loop() {
  client = server.available();
  if (client) {
    while (client.connected()) {
      int packetSize = CAN.parsePacket();
      if (packetSize) {
        unsigned long PacketId = CAN.packetId();
        byte buf3[8];
        int i = 0;
        while (i < 8 && CAN.available()) {
          buf3[i] = CAN.read();
          i++;
        }

        // Combine header, ID, and data into canFrameBuffer
        memcpy(canFrameBuffer, RD_FRAME_HEADER, 4);
        memcpy(canFrameBuffer + 4, (const byte*)&PacketId, 4);
        memcpy(canFrameBuffer + 8, (const byte*)buf3, 8);

        // Send the entire CAN frame to client
        client.write(canFrameBuffer, 16);
      }
    }
    client.stop();
    Serial.println("client disconnected");
  }
}

Comment out all the CAN stuff and see how many client.write() per second is possible using a dummy 8 byte load.

im sending 16 bytes in total per can bus message because i have to send 4 bytes as a header for the app on the phone to accept it.

Send dummy packets using whatever length is necessary for your app. That will tell you the theoretical maximum throughput.

Hi chrisisbrown, may I ask you which CAN library are you using with Arduino R4 WIFI? Thanks a lot for your help in advance and have a great day.
Andrea