I am trying now for days to store a config file from a web page to the sd card.
The REST command i use is "/arduino/saveconfig/data"
Where data is a json string.
On the arduino site i collect the data with the code where myfile is on the sd card
myfile FileSystem.open("/mnt/sd/arduino/www/project/myfile.cfg", FILE_WRITE);
This is very nice. Will keep it for future use. But it is not usable for my project.
I am configuring an online led schedule and want to save this on the arduino sd card. The schedule will be less then 1 kbyte.
Today i had one sollution which took about 15 sec for 0.41 kbyte. The 15 seconds is long because i had to chunk the data before sending in 300 bytes part.
Data is my JSON data created on the fly.
Data2=JSON.stringify(Data);
Data2=Data2.match(/.{1,300}/g);
error=false;
for (index = 0; index < Data2.length; ++index){
cnt=0;
do{
$.ajax({
async: false,
url:"/arduino/saveschedule/"+index.toString()+"/"+encodeURIComponent(Data2[index]),
type:'GET',
success: function(data) {
if (data='OK'){error=false;} else {error=true;}
},
error: function(data) {error=true;}
});
++cnt;
} while ((error) && (cnt<5));
}
if (error) alert('Error saving schedular'); else {alert('Schedule saved successfuly');}
}
ARDUINO CODE:
if (command == "saveschedule") {
String command = client.readStringUntil('/');
command.trim();
int mode;
FileSystem.begin();
if (command=="0")
{mode=FILE_WRITE;}
else { mode=FILE_APPEND;}
File schedule = FileSystem.open("/mnt/sd/arduino/www/oac/oac.cfg", mode);
if (schedule)
{
char c;
while(client.available()>0) {
c=client.read();
schedule.print(c);
}
client.println("OK");
schedule.close(); // close the file
}
else client.println("ERROR");
}
Suprisingly this works.
But i really hope that there is a better way.
I also have a problem reading the file again. Same problem timeout while reading the file from the SD.
Hi,
I have a similar problem, I try to resolve in this way.... but arduino doesn't write anything...
(via ssh on terminal the logger.sh seems to be correct: it writes to file)
Function
String writeLog() {
String result = " LOG_TEST";
Process pLog;
pLog.begin("/mnt/sda1/arduino/www/logger.sh");
pLog.addParameter(result);
pLog.runAsynchronously();
}
keebOo:
Hi,
I have a similar problem, I try to resolve in this way.... but arduino doesn't write anything...
(via ssh on terminal the logger.sh seems to be correct: it writes to file)
...
Is there any suggestion for my original problem .
I can write to the sd card but after about few 100 bytes there is a timeout. I send the data in the REST GET request which one is own is not very nice approach. But i do not know any other way.
I though it would be very easy to send 1 kbytes of configuration data to the yun with HTTP request and read back again.
I also tried to increase the timeout of ajax request but this also did not help.
I suspect that the yun drops the connection after few milliseconds. Can this be the case???