From 359eb64f30aa0fb97d2cfdb40d878341ce0e3af2 Mon Sep 17 00:00:00 2001 From: Glahera Date: Sat, 2 Nov 2024 12:14:06 +0700 Subject: [PATCH] Adjusting BLE communication --- src/lightingFirmware/esp32_test0/.theia/launch.json | 8 ++++++++ src/lightingFirmware/esp32_test0/esp32_test0.ino | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/lightingFirmware/esp32_test0/.theia/launch.json diff --git a/src/lightingFirmware/esp32_test0/.theia/launch.json b/src/lightingFirmware/esp32_test0/.theia/launch.json new file mode 100644 index 00000000..7e4253b3 --- /dev/null +++ b/src/lightingFirmware/esp32_test0/.theia/launch.json @@ -0,0 +1,8 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + "version": "0.2.0", + "configurations": [ + + ] +} diff --git a/src/lightingFirmware/esp32_test0/esp32_test0.ino b/src/lightingFirmware/esp32_test0/esp32_test0.ino index a5c9dc59..757c63d7 100644 --- a/src/lightingFirmware/esp32_test0/esp32_test0.ino +++ b/src/lightingFirmware/esp32_test0/esp32_test0.ino @@ -27,7 +27,7 @@ BLECharacteristic* pCharacteristic = NULL; bool deviceConnected = false; bool oldDeviceConnected = false; uint32_t value = 0; -String btmessage; +uint32_t btmessage; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ @@ -288,7 +288,7 @@ void setup() { pAdvertising->setScanResponse(false); pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter BLEDevice::startAdvertising(); - Serial.println("Waiting a client connection to notify..."); + Serial.println("\nWaiting a client connection to notify..."); pinMode(INTERRUPT_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING); @@ -305,7 +305,8 @@ void loop() { // notify changed value if (deviceConnected) { - btmessage = pCharacteristic->getValue().c_str(); + btmessage = pCharacteristic->getData(); + // Serial.print(btmessage); mode = btmessage.toInt(); } // disconnecting @@ -331,6 +332,7 @@ void loop() { button1.pressed = false; // Reset button status to FALSE }; if (modeOld != mode){ + Serial.printf("\nCurrently received data is %p", btmessage); Serial.printf("\nChanging Lighting Preset to Preset %d", mode); } // Wait until the packet is finished being sent before proceeding.