Ble connect to arduino problems

I have a problem with the connection between the arduino esp32 wroom and the thunkable app via bluetooth low energy. Does anyone have any idea why this is not working as it should. Thanks for help in advance. And if you have any working example please if you can provide it. I would need to send and receive data and connect which is key. Good day Jernej

I already got this from someone and it doesn’t work as well as it should on BlueLight it doesn’t find it at all


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

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include “DHTesp.h”
#include

/** Comfort profile */
ComfortState cf;
// 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”

BLECharacteristic *pCharacteristic;

#define DHTpin 14 //D5 of NodeMCU is GPIO14

DHTesp dht;

void setup() {
Serial.begin(115200);
Serial.println(“Starting BLE work!”);
Serial.println(“Status\tHumidity (%)\tTemperature (C)\t(F)\tHeatIndex (C)\t(F)”);
dht.setup(DHTpin, DHTesp::DHT11); //for DHT11 Connect DHT sensor to GPIO 17
BLEDevice::init(“esp32 Weather Station”);
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);

pCharacteristic->setValue(“Hello World says Neil”);
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_DEFAULT);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL0);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL1);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL2);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL3);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL4);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL5);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL6);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL7);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_CONN_HDL8);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_ADV);
BLEDevice::setPower(ESP_PWR_LVL_P7, ESP_BLE_PWR_TYPE_SCAN);
BLEDevice::startAdvertising();
Serial.println(“Characteristic defined! Now you can read it in your phone!”);
}

void loop() {
delay(dht.getMinimumSamplingPeriod());

float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

Serial.print(dht.getStatusString());
Serial.print(“\t”);
Serial.print(humidity, 1);
Serial.print(“\t\t”);
Serial.print(temperature, 1);
Serial.print(“\t\t”);
Serial.print(dht.toFahrenheit(temperature), 1);
Serial.print(“\t\t”);
Serial.print(dht.computeHeatIndex(temperature, humidity, false), 1);
Serial.print(“\t\t”);
Serial.println(dht.computeHeatIndex(dht.toFahrenheit(temperature), humidity, true), 1);

TempAndHumidity newValues = dht.getTempAndHumidity();
// Check if any reads failed and exit early (to try again).
if (dht.getStatus() != 0) {
Serial.println("DHT11 error status: " + String(dht.getStatusString()));
}
float heatIndex = dht.computeHeatIndex(newValues.temperature, newValues.humidity);
float dewPoint = dht.computeDewPoint(newValues.temperature, newValues.humidity);
float cr = dht.getComfortRatio(cf, newValues.temperature, newValues.humidity);

String comfortStatus;
switch (cf) {
case Comfort_OK:
comfortStatus = “Decent”;
break;
case Comfort_TooHot:
comfortStatus = “Too hot”;
break;
case Comfort_TooCold:
comfortStatus = “Too cold”;
break;
case Comfort_TooDry:
comfortStatus = “Too dry”;
break;
case Comfort_TooHumid:
comfortStatus = “Too humid”;
break;
case Comfort_HotAndHumid:
comfortStatus = “Hot and humid”;
break;
case Comfort_HotAndDry:
comfortStatus = “Hot and dry”;
break;
case Comfort_ColdAndHumid:
comfortStatus = “Cold and humid”;
break;
case Comfort_ColdAndDry:
comfortStatus = “Cold and dry”;
break;
default:
comfortStatus = “psh, we don’t know what to call it.”;
break;
};

// create string
String myString = String(“{"T":"” + String(dht.toFahrenheit(newValues.temperature)) + “","H":"” + String(newValues.humidity) + “","I":"” + String(dht.toFahrenheit(heatIndex)) + “","D":"” + String(dht.toFahrenheit(dewPoint)) + "","comfort":" " + comfortStatus + “"}”);
Serial.println(myString);

// get length of string (with one extra character for the null terminator)
int str_len = myString.length() + 1;

// Prepare the character array (the buffer)
char char_array[str_len];

// copy the string into char_array
myString.toCharArray(char_array, str_len);

//update the ble characteristic
pCharacteristic->setValue(char_array);

}

I have bought an extra part if that helps
I need to find out how it is being sent and that it connects because I haven’t found out for a long time.

@jernej.zupanc37zfze9 BLE is not a premium feature, it is available to all Creators.

The if else statement is a little off but should not have any bearing on the results not showing

If BlueLight is not seeing the device either, the issue is in the setup of the specific Bluethooth module.

I apologise, I misspoke. Bluelight sees it, it’s just that the thunkable app doesn’t detect anyone in the vicinity.

Made in the same way as this or copied

Are you testing with Thunkable Live? iOS or Android? Or is this a downloaded app?

Thunkable Live on Android and not downloaded

Ah, I found the issues. The incomplete if else is causing an issue, please remove that.

Second, this is an old project Jared created, our BLE blocks have updated since this. Can you just pull in a new Scan block from the BLE drawer?

I just tested with this combination and it is working now.

When I uninstall and make it so it says this on my phone

Hi @jernej.zupanc37zfze9
Could you please check that the location is active on your device and the app has permission to use it?

Location is on on your device. On the app, sorry, but I don’t know where to check. I haven’t noticed it yet. If you can please tell me where I can find it to check. Good day Jernej

On the app settings.


This is what you mean

No, I mean the settings of the app in your Android device


This?

App Info

Thunkable

OPEN UNINSTALL FORCE STOP

Notifications

  • 0 notifications this week

Permissions

  • Location

Storage & Cache

  • Used: 311 MB - Internal Storage

Mobile Data & Wi-Fi

  • Downloaded 808 MB since Oct 31, 2024

Usage Time

Battery

  • 0% usage since last full charge

Default Opening

  • The app is allowed to open supported links

I sincerely apologise, but I’m not skilled in this

On the permissions, the “Nearby devices” should be added as well


{CBC6C271-24EA-49A6-8B4D-C21945086523}

Now it tells me how to make it send the values correctly. Thank you for your help and quick response

I’ve already figured out what’s wrong. Thank you for all your previous help. Have a nice day Jernej