Arduino R4 Wifi connect with realdash

Hello im using this code on my new arduino R4 wifi as an access point, i can connect with the phone to the wifi but when i go to settings in realdash it wants me to put enter ip adress in wifi/lan settings. What ip adress is it looking for, is it the phones ip adress or the arduinos?

I tried both ip adresses of the arduino wifi / and my samsung phone

#include <CAN.h>
#include "WiFiS3.h"
#include "arduino_secrets.h"

char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;        // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;        

WiFiServer server(35000);
WiFiClient connectedClient; // Declare the connected client variable

// RealDash CAN frame headers
const byte RD_FRAME_HEADER[] = {0x44, 0x33, 0x22, 0x11};

//------------------------------------------------------------------------------
// Settings
#define CAN_SPEED (500E3) // Adjust this to your CAN network speed
#define SERIAL_BAUD_RATE 250000 // Adjust this to your serial communication speed

//------------------------------------------------------------------------------
// Inits, globals
typedef struct {
  long id;
  byte rtr;
  byte ide;
  byte dlc;
  byte dataArray[8]; // Adjust the size to match your CAN messages
} packet_t;

//------------------------------------------------------------------------------
// Printing a packet to serial
void printHex(long num) {
  if (num < 0x10) {
    Serial.print("0");
  }
  Serial.print(num, HEX);
}

void printPacket(packet_t *packet) {
  // packet format (hex string): [ID],[RTR],[IDE],[DATABYTES 0..8B]\n
  // example: 014A,00,00,1A002B003C004D\n
  printHex(packet->id);
  Serial.print(",");
  Serial.print(packet->rtr, HEX);
  Serial.print(",");
  Serial.print(packet->ide, HEX);
  Serial.print(",");
  Serial.print(packet->dlc, DEC);
  Serial.print(",");

  for (int i = 0; i < packet->dlc; i++) {
    Serial.print(packet->dataArray[i], HEX);
    Serial.print(",");
  }

  Serial.println();
}

//------------------------------------------------------------------------------
// Forward a CAN packet as RealDash CAN '44' frame
void forwardAsRD44Frame(packet_t *packet, WiFiClient client) {
  // RealDash '44' frame format:
  // 4 bytes - 0x44,0x33,0x22,0x11
  // 4 bytes - CAN frame id number (32bit little endian value)
  // 8 bytes - CAN frame payload (data)

  byte header[] = {0x44, 0x33, 0x22, 0x11};
  client.write(header, 4);
  client.write((byte *)&packet->id, 4);
  client.write(packet->dataArray, 8);
}

//------------------------------------------------------------------------------
// CAN RX, TX
void onCANReceive(int packetSize) {
  // received a CAN packet
  packet_t rxPacket;
  rxPacket.id = CAN.packetId();
  rxPacket.rtr = CAN.packetRtr() ? 1 : 0;
  rxPacket.ide = CAN.packetExtended() ? 1 : 0;
  rxPacket.dlc = CAN.packetDlc();
  byte i = 0;
  while (CAN.available()) {
    rxPacket.dataArray[i++] = CAN.read();
    if (i >= (sizeof(rxPacket.dataArray) / (sizeof(rxPacket.dataArray[0])))) {
      break;
    }
  }

  // Forward the received packet as RealDash '44' frame to the connected client
  forwardAsRD44Frame(&rxPacket, connectedClient);
}

//------------------------------------------------------------------------------
// Setup
void setup() {
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // Don't continue
    while (true);
  }

  // By default, the local IP address will be 192.168.4.1
  // You can override it with the following:
  WiFi.config(IPAddress(192, 10, 0, 1));

  int status = WiFi.beginAP(ssid, pass);
  if (status != WL_AP_LISTENING) {
    Serial.println("Creating access point failed");
    // Don't continue
    while (true);
  }

  // Wait 10 seconds for connection
  delay(10000);

  // Start the web server on port 80
  server.begin();

  Serial.begin(SERIAL_BAUD_RATE);
  while (!Serial) {
    // Wait for serial port to connect (needed for native USB port only)
  }

  if (!CAN.begin(CAN_SPEED)) {
    Serial.println("Starting CAN failed!");
    while (1);
  }

  // Register the receive callback
  CAN.onReceive(onCANReceive);

  Serial.println("CAN RX TX Started");
}

//------------------------------------------------------------------------------
// Main
void loop() {
  // Handle any other tasks if needed

  // Check for incoming client connections
  WiFiClient client = server.available();

  if (client) {
    Serial.println("New client connected");

    // Set the connected client to the newly connected client
    connectedClient = client;
  }
}

Impossible to troubleshoot this sort of projects remotely. The IP address that you enter to RealDash is the IP address of your WiFi device to connect to.


I got simulated packets to show in realdash on my phone now from my arduino r4 so happy :slightly_smiling_face::slightly_smiling_face::slightly_smiling_face:

i finally got everything working, but im only getting 37 packets/sec at max and this is really slow and laggy… any advise on what i could do?

The bike spits out around 400 packets per second.

Impossible to remotely troubleshoot this sort of custom hardware projects. We use TCP/IP simulator for our testing and we typically get around 5000 frames per second on local network so I do not believe that receiving end is the bottleneck.