delete file from SD and call HTTP

Hello. I have a problem with my arduino yun. I can use the wifi , read and write from the sd without problems but if I cancel a file from the SD after I cant communicate with the internet.

Here is a sketch for test

#include <SPI.h>
#include <Wire.h>
#include <Bridge.h>
#include <HttpClient.h>
#include <FileIO.h>


HttpClient client;
Process mioProcessoLinux;

void setup() {
    Bridge.begin();
  Serial.begin(19200);
  while(!Serial);
    Serial.println("seriale avviata");
   
  if (!FileSystem.begin() ) {    
    Serial.println("Cant use SD!");
  }
  else
    Serial.println("Ok it works");
    
  File mioFile = FileSystem.open("/mnt/sd/valori.txt", FILE_APPEND);
       if (mioFile) {

          mioFile.println("I hope it would work");
          mioFile.close();
          }
}



void loop() {
  // put your main code here, to run repeatedly:
      mioProcessoLinux.begin("curl");
      mioProcessoLinux.addParameter("-i");    //stampo l'header
     
      mioProcessoLinux.addParameter("http://arduino.cc/asciilogo.txt");
      mioProcessoLinux.run();
      while (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
      Serial.flush();
         
      Serial.print("linux ");
      Serial.println(mioProcessoLinux.exitValue());

      FileSystem.remove("/mnt/sd/valori.txt");      //After this HTTP does not work!!!

      mioProcessoLinux.begin("curl");
      mioProcessoLinux.addParameter("-i");    //stampo l'header
     
      mioProcessoLinux.addParameter("http://arduino.cc/asciilogo.txt");
      mioProcessoLinux.run();
      while (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
      Serial.flush();
         
      Serial.print("linux ");
      Serial.println(mioProcessoLinux.exitValue());

      delay(1000);
}

Do anyone have the same problem?
Any idea about how to solve this strange behaviour?

Thanks in advance for any help!

I can't help with your issue but I see an error in your code. You wrote

FileSystem.remove("valori.txt");

while it must be

FileSystem.remove("/mnt/sd/valori.txt");

You are right. In my real sketch it was ok, in this example I forgot "/mnt/sd/". Thanks!
Anyway the problem is not this one so any other suggestion would be really appreciated.
Thanks in advance

Not a solution to your problem as it stands but have you used Process to get the Linux side to delete the file.

mioProcessoLinux.begin("rm");
mioProcessoLinux.addParameter("-f");
mioProcessoLinux.addParameter("/mnt/sd/valori.txt");
mioProcessoLinux.run();

Would identify whether the file can actually be deleted.

#include <FileIO.h>
void setup() {
  Bridge.begin();
  Serial.begin(19200);
  while (!Serial);
  Serial.println("seriale avviata");
  if (!FileSystem.begin() ) {
    Serial.println("Cant use SD!");
  }
  else
    Serial.println("Ok it works");
  File mioFile = FileSystem.open("/mnt/sda1/valori.txt", FILE_APPEND);
  if (mioFile) {
    mioFile.println("I hope it would work");
    mioFile.close();
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  Process mioProcessoLinux;
  mioProcessoLinux.begin("curl");
  mioProcessoLinux.addParameter("-i");    //stampo l'header
  mioProcessoLinux.addParameter("http://arduino.cc/asciilogo.txt");
  mioProcessoLinux.run();
  while (mioProcessoLinux.available()) {
    char c = mioProcessoLinux.read();
    Serial.print(c);
  }
  Serial.flush();
  Serial.print("linux ");
  Serial.println(mioProcessoLinux.exitValue());
  FileSystem.remove("/mnt/sda1/valori.txt");      
  mioProcessoLinux.begin("curl");
  mioProcessoLinux.addParameter("-i");    //stampo l'header
  mioProcessoLinux.addParameter("http://arduino.cc/asciilogo.txt");
  mioProcessoLinux.run();
  while (mioProcessoLinux.available()) {
    char c = mioProcessoLinux.read();
    Serial.print(c);
  }
  Serial.flush();
  Serial.print("linux2 ");
  Serial.println(mioProcessoLinux.exitValue());
  delay(10000);
}

thanks sonnyyu and wildpalms. Using sonnyyu solution I have understood that the problem was in calling client.available and client read instead of mioProcessoLinux.available() mioProcessoLinux.read(). Strange...

sonnyyu why did you declared "Process mioProcessoLinux" in every loop and not only as global variable used by setup and loop?
thanks

cantore:
sonnyyu why did you declared "Process mioProcessoLinux" in every loop and not only as global variable used by setup and loop?
thanks

  1. Variable Scope: mioProcessoLinux declared as local variables, local variables are a useful way to insure that only one function has access to its own variables. This prevents programming errors when one function inadvertently modifies variables used by another function.

  2. delay(10000); : The time to declare mioProcessoLinux compare "10000" is next to nothing.