mobizt / FirebaseClient

🔥Async Firebase Client for Arduino. Supports Realtime Database, Cloud Firestore Database, Firebase Storage, Cloud Messaging, Google Cloud Functions and Google Cloud Storage.
MIT License
104 stars 6 forks source link

Using TFT_eSPI library causes errors in FirebaseClient (Poor third party lib) #85

Closed Irvan789 closed 3 months ago

Irvan789 commented 3 months ago

Hello, I have IoT project with TFT display, When I try to migrate from Firebase Esp32 to FirebaseClient, this error appears when I want to upload the code to my ESP32. But if i remove the #include <TFT_eSPI.h> the code works well.

Here my code main.cpp

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
WiFiClientSecure ssl_client;

#include <TFT_eSPI.h>
#include <FirebaseClient.h>

#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASS"

#define DATABASE_URL "database_url"
#define API_KEY "firebase_web_api_key"
#define FIREBASE_PROJECT_ID "firebase_project_id"
#define FIREBASE_CLIENT_EMAIL "firebase_client_email"
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----\XXXXXXXXXX\n-----END PRIVATE KEY-----\n";

void timeStatusCB(uint32_t &ts);
void asyncCB(AsyncResult &aResult);
void printResult(AsyncResult &aResult);

DefaultNetwork network;
ServiceAuth sa_auth(timeStatusCB, FIREBASE_CLIENT_EMAIL, FIREBASE_PROJECT_ID, PRIVATE_KEY, 3600);
FirebaseApp app;

using AsyncClient = AsyncClientClass;
AsyncClient aClient(ssl_client, getNetwork(network));

RealtimeDatabase Database;
AsyncResult aResult_no_callback;

void setup()
{
  Serial.begin(115200);
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print("WiFi: Connecting");
    delay(5000);

    if (WiFi.status() == WL_NO_SSID_AVAIL || WiFi.status() == WL_DISCONNECTED)
    {
      Serial.print("WiFi: No SSID");
      break;
    }
    else
    {
      Serial.print("WiFi: Connected");

      ssl_client.setInsecure();
      initializeApp(aClient, app, getAuth(sa_auth), aResult_no_callback);

      app.getApp<RealtimeDatabase>(Database);
      Database.url(DATABASE_URL);
    }
  }
}

void loop()
{
  JWT.loop(app.getAuth());

  app.loop();
  Database.loop();

  delay(100);
}

void timeStatusCB(uint32_t &ts)
{
#if defined(ESP8266) || defined(ESP32) || defined(CORE_ARDUINO_PICO)
  if (time(nullptr) < FIREBASE_DEFAULT_TS)
  {

    configTime(3 * 3600, 0, "pool.ntp.org");
    while (time(nullptr) < FIREBASE_DEFAULT_TS)
    {
      delay(100);
    }
  }
  ts = time(nullptr);
#elif __has_include(<WiFiNINA.h>) || __has_include(<WiFi101.h>)
  ts = WiFi.getTime();
#endif
}

void asyncCB(AsyncResult &aResult)
{
  printResult(aResult);
}

void printResult(AsyncResult &aResult)
{
  if (aResult.isEvent())
  {
    Firebase.printf("Event task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.appEvent().message().c_str(), aResult.appEvent().code());
  }

  if (aResult.isDebug())
  {
    Firebase.printf("Debug task: %s, msg: %s\n", aResult.uid().c_str(), aResult.debug().c_str());
  }

  if (aResult.isError())
  {
    Firebase.printf("Error task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.error().message().c_str(), aResult.error().code());
  }

  if (aResult.available())
  {
    Firebase.printf("task: %s, payload: %s\n", aResult.uid().c_str(), aResult.c_str());
  }
}

platformio.ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
board_build.filesystem = littlefs
lib_deps = 
    bodmer/TFT_eSPI@^2.5.34
    mobizt/FirebaseClient@^1.2.7

Expected behavior The code can be upload to ESP32

Screenshots image image image image image

IDE and its version:

mobizt commented 3 months ago

That is the issue from TFT_eSPI.h instead.

That library does some conflicts with filesystem which is generally available from core library.

See this basic example without Firebase library that still cannot compile.

#include <Arduino.h>
#include <TFT_eSPI.h>
#include <FS.h>

void setup()
{
    File fs;
}

void loop()
{
}

You still can use TFT_eSPI.h with FirebaseClient by include the TFT_eSPI.h after FirebaseClient.h.

#include <Arduino.h>
#include <FirebaseClient.h>
#include <TFT_eSPI.h>

FYI. Please use the discussion first instead of opening the issue.

mobizt commented 3 months ago

There are many issues in TFT_eSPI library related to FS.h.

The issue also occurs in the latest version of TFT_eSPI library which maintainer does not properly fix it as he doesn't test it with bare minimum setup.