hey, everyone, I wrote a code that can send a file
if i send text file it will work perfectly, but when i try to send voice it only send part of the
data and then it stop sending i tried to send .wav .mp3 .m4p
the code
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <SD.h>
const int push1 = 2;
File myFile;
char a[350];
int c= 0;
int counter = 0 ;
// network parameters
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x05, 0x02 }; // ethernet interface MAC address
IPAddress localIp(10,131,41,72); // local ip address
IPAddress destIp(10,131,41,74); // destination ip address
unsigned int port = 9631; // destination port
// EthernetUDP to send and receive messages.
EthernetUDP Udp;
// setup the arduino and shields
void setup() {
pinMode(push1, INPUT);
//Initialize serial and wait for port to open:
Serial.begin(9600); // 19200
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// start ethernet and udp
Ethernet.begin(mac, localIp); // static ip version
// open UDP port
Udp.begin(port);
// show the local ip address (useful for dhcp)
Serial.print("Local IP: ");
Serial.println(Ethernet.localIP());
}
// do tasks
void loop() {
if(digitalRead(push1) == LOW){
delay(1000);
myFile = SD.open("sv12.wav");
if (myFile) {
Serial.println("inside the file there's");
// read from the file until there's nothing else in it:
while (myFile.available()) {
a[c] = myFile.read();
c++;
if ( c==350 ){ // when array is full send the UDP message
Serial.println("i will send now");
Udp.beginPacket(destIp, port);
Udp.write(a);
delay(250);
Udp.endPacket();
Serial.println("Sending UDP message");
counter++; // to know how many packet is sent so far
Serial.print("Sending packet#");
Serial.println(counter);
for (int x = 0 ; x<c ; x++){
a[x] = '\0';}
c=0;
Serial.println("clearing");}
}
if ( c<350 ){ // to send last packet
Serial.println("i will send now");
Udp.beginPacket(destIp, port);
Udp.write(a);
Udp.endPacket();
Serial.println("Sending UDP message Last segment");
counter++;
for (int x = 0 ; x<c ; x++){
a[x] = '\0';}
c=0;}
// close the file:
myFile.close();
Serial.println(counter);
Serial.println("END");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
}
can someone help please.