Everytime the arduino shows up on my phone it says i need an app to connect to it? I dont understand why and im stuck... I have also updated the firmwire for the esp32 to 2.0...
<CAN.h>
#include <ArduinoBLE.h>
// 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 9600 // 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;
BLEService bleService("CAN Forwarder");
BLECharacteristic bleCharacteristic("CAN Data", BLERead | BLENotify, sizeof(packet_t));
//------------------------------------------------------------------------------
// Forward a CAN packet as RealDash CAN '44' frame
void forwardAsRD44Frame(packet_t *packet) {
// 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 rd44Frame[16];
memcpy(rd44Frame, RD_FRAME_HEADER, 4);
memcpy(rd44Frame + 4, &packet->id, 4);
memcpy(rd44Frame + 8, packet->dataArray, 8);
bleCharacteristic.writeValue(rd44Frame, sizeof(rd44Frame));
}
//------------------------------------------------------------------------------
// 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
forwardAsRD44Frame(&rxPacket);
}
//------------------------------------------------------------------------------
// Setup
void setup() {
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);
}
BLE.begin();
BLE.setLocalName("CAN Forwarder");
BLE.setAdvertisedService(bleService);
bleService.addCharacteristic(bleCharacteristic);
BLE.addService(bleService);
BLE.advertise();
// register the receive callback
CAN.onReceive(onCANReceive);
Serial.println("CAN RX TX Started");
}
//------------------------------------------------------------------------------
void loop() {
// Empty loop; no additional tasks are needed
BLE.poll();
}
Any ideas ?