Internet Of Things

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…


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

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! :slight_smile:

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


**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?

1 Like

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

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.

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

My App IOT

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)

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)…