Sending BLE commands from MKR 1010

I'm attempting to send commands via bluetooth from a MKR 1010 to ActiveLook glasses using their provided API. The commands can be upwards of 20 Bytes long and I don't know of a way to store a hex string that long. I'm using the bleCharacteristic.writevalue(command) but the data is being truncated. Is there way to store longer strings of HEX values?

#include <ArduinoBLE.h>

// Define ActiveLook advertising data
const char* deviceNamePrefix = "A.LooK";
const char* manufacturerName = "Microoled";
const char* serialNumber = "xxxxxx";   // Replace "xxxxxx" with the actual serial number
const int manufacturerDataLength = 9;  // Length of the manufacturer data

// Custom service UUIDs
const char* activeLookCommandsServiceUUID = "0783B03E-8535-B5A0-7140-A304D2495CB7";
const char* firmwareUpdateServiceUUID = "0000FEF5-0000-1000-8000-00805F9B34FB";

// ActiveLook command characteristic UUIDs
const char* txActiveLookCharacteristicUUID = "0783B03E-8535-B5A0-7140-A304D2495CB8";
const char* rxActiveLookCharacteristicUUID = "0783B03E-8535-B5A0-7140-A304D2495CBA";
const char* controlCharacteristicUUID = "0783B03E-8535-B5A0-7140-A304D2495CB9";
const char* gestureEventCharacteristicUUID = "0783B03E-8535-B5A0-7140-A304D2495CBB";
const char* touchEventCharacteristicUUID = "0783B03E-8535-B5A0-7140-A304D2495CBC";

// ActiveLook command descriptor UUIDs

// BLE advertising parameters
const int initialAdvertisingInterval = 25;

BLEService activeLookCommandsService(activeLookCommandsServiceUUID);  //Creates the service
BLEService firmwareUpdateService(firmwareUpdateServiceUUID);

BLECharacteristic txActiveLookCharacteristic;
BLECharCharacteristic rxActiveLookCharacteristic(rxActiveLookCharacteristicUUID, BLEWrite);  //Creates the RX characteristic
BLECharacteristic controlCharacteristic;
BLECharacteristic gestureEventCharacteristic;
BLECharacteristic touchEventCharacteristic;

BLEDescriptor ServerRXData("2901", "Server RX Data");  //Not sure if this is needed

//0xFFD0 0012 4465 6D6F 0000 0000 0000 0000 00AA

//long approaching = 0xFF 37 ;
int clearScreen[] = { 0xFF, 0x01, 0x00, 0x05, 0xAA };

//Long and int only hold 4 bytes, need to send 20 or more bytes
const long HELLO_TEXT = 0xFF3700140098008000020F68656C6C6F203000AA;  //20 Bytes, Demo hello command form AL API
const size_t CLEAR = 0xFF010005AA;                                   //5 Bytes, Clear Display command from AL API
//const size_t END = 0xAA;

void setup() {
  Serial.begin(9600);
  while (!Serial)
    ;

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");
    while (1)
      ;
  }

  Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer");

  // start scanning for peripherals
  BLE.scan();
}

void loop() {
  // check if a peripheral has been discovered
  BLEDevice peripheral = BLE.available();

  if (peripheral) {
    // discovered a peripheral, print out address, local name, and advertised service
    Serial.print("Found ");
    Serial.print(peripheral.address());
    Serial.print(" '");
    Serial.print(peripheral.localName());
    Serial.print("' ");
    Serial.print(peripheral.advertisedServiceUuid());
    Serial.println();

    // see if peripheral is a LED
    if (peripheral.localName() == "XXXXXX") {
      // stop scanning
      BLE.stopScan();

      explorerPeripheral(peripheral);  //Connects only, removed all other functions
    }

    // Add services
    BLE.setAdvertisedService(activeLookCommandsService);
    BLE.setAdvertisedService(firmwareUpdateService);

    // Add characteristics to services
    activeLookCommandsService.addCharacteristic(txActiveLookCharacteristic);
    activeLookCommandsService.addCharacteristic(rxActiveLookCharacteristic);
    activeLookCommandsService.addCharacteristic(controlCharacteristic);
    activeLookCommandsService.addCharacteristic(gestureEventCharacteristic);
    activeLookCommandsService.addCharacteristic(touchEventCharacteristic);

    // Add descriptor(s) to rx characteristic
    rxActiveLookCharacteristic.addDescriptor(ServerRXData);

    //Serial.print(rxActiveLookCharacteristic.value());
    //rxActiveLookCharacteristic.writeValue(clearScreen[i]);
    //Serial.print(rxActiveLookCharacteristic.value(), HEX);
    //Serial.println();
    //Serial.print(CLEAR_DISPLAY, HEX);
    //Serial.print(rxActiveLookCharacteristicUUID);
    //Serial.println();
    if (peripheral.connected()) {
      //for (int i = 0; i < ; i = i + 1){
      rxActiveLookCharacteristic.writeValue(CLEAR);
      rxActiveLookCharacteristic.writeValue(END);
      //Serial.print(CLEAR, HEX);
    }
  }



  Serial.print(rxActiveLookCharacteristic.value(), HEX);
  //Serial.println();
}
void explorerPeripheral(BLEDevice peripheral) {
  // connect to the peripheral
  Serial.println("Connecting ...");

  if (peripheral.connect()) {
    Serial.println("Connected");
  } else {
    Serial.println("Failed to connect!");
    return;
  }
}

void sendCommand(BLEDevice peripheral) {

  rxActiveLookCharacteristic.writeValue(HELLO_TEXT);
  Serial.println("sent hello");
}
void printServiceUUID(BLEDevice peripheral) {
  // print the advertised service UUIDs, if present
  if (peripheral.hasAdvertisedServiceUuid()) {
    Serial.print("Service UUIDs: ");
    for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
      Serial.print(peripheral.advertisedServiceUuid(i));
      Serial.print(" ");
    }
    Serial.println();
  }
}

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