BLE - basic question

Hi All,

New to the forums, was programming before in Python and I must say the change feels big.
Currently I am doing a project with an ESP32 with BLE to switch some relays.

Now I am having the following problem and just can figure out how to do it, maybe one of you guys can help me on the way.

I created several relays characteristics and want to be able to switch the relay on and off on the moment the ESP receives a write on BLE.

// Relay1
char Relay1NameID[37] = "8469a6de-861a-11ea-bc55-0242ac130002";
char Relay1StateID[37] = "b3364172-8721-11ea-bc55-0242ac130003";
char Relay1Name[8] = "Relay1";

BLECharacteristic RelayNameCharacteristic1(BLEUUID(Relay1NameID), BLECharacteristic::PROPERTY_READ);
BLECharacteristic RelayStateCharacteristic1(BLEUUID(Relay1StateID), BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE);

char Relay2NameID[37] = "384f81cc-8720-11ea-bc55-0242ac130003";
char Relay2StateID[37] = "04603914-87b2-11ea-bc55-0242ac130003";
char Relay2Name[8] = "Relay2";

BLECharacteristic RelayNameCharacteristic2(BLEUUID(Relay2NameID), BLECharacteristic::PROPERTY_READ );
BLECharacteristic RelayStateCharacteristic2(BLEUUID(Relay2StateID), BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE);

char Relay3NameID[37] = "81b10b1a-87b1-11ea-bc55-0242ac130003";
char Relay3StateID[37] = "7b3debd6-87b1-11ea-bc55-0242ac130003";
char Relay3Name[8] = "Relay3";

BLECharacteristic RelayNameCharacteristic3(BLEUUID(Relay3NameID), BLECharacteristic::PROPERTY_READ );
BLECharacteristic RelayStateCharacteristic3(BLEUUID(Relay3StateID), BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE);

// Relay Callback

class RelayCallbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *customCharacteristic) {
      std::string rcvString = customCharacteristic->getValue();
      if (rcvString.length() > 0) {
        Serial.println("Value Received for BLEUUID: ");
        for (int i = 0; i < rcvString.length(); ++i)
          value[i] = rcvString[i];
        for (int i = rcvString.length(); i < 50; ++i)
          value[i] = NULL;


      else {
        Serial.println("Empty Value Received!");

the questions that I have is how I can get the class to switch all relays instead of having to write a class for each one seperate.

I am guessing with a multidimensional array where I do a lookup on the BLEUUID, but I just cannot get this to work.

Some pointers would be appreciated.


the questions that I have is how I can get the class...

Which class?

What does the code do now?

Hi Paul,

I meant the class

RelayCallBacks, or perhaps its called a library within arduino?

I have found a solutions myself using a md array, now just need to write a function for it.

char* relays[][7] = {
  {"first1", "second1", "third1", "fourth1", "fifth1", "sixth1", "seventh1"},
  {"first2", "second2", "third2", "fourth2", "fifth2", "sixth2", "seventh2"},
  {"first3", "second3", "third3", "fourth3", "fifth3", "sixth3", "seventh3"},
  {"first4", "second4", "third4", "fourth4", "fifth4", "sixth4", "seventh4"}

const uint8_t numRows = sizeof(relays) / sizeof(relays[0]);

void setup() {
  // put your setup code here, to run once:


  Serial.println("Print number of rows");


void loop() {

int result;
char lookup[7]= "first2";

for(int i = 0; i < numRows; i++){

  for(int j = 0; j < 6; j++){
    result = strcmp(relays[i][j], lookup);
    Serial.println("Result is:");