I have question currently have this idea, but don't know if its the right one.
So what I want is to send binary file from one ESP to another via RS485.
What I think would be the best, download .bin from URL via client, save it to SPIFF and after save is done, start sending data from file to another ESP. Here I have first problem, currently I'm just playing with some .txt file, which I download from URL, but file is not saved completely at last bigger files are not. For example file which is about 200kb has been saved, bigger files are not saved at all. Already in start I get from client for example 3/4 data of complete file soo for example 1/4 is already missing.
Here is my code with which I start. Currently I'm just saving data to SD card, next will be SPIFF.
void getFile() {
WiFiClient client;
const char http_site[] = "xyz";
const int http_port = 80;
if (client.connect(http_site, 80)) { //starts client connection, checks for connection
Serial.println("connected");
Serial.println("##########################");
Serial.println("");
client.println("GET /test.txt HTTP/1.1"); //download text
client.println("Host: xyz");
client.println("Connection: close"); //close 1.1 persistent connection
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
String readString;
String readChar;
while (client.connected() && !client.available()) delay(1); //waits for data
File fileWrite;
fileWrite = SD.open("/test.txt", FILE_WRITE);
while (client.connected() || client.available()) { //connected or data available
char c = client.read();
readString += c;
readChar = c;
String content = readChar;
//fileWrite.println(content);
fileWrite.print(content);
}
fileWrite.close();
int index = readString.indexOf("Accept-Ranges: bytes");
readString.remove(0, index + 20);
readString.trim();
client.stop(); //stop client
Serial.println("##########################");
if (readString.length() > 0) {
Serial.println("Receive from client:");
Serial.println("Size: " + String(readString.length()));
// Serial.println(readString);
// I2CExpander.write(SC16IS752_CHANNEL_A, readString);
Serial.println(readString);
// fileWrite("/test.txt", readString);
// fileOpen("/test2.bin");
}
Serial.println("##########################");
readString = ""; //clear readString variable
}