Last active
September 7, 2020 10:37
-
-
Save beegee-tokyo/993b250bae96554f0f5066ca554eec3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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