White this may be a post better suited for the Arduino Community or StackOverflow I wanted to jump in as I was able to set this up relatively easily. FWIW the code you have there is for passing data to firebase which could then be fed into a Thunkable app!
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
const byte ledG = 33;
#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 setup() {
Serial.begin(115200);
pinMode(ledG, OUTPUT);
BLEDevice::init("Thunkable & esp32");
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("Turn me on/off");
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
I think the best place to get support for how to code the thing will be on the Arduino forum.
Creating the app is pretty easy. You’ll only use a few blocks to control your Bluetooth device. Can you give more context of what you’re trying to accomplish here? You will not need firebase in order to control an led via your node MCU unit. You simply need a breadboard, an LED, some jumper wires, and your device.
You code your device to accept a string that either is or is not correct. If the string is correct you can turn on the light if the string is incorrect turn off the light.
Perhaps if you can give me more context on how firebase comes into play I can help you with some ideas around that.
do you want the app controlled from the internet
or
do you want to control those devices via the internet from your app? (for example, to turn off lights when you’re not home)