# Internet Of Things

**URL:** https://community.thunkable.com/t/internet-of-things/1941919
**Category:** BLE / BlueTooth
**Tags:** firebase
**Created:** [June 27, 2022, 9:39am UTC](https://community.thunkable.com/t/internet-of-things/1941919 "2022-06-27T09:39:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![uj-ulongjep](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/uj-ulongjep/32/119596_2.png) [@uj-ulongjep](https://community.thunkable.com/u/uj-ulongjep)
#### Post date: [June 27, 2022, 9:39am UTC](https://community.thunkable.com/t/internet-of-things/1941919/1 "2022-06-27T09:39:15Z")

</div>

Please help master…how to use the example firebase Demo ESP8266 below, in order to control the light on/off thunkable+firebase+nodeMCU ESP 8266…

```auto

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run example.
#define FIREBASE_HOST "example.firebaseio.com"
#define FIREBASE_AUTH "token_or_secret"
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"

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

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

int n = 0;

void loop() {
  // set value
  Firebase.setFloat("number", 42.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);
  
  // update value
  Firebase.setFloat("number", 43.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // get value 
  Serial.print("number: ");
  Serial.println(Firebase.getFloat("number"));
  delay(1000);

  // remove value
  Firebase.remove("number");
  delay(1000);

  // set string value
  Firebase.setString("message", "hello world");
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /message failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);
  
  // set bool value
  Firebase.setBool("truth", false);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /truth failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // append a new value to /logs
  String name = Firebase.pushInt("logs", n++);
  // handle error
  if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;
  }
  Serial.print("pushed: /logs/");
  Serial.println(name);
  delay(1000);
}

```

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [June 27, 2022, 3:19pm UTC](https://community.thunkable.com/t/internet-of-things/1941919/2 "2022-06-27T15:19:43Z")

</div>

White this may be a post better suited for the [Arduino Community](https://forum.arduino.cc/) or [StackOverflow](https://stackoverflow.com/) 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! 🙂

```auto
#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);
 
}

```

 ![IMG_7128.HEIC](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/0/207e8cc4dfd4a633c51261c4e7f74152f5a3dd0c.jpeg)  
\*\*that’s a 220 **Ω** resistor and an esp32 nodeMCU unit

I just reread this and am wondering if I misunderstood. Do you want to control the device from data you are sending to firebase from a thunkable app?

---

<div class="post-metadata">

### Author: ![uj-ulongjep](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/uj-ulongjep/32/119596_2.png) [@uj-ulongjep](https://community.thunkable.com/u/uj-ulongjep)
#### Post date: [June 28, 2022, 1:56am UTC](https://community.thunkable.com/t/internet-of-things/1941919/3 "2022-06-28T01:56:01Z")

</div>

Thanks…yes…I want to control NodeMCU from Thunkable on/off electric light  
Apps Thunkable+Firebase+NodeMcu+Relay

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [June 28, 2022, 11:51am UTC](https://community.thunkable.com/t/internet-of-things/1941919/4 "2022-06-28T11:51:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![uj-ulongjep](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/uj-ulongjep/32/119596_2.png) [@uj-ulongjep](https://community.thunkable.com/u/uj-ulongjep)
#### Post date: [June 28, 2022, 12:43pm UTC](https://community.thunkable.com/t/internet-of-things/1941919/5 "2022-06-28T12:43:24Z")

</div>

ok… thanks…i want this application to be controlled from the internet

![My App IOT](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/e/eed34fde98103d479b277b5b7fc5dd8eac021b37.png)

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [June 28, 2022, 12:46pm UTC](https://community.thunkable.com/t/internet-of-things/1941919/6 "2022-06-28T12:46:04Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![uj-ulongjep](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/uj-ulongjep/32/119596_2.png) [@uj-ulongjep](https://community.thunkable.com/u/uj-ulongjep)
#### Post date: [June 28, 2022, 1:26pm UTC](https://community.thunkable.com/t/internet-of-things/1941919/7 "2022-06-28T13:26:04Z")

</div>

Yes, that is true

do you want to control those devices via the internet from your app? (for example, to turn off lights when you’re not home)…

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:13pm UTC](https://community.thunkable.com/t/internet-of-things/1941919/8 "2024-11-08T13:13:08Z")

</div>


