Hello, I'm currently trying to use Arduino OTA and I can't understand some behavior
Just for you to understand my project:
It is an Arduino Telegram Bot which can receive and send message. I added a feature that allow me to update the Arduino by sending a file on Telegram. The functions to send, receive et download the message work perfectly! Until... until I use OTA.
Let me explain:
- If I don't use the part of the code that allow me to update the Arduino, every goes well.
- If I call that function to update the code by OTA, then the Arduino starts behaving oddly (I'll explain)
Here is my code (only the part with the OTA update):
InternalStorage.debugPrint();
if (InternalStorage.maxSize() > File_size)
{
if (InternalStorage.open(File_size))
{
InternalStorage.debugPrint();
int b;
while (File_size > 0)
{
b = Fichier.read();
if (b != (-1))
{
InternalStorage.write(b);
}
else
{
InternalStorage.close();
break;
}
File_size--;
}
//InternalStorage.close();
if (File_size == 0)
{
//Envoi_Message_Telegram(Nouveau_Message_Telegram.ID_Conversation, "L'arduino va redémarrer avec le nouveau programme");
//delay(1000);
InternalStorage.close();
InternalStorage.debugPrint();
//InternalStorage.apply();
Serial.println("Test1");
return Retour_FCT;
}
}
else
{
Serial.println("Echec ouverture mémoire");
}
}
Don't worry for the fact that there is no return in certain conditions; there is one return after all this part.
So I want this code to work this way:
- Receiving the file (and so its size) ; it works!
- Looking if there is enough place. If not, then it's the end. If yes:
- Opening the memory and then writing the bytes in the good place to work
- If there was an error during reading the file, we break the procedure
- If not, then we should apply the changes.
Applying the changes seems to work so it's good. But before applying the changes I wanted to send a message on Telegram to say that it's going to reboot; but it doesn't work. I then tried to print some messages over Serial.println() and something seems broken.
The first InternalStorage.debugPrint(), which is BEFORE opening the storage works and the output is
19:07:47.287 -> SKETCH_START_ADDRESS 8192
19:07:47.287 -> PAGE_SIZE 64
19:07:47.287 -> MAX_FLASH 245760
19:07:47.287 -> MAX_PARTIONED_SKETCH_SIZE 118784
19:07:47.287 -> STORAGE_START_ADDRESS 126976
But the second one after opening the InternalStorage isn't as good:
19:07:51.113 -> SKETCH_START_ADDRESS 8192��PAGE_SIZE 64��MAX_FLASH 245760��MAX_PARTIONED_SKETCH_SIZE 118784��STORAGE_START_ADDRESS 126976��
The LF and CR don't work anymore... And it is the same with all my Serial.println() that come after it, even in other parts of the global sketch.
Moreover, after that the Arduino seems to continue to execute the code but it doesn't work, if I send a message on Telegram then nothing happens
Finally, even cliking on the reset button doesn't work. The arduino disconnects from the computer but never connect back. I have to click twice quickly on the reset button to be able to upload another sketch.
Has someone an idea on how to fix that? Is someting missing in my code?