Optimizing BLE characteristic desgin

Tobbera
Posts: 1
Joined: Mon May 17, 2021 6:25 pm

Optimizing BLE characteristic desgin

Postby Tobbera » Mon May 17, 2021 6:50 pm

I am in the process of building a battery monitoring device. It will collect several data, approx. 25 int variables, and communicate these to a smartphone app over BLE. Since this is a battery powered device, energy consumption is important. As is speed as it is supposed to update the graph in the smartphone app “live”.

So, the question I’m struggling with is how I shall design my BLE characteristics in the ESP32? Right now, I have made one characteristic for every int var. Like this:

Code: Select all

#define SERVICE_UUID_STATUS "961ba01f-f367-4546-a9fb-8a623dd30c9f"
#define CHARACTERISTIC_UUID_SOCBATT1  "961ba02f-f367-4546-a9fb-8a623dd30c9f"
#define CHARACTERISTIC_UUID_SOCBATT2  "961ba03f-f367-4546-a9fb-8a623dd30c9f"
#define CHARACTERISTIC_UUID_IBAT1 "961ba04f-f367-4546-a9fb-8a623dd30c9f"
#define CHARACTERISTIC_UUID_IBAT2 "961ba05f-f367-4546-a9fb-8a623dd30c9f"
#define CHARACTERISTIC_UUID_IGEN  "961ba06f-f367-4546-a9fb-8a623dd30c9f"
#define CHARACTERISTIC_UUID_ISUN  "961ba07f-f367-4546-a9fb-8a623dd30c9f"
Etc etc…
But I realize that each one of these comes with a fair bit of overhead when their payload is sent over BLE. One alternative I am thinking about is combining several int vars into an array and send in one or two characteristics instead. And then have them broken down in individual vars at the smart phone end. Something like:

Code: Select all

outMsg.buf[0] = SOCBATT1;
outMsg.buf[1] = SOCBATT2;
outMsg.buf[2] = IBAT1;
BLECharacteristic *BATTCharacteristic = STATUSService->createCharacteristic(CHARACTERISTIC_UUID_BATTERY, BLECharacteristic::PROPERTY_READ);
BATTCharacteristic->setValue((uint8_t*)& outMsg.buf, 4);
What is the best way froward?

Thanks in advance.

/Tobias

Who is online

Users browsing this forum: Google [Bot], weoiss and 119 guests