# BLE\_bluetooth Can't recieve data from arduino (esp32)

**URL:** <https://community.thunkable.com/t/ble-bluetooth-cant-recieve-data-from-arduino-esp32/2066022>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [October 1, 2022, 7:00pm UTC](https://community.thunkable.com/t/ble-bluetooth-cant-recieve-data-from-arduino-esp32/2066022 "2022-10-01T19:00:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![proximilius](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/proximilius/32/140171_2.png) [@proximilius](https://community.thunkable.com/u/proximilius)\
**Post date:** [October 1, 2022, 7:00pm UTC](https://community.thunkable.com/t/ble-bluetooth-cant-recieve-data-from-arduino-esp32/2066022/1 "2022-10-01T19:00:55Z")

</div>

Hi,

I’m trying to recieve some response from arduino to thunkable. When I try to send to arduino ther’s no problem, recieving seems not to fire any erros but no response is shown.

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/2/b2a794dfa638e51ba38faffde52dfc0b0844058c.png)

I have arduino code:

```auto
/*
    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleWrite.cpp
    Ported to Arduino ESP32 by Evandro Copercini
*/

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
const byte ledG = 33;

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

class MyCallbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
      std::string value = pCharacteristic->getValue();

      if (value == "0") {
        digitalWrite(ledG, HIGH);
      } else {
        digitalWrite(ledG, LOW);
      }
    }

   void onRead(BLECharacteristic *pCharacteristic) {
      int MyResponse;
      
      if (digitalRead(ledG) == LOW){
        MyResponse = 1;
      } else { 
        MyResponse = 0;
      }

      pCharacteristic->setValue(MyResponse);
    }

    /*void onRead(BLECharacteristic *pCharacteristic) {
      struct timeval tv;
      gettimeofday(&tv, nullptr);
      std::ostringstream os;
      os << "Time: " << tv.tv_sec;
      pCharacteristic->setValue(os.str());
    }*/
};

void setup() {
  Serial.begin(115200);

  Serial.println("1- Download and install an BLE scanner app in your phone");
  Serial.println("2- Scan for BLE devices in the app");
  Serial.println("3- Connect to MyESP32");
  Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something");
  Serial.println("5- See the magic =)");

  pinMode(ledG, OUTPUT);

  BLEDevice::init("MyESP32");
  BLEServer *pServer = BLEDevice::createServer();

  BLEService *pService = pServer->createService(SERVICE_UUID);

  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setCallbacks(new MyCallbacks());

  pCharacteristic->setValue("Hello World");
  pService->start();

  BLEAdvertising *pAdvertising = pServer->getAdvertising();
  pAdvertising->start();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}

```

---

<div class="post-metadata">

**Author:** ![cassandra](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/cassandra/32/115809_2.png) [@cassandra](https://community.thunkable.com/u/cassandra)\
**Post date:** [October 8, 2022, 11:46am UTC](https://community.thunkable.com/t/ble-bluetooth-cant-recieve-data-from-arduino-esp32/2066022/2 "2022-10-08T11:46:45Z")

</div>

Hi @proximilius, hope you are having a great weekend. Our engineers made an update to our platform last night that should have resolved this. Can you please test this again?

---

<div class="post-metadata">

**Author:** ![proximilius](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/proximilius/32/140171_2.png) [@proximilius](https://community.thunkable.com/u/proximilius)\
**Post date:** [October 8, 2022, 6:49pm UTC](https://community.thunkable.com/t/ble-bluetooth-cant-recieve-data-from-arduino-esp32/2066022/3 "2022-10-08T18:49:31Z")

</div>

Many thanks, now it works.

Maybe the problem was also my “onRead” function inside the arduino script. With the old script my information label on the app refreshed into a blank with no text. After a small change now everything seems to be working.

New arduino snippet (with un changed thunkable blocks):

```auto
void onRead(BLECharacteristic *pCharacteristic) {
      int MyResponse;
      
      if (digitalRead(ledG) == LOW){
        pCharacteristic->setValue("1");
      } else { 
        pCharacteristic->setValue("0");
      }
   }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [January 6, 2023, 6:50pm UTC](https://community.thunkable.com/t/ble-bluetooth-cant-recieve-data-from-arduino-esp32/2066022/4 "2023-01-06T18:50:08Z")

</div>

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