i'm working on this project that is an arduino nano 3.0 board with micro sd module and esp8266 esp01 wifi module in the microsd i have wav file and the purpose of the wifi module is to upload the wav file from the sd card to my web server using HTTP or any another protocl so, how can i make this project because i have faced a problem when trying to open the wav file from the sd card and send it to the wifi module via serial to upload it , it seems that the SD library can not open a wav file and read it so i can send it in chucks to the wifi module and upload it so the quesion is what should do to make this idea
here is the code i'm trying to work with
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
const int baudRate = 9600;
void setup() {
Serial.begin(baudRate);
while(!Serial);
if(!SD.begin(chipSelect)){
Serial.println("SD card failed");
return;
} else{
Serial.println("SD is Connected Sucessfully");
}
Serial.println("Ready!");
}
void loop(){
File file = SD.open("audio.wav");
if(file){
Serial.println("Uploading file...");
while(file.available()){
byte buffer[1024];
// or size_t bytesRead = file.read(buffer, sizeof(buffer));
file.read(buffer, 1024);
sendToESP(buffer);
}
file.close();
Serial.println("Upload complete!");
}
}
void sendToESP(byte buffer[]){
Serial.write(buffer, 1024);
}
and the esp01 module code
#include <ESP8266WiFi.h>
const char* ssid = "";
const char* password = "";
const char* host = ".........../wav/uploadwav";
const int port = 80;
const int baudRate = 9600;
String data;
WiFiClient client;
void setup() {
Serial.begin(baudRate);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Check for incoming data
if (Serial.available()) {
char c = Serial.read();
data += c;
// If we have received a full chunk of data (1024 bytes), send it to the server
if (data.length() >= 1024) {
sendDataToServer();
data = "";
}
}
}
void sendDataToServer() {
if (client.connect(host, port)) {
// Send the HTTP POST request
client.print("POST /upload.php HTTP/1.1\n");
client.print("Host: \n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(data.length());
client.print("\n");
client.print(data);
client.print("\n");
// Wait for the response from the server
while (client.connected()) {
if (client.available()) {
String line = client.readStringUntil('\n');
Serial.print(line);
}
}
client.stop();
} else {
Serial.println("Connection to server failed");
}
}