Skip to content

Commit

Permalink
fix sending of multiple values through one characteristic
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaScharf committed Nov 26, 2024
1 parent a84f89b commit e54b054
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
30 changes: 22 additions & 8 deletions sensebox-bike-atrai-v2-esp32s3/src/ble/BLEModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,51 @@ bool BLEModule::writeBLE(const char * characteristicId, float value)
return true;
}

bool BLEModule::writeBLE(const char * characteristicId, uint8_t value, uint8_t value2)
bool BLEModule::writeBLE(const char * characteristicId, float value, float value2)
{
BLECharacteristic *pCharacteristic = pService->getCharacteristic(characteristicId);
uint8_t buf[2] = {value, value2};
uint8_t buf[8];
memcpy(&buf[0], &value, sizeof(float));
memcpy(&buf[4], &value2, sizeof(float));
pCharacteristic->setValue(buf,2);
pCharacteristic->notify();
return true;
}

bool BLEModule::writeBLE(const char * characteristicId, uint8_t value, uint8_t value2, uint8_t value3)
bool BLEModule::writeBLE(const char * characteristicId, float value, float value2, float value3)
{
BLECharacteristic *pCharacteristic = pService->getCharacteristic(characteristicId);
uint8_t buf[3] = {value, value2, value3};
uint8_t buf[12];
memcpy(&buf[0], &value, sizeof(float));
memcpy(&buf[4], &value2, sizeof(float));
memcpy(&buf[8], &value3, sizeof(float));
pCharacteristic->setValue(buf,3);
pCharacteristic->notify();
return true;
}

bool BLEModule::writeBLE(const char * characteristicId, uint8_t value, uint8_t value2, uint8_t value3, uint8_t value4)
bool BLEModule::writeBLE(const char * characteristicId, float value, float value2, float value3, float value4)
{
BLECharacteristic *pCharacteristic = pService->getCharacteristic(characteristicId);
uint8_t buf[4] = {value, value2, value3, value4};
uint8_t buf[16];
memcpy(&buf[0], &value, sizeof(float));
memcpy(&buf[4], &value2, sizeof(float));
memcpy(&buf[8], &value3, sizeof(float));
memcpy(&buf[12], &value4, sizeof(float));
pCharacteristic->setValue(buf,4);
pCharacteristic->notify();
return true;
}

bool BLEModule::writeBLE(const char * characteristicId, uint8_t value, uint8_t value2, uint8_t value3, uint8_t value4, uint8_t value5)
bool BLEModule::writeBLE(const char * characteristicId, float value, float value2, float value3, float value4, float value5)
{
BLECharacteristic *pCharacteristic = pService->getCharacteristic(characteristicId);
uint8_t buf[5] = {value, value2, value3, value4, value5};
uint8_t buf[20];
memcpy(&buf[0], &value, sizeof(float));
memcpy(&buf[4], &value2, sizeof(float));
memcpy(&buf[8], &value3, sizeof(float));
memcpy(&buf[12], &value4, sizeof(float));
memcpy(&buf[16], &value5, sizeof(float));
pCharacteristic->setValue(buf,5);
pCharacteristic->notify();
return true;
Expand Down
8 changes: 4 additions & 4 deletions sensebox-bike-atrai-v2-esp32s3/src/ble/BLEModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class BLEModule
static int createCharacteristic(const char *uuid);

static bool writeBLE(const char * characteristicId, float value);
static bool writeBLE(const char * characteristicId, uint8_t value, uint8_t value2);
static bool writeBLE(const char * characteristicId, uint8_t value, uint8_t value2, uint8_t value3);
static bool writeBLE(const char * characteristicId, uint8_t value, uint8_t value2, uint8_t value3, uint8_t value4);
static bool writeBLE(const char * characteristicId, uint8_t value, uint8_t value2, uint8_t value3, uint8_t value4, uint8_t value5);
static bool writeBLE(const char * characteristicId, float value, float value2);
static bool writeBLE(const char * characteristicId, float value, float value2, float value3);
static bool writeBLE(const char * characteristicId, float value, float value2, float value3, float value4);
static bool writeBLE(const char * characteristicId, float value, float value2, float value3, float value4, float value5);

// Set callback for receiving data
// void setReceiveCallback(void (*callback)(BLEDevice, BLECharacteristic));
Expand Down

0 comments on commit e54b054

Please sign in to comment.