ESP32 / Arduino - Optimizing BLE characteristic desgin

I am in the process of building a battery monitoring device based on the ESP32, programed in the Arduino environment. 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:

#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:

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.


This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.