Problem upload an file from sdcard to webserver #7972
MRcode2102
started this conversation in
General
Replies: 1 comment 1 reply
-
it has nothing to do with esp8266 Arduino boards support package |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi my friends
I recorded a wave file with Arduino mega 2560 (microphone is connected to Arduino mega 2560) and now I want to upload the recorded wave file is stored in my sd card to a web server with ESP12-F module which connected to Arduino mega 2560 with serial (UART) port, So I can't remove Arduino mega 2560 because I used of it for recording voices;
Now my problem is in uploading recorded wave file from my sd card (which connected to Arduino mega 2560) to a web server.
The problem is when I sending a file with a less size of 32 kb to the webserver, it's working fine and the file has been uploaded but when the size of my file is bigger than 32 kb, I can't send this file.
I think the problem is from the size of the Serial buffer and I don't know my problem for buffer size or another problem!
additional explanation : ( I used WampServer app as webserver and this library (WifiEspAT.h) for communication with ESP12-F module )
this is Link's from WIFIESPAT.h library (https://github.com/jandrassy/WiFiEspAT) and this is my sketch code
`#include <WiFiEspAT.h>
#include <SD.h>
#include <SPI.h>
//#include <StreamLib.h>
File myFile;
String post_host = "192.168.1.103";
const int post_port = 80;
String url = "/upload_file.php";
char server[] = "192.168.1.103";
// Emulate Serial1 on pins 6/7 if not present
#if defined(ARDUINO_ARCH_AVR) && !defined(HAVE_HWSERIAL1)
//#include <SoftwareSerial.h>
//SoftwareSerial Serial1(6, 7); // RX, TX
#define AT_BAUD_RATE 9600
#else
#define AT_BAUD_RATE 115200
#endif
//const char* server = "arduino.cc";
WiFiClient client;
//format bytes
String formatBytes(unsigned int bytes) {
if (bytes < 1024) {
return String(bytes) + "B";
} else if (bytes < (1024 * 1024)) {
return String(bytes / 1024.0) + "KB";
} else if (bytes < (1024 * 1024 * 1024)) {
return String(bytes / 1024.0 / 1024.0) + "MB";
}
}
void setup() {
Serial.begin(115200);
while (!Serial);
Serial1.begin(AT_BAUD_RATE);
WiFi.init(Serial1);
if (WiFi.status() == WL_NO_MODULE) {
Serial.println();
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
// waiting for connection to Wifi network set with the SetupWiFiConnection sketch
Serial.println("Waiting for connection to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print('.');
}
Serial.println();
Serial.println("Connected to WiFi network.");
//test connect to sd
Serial.print("Initializing SD card...");
if (!SD.begin(53))
{
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
//read file from SD
//define file
myFile = SD.open("data.wav", FILE_READ);
String fileName = myFile.name();
String fileSize = formatBytes(myFile.size());
Serial.println();
Serial.println("file exists");
if (myFile)
{
Serial.println("test file:ok");
// print content length and host
Serial.print("contentLength : ");
Serial.println(fileSize);
Serial.print("connecting to ");
Serial.println(post_host);
}
else
{
// if the file didn't open, print an error:
Serial.println("error opening test.WAV");
Serial.println("Post Failure");
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("request sent");
String responseHeaders = "";
while (client.connected() ) {
// Serial.println("while client connected");
String line = client.readStringUntil('\n');
Serial.println(line);
responseHeaders += line;
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
//close file
myFile.close();
}
//}
void loop()
{}
and this is my php code :
<?PHP}
?>`
and this is Serial monitor response for wave file bigger and less than 32kb ( screenshot's PNG is attached )
(( and also I tested this code with ESP8266 NODE MCU and I can send a bigger file of about 1MB to the same webserver (WampServer) ))
If possible help me
thanks....
Beta Was this translation helpful? Give feedback.
All reactions