Skip to content

Commit

Permalink
receiving data
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaScharf committed Dec 13, 2024
1 parent fb7ec74 commit 2e3fb6e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions sensebox-bike-atrai-v2-esp32s3/src/ble/BLEModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ BLEService *pService;

char macString[32]; // Enough space for the MAC string

class CustomBLECallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) override {
std::string value = pCharacteristic->getValue();

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

BLEModule::BLEModule()
{
bleName = "";
Expand Down Expand Up @@ -64,6 +78,21 @@ int BLEModule::createCharacteristic(const char *uuid)
return 1;
}

// for receiving data
int BLEModule::createCharacteristicWithCallback(const char *uuid) {
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
uuid,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_INDICATE |
BLECharacteristic::PROPERTY_NOTIFY
);

// Attach the callback to handle incoming data
pCharacteristic->setCallbacks(new CustomBLECallbacks());
return 1;
}

bool BLEModule::writeBLE(const char * characteristicId, float value)
{
BLECharacteristic *pCharacteristic = pService->getCharacteristic(characteristicId);
Expand Down
1 change: 1 addition & 0 deletions sensebox-bike-atrai-v2-esp32s3/src/ble/BLEModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BLEModule

// Create a BLE characteristic
static int createCharacteristic(const char *uuid);
static int createCharacteristicWithCallback(const char *uuid);

static bool writeBLE(const char * characteristicId, float value);
static bool writeBLE(const char * characteristicId, float value, float value2);
Expand Down

0 comments on commit 2e3fb6e

Please sign in to comment.