Can i save this firebase config on sd card and then on booting process esp8266 read config from sdcard?

can i save this firebase config on sd card and then on booting process esp8266 read config from sdcard?
#define USER_EMAIL "user@email.com"
#define USER_PASSWORD "mypassword123"
#define STORAGE_BUCKET_ID "mybucket.appspot.com"
#define DATABASE_URL "default-rtdb.firebaseio.com/"

so the goal is when we change the firebase configuration at any time, there is no need to do hard programming, just change the configuration stored in the SD card file.

Not as such no.

You can store those strings and restore them into variables and use those variables in your code but #define is a pre compiler directive and is not something you can do at run time.

i try to store my api key on APIKEY.txt file, it can be readed but need to convert to the right format, iam stuck till there

 dataFile = SD.open("APIKEY.txt");
  if (dataFile) {
    Serial.println("READ API KEY");
    while (dataFile.available()) {
      
    #define API_KEY dataFile.read()
    config.api_key = API_KEY;
    auth.user.email = USER_EMAIL;
    auth.user.password = USER_PASSWORD;
    config.token_status_callback = tokenStatusCallback;
    config.database_url = DATABASE_URL;
    Firebase.begin(&config, &auth);
    Firebase.reconnectWiFi(true);
  }
       dataFile.close();
  } 
  else {
    Serial.println("error opening API KEY");
  }

can i change the #define to another structure? do you have any suggestions?

No that will not work because the compiler can not know what is in the file at compile time.
The pre compiler substitutes your #define before it compiles the source into code.

Yes I already said.

thanks mike i will try it

there is a library - Wi-Fi-Multi library -
it selects the strongest Wifi signal.

Not sure if it allows you to take your device, move to a new WiFi, get the SSID, then input your password and save that.

The idea is that it allows you to have move from the bench in your home wifi to your work, garden, or whatever.

more about it , halfway down the page

https://tttapa.github.io/ESP8266/Chap07%20-%20Wi-Fi%20Connections.html

if the link does not work, search for a beginners guide to the esp8266

it may not be compatible with firebase, but the details of how it works is open source.

You can store those strings and restore them into variables and use those variables in your code but #define is a pre compiler directive and is not something you can do at run time.

I try to do your suggestion. so far that i can do to make a program like this.

dataFile = SD.open("APIKEY.txt");
  if (dataFile) {
    Serial.println("READ API KEY");
    while (dataFile.available()) {
    const char* API_KEY;
    API_KEY = dataFile.readString().c_str();
    config.api_key = API_KEY;
    auth.user.email = USER_EMAIL;
    auth.user.password = USER_PASSWORD;
    config.token_status_callback = tokenStatusCallback;
    config.database_url = DATABASE_URL;
    Firebase.begin(&config, &auth);
    Firebase.reconnectWiFi(true);
  }
       dataFile.close();
  } 
  else {
    Serial.println("error opening API KEY");
  }

I tried to save the token in a txt file called APIKEY.txt but the result is not what I expected

APIKEY.txt contains :
AIzaSyDQi_EzowRNsOer04QA0EsICSTditJUyzU

So what did you expect and what happened?

Doesn’t look like you actually saved text in that file. How was it written?

That won’t work anyway because it needs to know where in the memory the callback function is and it is not known until after compile time, and it will change with every new code.

RELATED QUESTION:
ESP32 has bluetooth and wifi.
Can one add the SSID and password to a running sketch?

Follow up :slight_smile:
Use it dynamically AND append a file to add an additional set?

This might help the OP.

token has a bad request, can't connect to firebase

it written manually, i created txt file in my desktop

i don't understand what do you mean, can you give me example if it possible? i copy that code from firebase_ESP_Client library

thanks, i will follow it

finally i got the answer from this : Arduino converting value from file.read() to const char* - Stack Overflow

on the global defined API_KEY

char API_KEY [40] = {'\0'}; 
void setup
 dataFile = SD.open("/APIKEY.txt");
  if (!dataFile){
    Serial.println("FAILED READ API KEY");
        return;
  }
    uint16_t i = 0;
    while (dataFile.available()) {
    API_KEY [i] = dataFile.read();
    Serial.print (API_KEY[i]); // for debug
    i++;
    }
    API_KEY [i] = '\0';
    Serial.print (API_KEY);
    dataFile.close();```