@realdashdev, here is my updated code, I can confirm that I receive ELM327 commands with both racechrono and torque, as a carista elm327 ble odb,
but real dash doesnât connect,
#include <BLE2902.h>
#include <BLECharacteristic.h>
#include <BLEDevice.h>
namespace elm327 {
class device final : public BLEServerCallbacks {
public:
~device() noexcept override = default;
static device& get() noexcept;
bool connected() const noexcept { return _server->getConnectedCount() > 0; }
bool start(BLECharacteristicCallbacks* callbacks) noexcept;
void send(uint8_t* data, size_t len) noexcept;
void onConnect(BLEServer*) override;
void onDisconnect(BLEServer*) override;
void stats() noexcept {}
private:
static constexpr uint16_t elm327_service_uuid = 0xfff0;
static constexpr uint16_t ELM327_RX_uuid = 0xfff1;
static constexpr uint16_t ELM327_TX_uuid = 0xfff2;
device() noexcept;
BLEServer* _server;
BLEService* _service;
BLECharacteristic* _ELM327_RX;
BLECharacteristic* _ELM327_TX;
BLE2902 _2902_desc;
bool _client_connected;
unsigned long _ble_count;
};
device& device::get() noexcept {
static device instance;
return instance;
}
device::device() noexcept : _server(nullptr), _service(nullptr), _ELM327_RX(nullptr), _ELM327_TX(nullptr), _2902_desc(), _client_connected(false), _ble_count(0UL) {
_2902_desc.setNotifications(true);
}
bool device::start(BLECharacteristicCallbacks* callbacks) noexcept {
BLEDevice::init(âCaristaâ);
BLEDevice::setPower(ESP_PWR_LVL_P9);
_server = BLEDevice::createServer();
_server->setCallbacks(this);
_service = _server->createService(elm327_service_uuid);
// ELM327_RX with Notify and Indicate properties
_ELM327_RX = _service->createCharacteristic(ELM327_RX_uuid,
BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE);
_ELM327_RX->addDescriptor(new BLE2902());
// ELM327_TX with Write and Write No Response properties
_ELM327_TX = _service->createCharacteristic(ELM327_TX_uuid,
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR);
_ELM327_TX->setCallbacks(callbacks);
_service->start();
BLEAdvertising* advertising = BLEDevice::getAdvertising();
advertising->addServiceUUID(_service->getUUID());
advertising->setScanResponse(false);
BLEDevice::startAdvertising();
return true;
}
void device::onConnect(BLEServer*) {
_client_connected = true;
Serial.println(âDevice connected!â);
// Send "OK\n" upon connection
const char* welcomeMsg = "OK\n";
_ELM327_TX->setValue((uint8_t*)welcomeMsg, strlen(welcomeMsg));
_ELM327_TX->notify();
}
void device::onDisconnect(BLEServer*) {
_client_connected = false;
Serial.println(âDevice disconnected!â);
BLEDevice::startAdvertising();
}
void device::send(uint8_t* data, size_t len) noexcept {
if (_client_connected) {
_ELM327_RX->setValue(data, len);
_ELM327_RX->notify();
++_ble_count;
Serial.print("Data sent: ");
for (size_t i = 0; i < len; ++i) {
Serial.print((char)data[i]);
}
Serial.println();
}
}
} // namespace elm327
class MyCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic* characteristic) override {
std::string value = characteristic->getValue();
if (!value.empty()) {
Serial.print("Received ASCII Data: ");
Serial.println(value.c_str());
} else {
Serial.println(âNo data received or data is emptyâ);
}
}
};
elm327::device& ELM327 = elm327::device::get();
void setup() {
Serial.begin(115200);
MyCallbacks* myCallbacks = new MyCallbacks();
if (ELM327.start(myCallbacks)) {
Serial.println(âBLE startup successful.â);
} else {
Serial.println(âERROR: BLE startup failed!â);
esp_restart();
}
}
void loop() {
// Your main code here
}
can you kindly check my code aginst realdash to see why real dash is not working still ?
The photo is both racechrono and torque sending commands to the esp32 s3
But realdash doesnât connect.
Im guessing its UUID related still.
Thanks