[SOLVED] Yun: Problems downloading to sd using shell curl

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.

// 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 :slight_smile:

edit: I saw this thread, but it doesn't seem to be related to my issue: [SOLVED] Arduino Yun: uploading www folder to SD card doesnt work - Arduino Yún - Arduino Forum

-Vince

Vincefarq:

    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

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

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

Please can you change the topic to [SOLVED] ?

So the (mytextfile) file is showing up, but it's empty :cold_sweat:

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

    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

    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

Footnote:

This eventually worked after days of debugging:

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