DIY Esp32_S3 BLE Bug

Hi, i am trying to get race chrono to connect to my esp32 s3 via ble,

using BLE scanner i have no such issues, but with either the DIY UUID's or the veepeak ELM uuids, i cannot get any connection at all, racechrno does not even attempt to connect
This is my code:

#include
#include
#include
#include

// UUIDs for the BLE service and characteristics of your ELM327 device
#define SERVICE_UUID "0000fff0-0000-1000-8000-00805f9b34fb"
#define CHARACTERISTIC_UUID_RX "0000fff1-0000-1000-8000-00805f9b34fb"
#define CHARACTERISTIC_UUID_TX "0000fff2-0000-1000-8000-00805f9b34fb"

BLEServer *pServer = NULL;
BLECharacteristic *pTxCharacteristic;
bool deviceConnected = false;
bool oldDeviceConnected = false;

class ServerCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer *pServer) {
deviceConnected = true;
Serial.println("Device connected");
};

void onDisconnect(BLEServer *pServer) {
deviceConnected = false;
Serial.println("Device disconnected");
}
};

class CharacteristicCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();

if (rxValue.length() > 0) {
Serial.println("Received Value: ");
for (int i = 0; i < rxValue.length(); i++) {
Serial.print(rxValue[i]);
}
Serial.println();
}
}
};

void setup() {
Serial.begin(115200);

BLEDevice::init("VEEPEAK");
pServer = BLEDevice::createServer();
pServer->setCallbacks(new ServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);

BLECharacteristic *pRxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY
);
pRxCharacteristic->setCallbacks(new CharacteristicCallbacks());

pTxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
pTxCharacteristic->addDescriptor(new BLE2902());

pService->start();
pServer->getAdvertising()->start();
Serial.println("Waiting for a client connection to notify...");
}

void loop() {
// Handle connection status changes
if (deviceConnected != oldDeviceConnected) {
if (!deviceConnected) {
pServer->startAdvertising();
}
oldDeviceConnected = deviceConnected;
}

// Read data from Serial and send over BLE
if (Serial.available()) {
String data = Serial.readStringUntil('\n'); // Read the incoming data until newline
if (deviceConnected) {
pTxCharacteristic->setValue(data.c_str()); // Set the value to the Tx Characteristic
pTxCharacteristic->notify(); // Notify the connected device
Serial.print("Transmitted Value: ");
Serial.println(data); // Print the transmitted data
}
}
}


please don't be too hard on me, i am learning, and i am new to BLE, Thanks

Comments

  • Wanted to add, that using serial bluetooth terminal ( android) ,. i can also communicate without issues.

Sign In or Register to comment.