![]() Probably it should be wtitten in a different way.Īctually I still test it on ESP32, but the code already adapted to ESP8266. If you see B4A code, I set the first timer interval to 100 ms, send info string, then decrease the timer interval to send file chunks. Maybe it is best send chunks in a Do While loop awaiting ESP that read a chunk before send another one ? I've used a timer to send file chunks, probably this is not good, I noticed that when Android send a chunk of bytes, then wait ESP to download it, if ESP do not read bytes from the stream, Android just wait until ESP read it, so probably using a Timer is not a good option here ? Note that I cannot convert ESP side to B4R because it is a big project I started in 2018, so I cannot use socket stream in prefix mode. In my app I cannot do this, just I open the socket and mantain it always open, there is a button to connect/disconnect. ![]() Note that here in the B4A code I open the socket connection before send all data, then send all data, finally I close it. Note that here there is a sort of data encryption (just for string commands) that I just disabled on this test. I've attached a working B4A (client) and C++ (server) code, errors only happen on my real app where I have other stuffs in the ESP loop() function. When this happen sometime Android app completely stall, no errors, completely hang, the only way is to use Android menu to close it.īecause I need to make it always working I've decided to reproduce it in a small project and post it so maybe someone can help to improve this piece of code. Sometime Android (TCP CLIENT) send info string and ESP (TCP SERVER) do not receive it or receive but then do not receive file chunks, This worked well for a long time in my app, now I've changed something and sometime the transfer fails, after this B4A start read byte chunks (buffer) from file and send to ESP that collect it and append chunk by chunk to a file on micro sdcard. The info string is a splited delimiter string and ESP split it to extract all infos If there is a space to save a file on ESP SD Card, then B4A send the info string containing the file name, size and other stuff (variables) not used here. ESP check for a space in the SD Card, if there is space to save a file send a string SPACEOK and B4A will continue the upload, if there is no space it send a string NOSPACE and B4A stop the upload B4A code send a request to ESP with a file size ![]() and other variables I've put here just as an example, you can put yours. This is a code snippet but even an help request to improve it, so I post here before move on code snippets section.įor my 3D printing app host I had necessity to transfer files from Android to ESP8266-ESP32 micro sd card (over network).īecause I don't wanted to use an FTP library on ESP side to just upload a file, I wrote a raw code that read a file in chunks and thenīecause I even want to pass some infos from Android to ESP before send a file I send an info string that contain some variables I want to pass, ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |