Skip to content

Instantly share code, notes, and snippets.

@beegee-tokyo
Last active September 7, 2020 10:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beegee-tokyo/993b250bae96554f0f5066ca554eec3f to your computer and use it in GitHub Desktop.
Save beegee-tokyo/993b250bae96554f0f5066ca554eec3f to your computer and use it in GitHub Desktop.
// Define digital output UUID
#define OUTPUT_UUID 0x2A57
/** Characteristic for digital output */
BLECharacteristic *pCharacteristicOutput;
/**
* MyServerCallbacks
* Callbacks for client write requests
*/
class MyCallbackHandler: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();
int len = value.length();
if (value.length() > 0) {
Serial.println("*********");
Serial.print("New value: ");
for (int i = 0; i < value.length(); i++) {
Serial.print(String(value[i]));
}
Serial.println();
Serial.println("*********");
}
}
};
/**
* initBLEserver
* Setup BLE server
* Setup callbacks for server and pCharacteristicStatus
* Start advertising the BLE service
*/
void initBLEserver() {
// skipped code to initialize the BLE server
// Create BLE Characteristic for Digital output
pCharacteristicOutput = pService->createCharacteristic(
BLEUUID((uint16_t)OUTPUT_UUID),
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristicOutput->setCallbacks(new MyCallbackHandler());
// skipped code to start advertisment
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment