Adjusting BLE communication

This commit is contained in:
Glahera 2024-11-02 12:14:06 +07:00
parent 703a3e0c38
commit 359eb64f30
2 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,8 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
]
}

View File

@ -27,7 +27,7 @@ BLECharacteristic* pCharacteristic = NULL;
bool deviceConnected = false; bool deviceConnected = false;
bool oldDeviceConnected = false; bool oldDeviceConnected = false;
uint32_t value = 0; uint32_t value = 0;
String btmessage; uint32_t btmessage;
// See the following for generating UUIDs: // See the following for generating UUIDs:
// https://www.uuidgenerator.net/ // https://www.uuidgenerator.net/
@ -288,7 +288,7 @@ void setup() {
pAdvertising->setScanResponse(false); pAdvertising->setScanResponse(false);
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
BLEDevice::startAdvertising(); BLEDevice::startAdvertising();
Serial.println("Waiting a client connection to notify..."); Serial.println("\nWaiting a client connection to notify...");
pinMode(INTERRUPT_PIN, INPUT_PULLUP); pinMode(INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING); attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING);
@ -305,7 +305,8 @@ void loop() {
// notify changed value // notify changed value
if (deviceConnected) { if (deviceConnected) {
btmessage = pCharacteristic->getValue().c_str(); btmessage = pCharacteristic->getData();
// Serial.print(btmessage);
mode = btmessage.toInt(); mode = btmessage.toInt();
} }
// disconnecting // disconnecting
@ -331,6 +332,7 @@ void loop() {
button1.pressed = false; // Reset button status to FALSE button1.pressed = false; // Reset button status to FALSE
}; };
if (modeOld != mode){ if (modeOld != mode){
Serial.printf("\nCurrently received data is %p", btmessage);
Serial.printf("\nChanging Lighting Preset to Preset %d", mode); Serial.printf("\nChanging Lighting Preset to Preset %d", mode);
} }
// Wait until the packet is finished being sent before proceeding. // Wait until the packet is finished being sent before proceeding.