Hello. I ask for help.
I'm using the sendFile example from this library:
https://github.com/GyverLibs/FastBot/tree/main
But instead of having the BOT_TOKEN value as a #define, I intend to read the BOT_TOKEN from a .txt file inside LittleFS.
For this I declared a global String bottokenstring;
I comment out // the #define BOT_TOKEN and create an empty global String BOT_TOKEN.
And read using:
file = LittleFS.open("/CONFIG.txt", "r");
if (file) {
while (file.available()) {
bottokenstring = myFile.readStringUntil('\n');
}
file.close();
}
Then I do it inside the setup(), BOT_TOKEN = bottokenstring;
Mute FastBot bot(BOT_TOKEN); instead of placing it inside the Setup(); after getting the String BOT_TOKEN.
Does not work.
But if I enter the value of BOT_TOKEN inside Setup(); Just type, manually, BOT_TOKEN = "2654326546:asjhAsfAsfkllgUsaOuiz_axfkj_AsfkjhB";
There it works.
Wonder what's going on? I read the String bottokenstring in the serial monitor and it is identical. But something prevents it from being recognized as a String.
Esp32cam: I read String from SPIFFS but it is not accepted. Why ?
-
- Posts: 16
- Joined: Wed Apr 12, 2023 11:14 am
-
- Posts: 23
- Joined: Wed May 31, 2023 6:54 pm
Re: Esp32cam: I read String from SPIFFS but it is not accepted. Why ?
Hello esp@esp@esp,
Could you check and compare, whether the String variable retrieved from file has same length as the one with static assignment ?
One thing that comes to my mind is that the file CONFIG.txt has been created on windows environment and before \n character it also contains \r character. When reading the file, the \r will be part of String data, but when printing it using serial.println(), there won't be visible difference on serial monitor.
Could you check and compare, whether the String variable retrieved from file has same length as the one with static assignment ?
Code: Select all
unsigned int bts_len = bottokenstring.length();
serial.println(bts_len);
-
- Posts: 23
- Joined: Wed May 31, 2023 6:54 pm
Re: Esp32cam: I read String from SPIFFS but it is not accepted. Why ?
Hello esp@esp@esp,
Could you please compare length of String retrieved from config file with length of statically initialised String ?
i.e.
Last character of the string retrieved from config file might be the '\r' character and visual check using serial.println(bottokenstring) would not reveal this.
Could you please compare length of String retrieved from config file with length of statically initialised String ?
i.e.
Code: Select all
unsigned int bts_len = bottokenstring.length();
serial.println(bts_len);
-
- Posts: 16
- Joined: Wed Apr 12, 2023 11:14 am
Re: Esp32cam: I read String from SPIFFS but it is not accepted. Why ?
Thanks for the answer. I take the opportunity to ask something else: When I do OTA I see progress evolve in the serial monitor according to the code below:
// Callback - Progress
Update.onProgress([](size_t progresso, size_t total) {
Serial.print(progresso * 100 / total);
});
But the 100% is relative to the maximum size of the selected partition (in my case ESP DEV MODULE). This way when the count % is at 52% (relative size of my code) it's already finished. To be more correct, I would like 100% to be relative to the maximum size of my code, so the count would end at 100%. It's not important but I'd like to know if it's possible and how the code would look. Grateful.
// Callback - Progress
Update.onProgress([](size_t progresso, size_t total) {
Serial.print(progresso * 100 / total);
});
But the 100% is relative to the maximum size of the selected partition (in my case ESP DEV MODULE). This way when the count % is at 52% (relative size of my code) it's already finished. To be more correct, I would like 100% to be relative to the maximum size of my code, so the count would end at 100%. It's not important but I'd like to know if it's possible and how the code would look. Grateful.
-
- Posts: 23
- Joined: Wed May 31, 2023 6:54 pm
Re: Esp32cam: I read String from SPIFFS but it is not accepted. Why ?
Hi,
The total parameter of onProgress() comes from Arduino framework. It looks like it is populated by the flash size rather than value dynamically created during the build process. I think you would have turn to the Arduino forum to figure out whether there is chance to change the value reported to the onProgress callback as "total".
Regards
The total parameter of onProgress() comes from Arduino framework. It looks like it is populated by the flash size rather than value dynamically created during the build process. I think you would have turn to the Arduino forum to figure out whether there is chance to change the value reported to the onProgress callback as "total".
Regards
Who is online
Users browsing this forum: Bing [Bot] and 80 guests