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?
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
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...
cantore:
sonnyyu why did you declared "Process mioProcessoLinux" in every loop and not only as global variable used by setup and loop?
thanks
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.
delay(10000); : The time to declare mioProcessoLinux compare "10000" is next to nothing.