How to convert this function to int, is function String?

in this situation i want to get some value from firebase RTDB, and i tried to coverting that value to int, how to do that?
and this is my last code :

 int setTemp = (Firebase.RTDB.getInt(&fbdo, "/setValue/tMax") ? String(fbdo.intData()).c_str() : fbdo.errorReason().c_str());
 int setHumi = (Firebase.RTDB.getInt(&fbdo, "/setValue/hMin") ? String(fbdo.intData()).c_str() : fbdo.errorReason().c_str());
  
  if (t >= setTemp)
  {
    lcd.setCursor(10, 0);
    lcd.print(">");
    }
  else
  {
    lcd.setCursor(10, 0);
    lcd.print(" ");
    }

Read the forum guidelines.

Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.

Post your code in code tags.

ok pardon me, it was editted, Thanks

From the name of the function I would try

int setTemp = Firebase.RTDB.getInt(&fbdo, "/setValue/tMax");

From the name of the function I would try

int setTemp = Firebase.RTDB.getInt(&fbdo, "/setValue/tMax");

thanks for replying, now i know from library firebase client the fbdo.intData() it's already int, so i just put the code like this:

Firebase.RTDB.getInt(&fbdo, "/setValue/tMax") ? String(fbdo.intData()).c_str() : fbdo.errorReason().c_str(); int setTemp = fbdo.intData()

If you had included a link to the library you are using, I could have checked it myself.

I know from education and experience that assigning a char* to an int is rarely reasonable.

this the link of library that i use

I know from education and experience that assigning a char* to an int is rarely reasonable.

please tell me if i was wrong, thanks

Firebase.RTDB.getInt(&fbdo, "/setValue/tMax", &setTemp);

should do the trick.

With bool getInt(FirebaseData *fbdo, const char *path, int *target);

I'm not quite sure which of the functions you are really using, there are some variants,
but all include an overloaded function that specifies the target.

src/FirebaseESP32.cpp:bool FirebaseESP32::getInt(FirebaseData &fbdo, const String &path)
src/FirebaseESP32.cpp:bool FirebaseESP32::getInt(FirebaseData &fbdo, const String &path, int &target)
src/FirebaseESP32.h:  bool getInt(FirebaseData &fbdo, const String &path);
src/FirebaseESP32.h:  bool getInt(FirebaseData &fbdo, const String &path, int &target);
src/rtdb/FB_RTDB.cpp:bool FB_RTDB::getInt(FirebaseData *fbdo, const char *path)
src/rtdb/FB_RTDB.cpp:bool FB_RTDB::getInt(FirebaseData *fbdo, const char *path, int *target)
src/rtdb/FB_RTDB.h:  bool getInt(FirebaseData *fbdo, const char *path);
src/rtdb/FB_RTDB.h:  bool getInt(FirebaseData *fbdo, const char *path, int *target);

i'm sure i using this function.

So using bool getInt(FirebaseData *fbdo, const char *path, int *target); should work.

Firebase.RTDB.getInt(&fbdo, "/setValue/tMax", &setTemp);

yups thats works! thanks

Glad it works.

I learned some things about a new library. :wink:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.