Thanks in advance for your attention
I am in a proyect where I read data stored in a microSD.
The data is saved in a document line by line separating values with commas up to 6 different sensors value data.
Each line is printed in the microSD with a sample rate of 100Hz.
After saving all this information in the microSD, I read it line by line and send each line by wifi to a sever in a Raspberry Pi.
However for 1 minute of recording I have 2 minutes aproximately to send all this data.
I already tried to store 10 lines of this data in a buffer and send this buffer every 10 lines however I have only reduced the transfer time in just 1 minute.
Can I improve my data transfer speed by WIFI? How?
Here is my code:
void readSD(){
//------------------------------------------------------------------------------
// OPEN SD FILE AND REED VALUES TO SEND BY WIFI
//------------------------------------------------------------------------------
file = SD.open("File.txt",FILE_READ);
if (file) {
while (file.available()) {
char charc = file.read();
if(charc=='\r'){
while (file.read() != '\n'); // Descartar el resto hasta llegar a la siguiente línea
cont=cont+1;;
if (cont==10){
sendDataWIFI();
data = "";
cont=0;
}
} else {
data = data + charc;
}
}
sendDataWIFI();
data = "";
// close the file:
archivo.close();
} else {
// if the file didn't open, print an error:
if (mySerial == true){
Serial.println("Error trying to open File.txt");
}
}
void sendDataWIFI(){
if (client.connect(server, 80)>0) { // Connect with server
client.print("GET /recieverdata.php?data=");
client.print(data);
client.println(" HTTP/1.0");
client.println("User-Agent: Arduino 1.0");
client.println();
if (mySerial == true){
Serial.println("Conectado");
}
} else {
if (mySerial == true){
Serial.println("Fail in the connection");
}
}
if (!client.connected()) {
if (mySerial == true){
Serial.println("Disconnected!");
}
}
client.stop();
client.flush();
}
void setupWIFI() {
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
if (mySerial == true){
Serial.println("Communication with WiFi module failed!");
}
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
if (mySerial == true){
Serial.println("Please upgrade the firmware");
}
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
if (mySerial == true){
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
}
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
if (mySerial == true){
Serial.println("Connected to wifi");
}
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
if (mySerial == true){
Serial.println("connected to server");
}
}
}
Also in the server I store all this data in another .txt file with this code:
<?php
$data1 = $_GET['data'];
$direc='File.txt';
$file1 = fopen($direc, 'a') or die("Error trying to open the file");
fwrite($file1, $data1 . PHP_EOL);
fclose($file1);
?>