mobizt / Firebase-ESP32

[DEPRECATED]🔥 Firebase RTDB Arduino Library for ESP32. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
415 stars 118 forks source link

HELP #133

Closed noppawitflam closed 3 years ago

noppawitflam commented 3 years ago

Hello I'm Noppawit, (Thai) I need use firebase for my project but I use esp32s2 , Can you help me please? My problem is esp32s2 can not connect firebase. Thank you Noppawit

mobizt commented 3 years ago

Please post your code and the bebug message here.

noppawitflam commented 3 years ago
#include <WiFi.h>
#include "FirebaseESP32.h"

#define FIREBASE_HOST "*********.firebaseio.com" //Change to your Firebase RTDB project ID e.g. Your_Project_ID.firebaseio.com
#define FIREBASE_AUTH "********************************" //Change to your Firebase RTDB secret password
#define WIFI_SSID "NOPPAWIT"
#define WIFI_PASSWORD "1212312121"

//Define Firebase Data objects
FirebaseData firebaseData1;
FirebaseData firebaseData2;

const int ledPin =  19; //GPIO19 for LED
const int swPin =  18; //GPIO18 for Switch
bool swState = false;
String path = "/Nodes";
String nodeID = "Node1"; //This is this node ID to receive control
String otherNodeID = "Node2"; //This is other node ID to control

void streamCallback(StreamData data)
{
  if (data.dataType() == "boolean") {
    if (data.boolData())
      Serial.println("Set " + nodeID + " to High");
    else
      Serial.println("Set " + nodeID + " to Low");
    digitalWrite(ledPin, data.boolData());
  }
}

void streamTimeoutCallback(bool timeout)
{
  if (timeout)
  {
    Serial.println();
    Serial.println("Stream timeout, resume streaming...");
    Serial.println();
  }
}

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode(swPin, INPUT);
  Serial.println();
  Serial.println();
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  if (!Firebase.beginStream(firebaseData1, path + "/" + nodeID))
  {
    Serial.println("Could not begin stream");
    Serial.println("REASON: " + firebaseData1.errorReason());
    Serial.println();
  }

  Firebase.setStreamCallback(firebaseData1, streamCallback, streamTimeoutCallback);
}

void loop()
{
  if (digitalRead(swPin) != swState) {
    bool _swState = swState;
    swState = digitalRead(swPin);

    if (Firebase.setBool(firebaseData2, path + "/" + otherNodeID, swState)) {
      if (swState)
        Serial.println("Set " + otherNodeID + " to High");
      else
        Serial.println("Set " + otherNodeID + " to Low");
    } else {
      swState = _swState;
      Serial.println("Could not set " + otherNodeID);
    }

  }
}

Capture

Capture2 c:/users/noppawit/documents/arduino/hardware/espressif/esp32/tools/xtensa-esp32s2-elf/bin/../lib/gcc/xtensa-esp32s2-elf/8.4.0/../../../../xtensa-esp32s2-elf/bin/ld.exe: C:\Users\Noppawit\Documents\Arduino\Hardware\espressif\esp32/tools/sdk/esp32s2/lib\librtc.a(rtc.o)(.text.rtc_pad_gpio_wakeup+0x50b7fb000000a9): could not decode instruction; possible configuration mismatch

mobizt commented 3 years ago

The problem is no internet connection, your WiFi hotspot or router may not access to the internet.

mobizt commented 3 years ago

You can test with other APs e.g. mobile hotspot.

Fantom-3000 commented 3 years ago

Добрый вечер! А правила в базе данных правильно выставлены? База данных в тестовом режиме?

mobizt commented 3 years ago

@Fantom-3000 The database rules are not applied when you authenticate with legacy token (database secret).