Go Down

Topic: [SOLVED] Yun: Problems downloading to sd using shell curl (Read 2577 times) previous topic - next topic

Vincefarq

Jul 02, 2014, 04:17 am Last Edit: Jul 04, 2014, 11:06 am by Vincefarq Reason: 1
Hi, folks. Does anyone know why I can't successfully download a text file to my Yun? While debugging, it seems the cd command is working fine (I can ls the directory) but the downloaded file never shows up on the SD.

I based my code on the web camera from Neuroballs: http://neuroballs.com/2014/01/how-to-build-a-arduino-yun-powered-cat-camera/ (only downloading instead of uploading)

I've tried every variation of curl in the manual. I've even tried wget.  I can run that curl command from the shell prompt. I even tried runShellCommandAsynchronously. After three days, and a ton of searching, I'm stumped. Any help would be appreciated.

Code: [Select]

// download remote file card to SD
#include <Process.h>
void setup() {
 // Initialize the Bridge and the Serial
    Serial.begin(9600);//
    while(!Serial);  // wait for Serial port to connect.//
    Serial.println("Save text file\n");//
    Bridge.begin();
}
void loop(){
   Serial.print("reading file...");
   Process p;
   p.runShellCommand("cd /mnt/sda1/");
   p.runShellCommand("curl -O http://api.mywebserver.com/1/textfile.txt");
   Serial.println("Done. Do other things now.");
   delay(30000);
}


..and yes, I did upgrade my Yun  :)

edit: I saw this thread, but it doesn't seem to be related to my issue: http://forum.arduino.cc/index.php?topic=218640.0

-Vince

federicofissore


Code: [Select]

   p.runShellCommand("cd /mnt/sda1/");
   p.runShellCommand("curl -O http://api.mywebserver.com/1/textfile.txt");



It does not work like this.  Once you've CDed into a folder, next command will NOT start from that folder: every single command runs independently of the results of the previous ones.
Use
Code: [Select]

   p.runShellCommand("curl -O http://api.mywebserver.com/1/textfile.txt > /mnt/sda1/textfile.txt");


Vincefarq

Ah! That is great to know. I assumed the commands were being run in sequence as if I were issuing them from the shell.

Thank you! The file is showing up now!

-Vince

federicofissore

Please can you change the topic to [SOLVED] ?

Vincefarq

#4
Jul 03, 2014, 01:59 pm Last Edit: Jul 04, 2014, 11:06 am by Vincefarq Reason: 1
So the (mytextfile) file is showing up, but it's empty  :smiley-roll-sweat:

Any ideas why? everything works fine from the command line.

Code: [Select]

   Serial.print("reading file...");
   Process p;
   //p.runShellCommand("cd /mnt/sda1/");
   p.runShellCommand("curl 'http://api.mysite.com/1/index.php?cliid=07b9&imgwd=8&imght=8&numimg=8&verbose=no&formSubmit=Submit' > /mnt/sda1/temp.html");
   p.runShellCommand("curl -O 'http://api.mysite.com/1/mytextfile.txt' > /mnt/sda1/mytextfile.txt");
   Serial.println("Done. Do other things now.");


-Vince

federicofissore

Code: [Select]

    p.runShellCommand("curl -O 'http://api.mysite.com/1/mytextfile.txt' > /mnt/sda1/mytextfile.txt");


Google for "curl man": I think -O is interfering with output redirection

Vincefarq

Footnote:

This eventually worked after days of debugging:

Code: [Select]

p.runShellCommand("curl 'http://api.mywebserver.com/phpfile.php?name1=value1&name2=value2&name3=value3' > /mnt/sda1/textfile.txt");


It seems there were two things wrong:

  • firstly, -O never worked for me outside of the command line, and I've run out of curiosity to find out why.

  • secondly, I was also running a bunch of libraries (and had a few arrays) which chewed away at my memory and caused some unpredictable behavior (like my Yun resetting intermittently)


Just leaving a note for future sufferers. Good luck!

-Vince

Go Up