Yun, curl and process: error? [urgent]

I've got a big stupid problem and I need to solve [u]today[/u] for our project at MakerFaire Torino: we will expose tomorrow... so if anyone can help it will be appreciated and I will start with all of my love, than beer, presents, goods, and so on! ;) And if you will be in Turin, tomorrow, yes, I will give you really!!! XD XD

So, the problem: I need to send a file (anemoPark.csv) to a mySQL database on AlterVista, if I write the command in a shell inside Linino

  curl -F file=@anemoPark.csv http://xxxxxxxxxxx.altervista.org/samplesload/filetodb.php

it works like a charme

if I insert this in an Arduino sketch, like this

  p.runShellCommandAsynchronously("curl -F file=@anemoPark.csv http://xxxxxxxxxxx.altervista.org/samplesload/filetodb.php");

it doesn't work anymore, even if I use a test sketch without anything else than this command (and related declarations, obviously). I also tried runShellCommand instead of runShellCommandAsynchronously, same failure no result.

I'm going slightly mad! if it works inside Linino shell why doesn't it work inside an Arduino sketch? same command, same sintax!

Is a Process related problem?

please help me as soon as possibile!

EDIT some more information about curl -F here: http://curl.haxx.se/docs/manpage.html

use an absolute path to specify the location of anemoPark.csv. example: /mnt/sd/anemoPark.csv

thanks for the quick answer!

well, I tried it: no joy...

could it be related to the lenght/weight of the file? it is a simple csv file, with ten fields per record, and 12 records. something like 350 bytes...

Does it work on the shell when you specify the absolute path? Can you paste the command you're using?

put "anemoPark.csv" into "/usr/lib/python2.7/bridge" directory. and Testing;-

p.runShellCommandAsynchronously("curl -F file=@anemoPark.csv http://xxxxxxxxxxx.altervista.org/samplesload/filetodb.php");

[quote author=Federico Fissore link=topic=243665.msg1745062#msg1745062 date=1401447989] Does it work on the shell when you specify the absolute path? Can you paste the command you're using? [/quote]

yes! if I use relative path in shell it works:

root@supermarioyun:/mnt/sda1# curl -F file=@anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php

and the same happens with absolute path:

root@supermarioyun:/mnt/sda1# curl -F file=@/mnt/sda1/anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php

even with copying in /usr/lib/python2.7/bridge/anemoPark.csv

root@supermarioyun:/usr/lib/python2.7/bridge# curl -F file=@/usr/lib/python2.7/bridge/anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php

no answer, no errors, data copied in remote server.

EDIT quite obviously, if I remove the file from /mnt/sda1/ and I try in the shell:

root@supermarioyun:/mnt/sda1# curl -F file=@anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php
curl: (26) couldn't open file "anemoPark.csv"

it gives error, since it doesn't find the file and it doens't search for it in /usr/lib/python2.7/bridge

this a copy of the file I need to upload

anemoPark.csv (168 Bytes)

...and this is the whole procedure I use to update the server:

void serverUpdate () {
  Process p;
  cc = getTimeStamp(); //get a timestamp UNIX format to save in log file for debug
  p.runShellCommandAsynchronously("curl -F file=@anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php");    
  p.runShellCommandAsynchronously("rm -f /mnt/sda1/anemoPark.csv ");
  while (p.available() > 0) {
    Serial.println(p.readString());
  }
  while (p.available()) {
    c = p.read();
    cc = cc + c;
  }
  cc += " uploaded on " + getTimeStamp(); 
  cc.trim(); // IMPORTANT !!!
  File logFile = FileSystem.open("/mnt/sda1/FTPlog.txt", FILE_APPEND);
  if (logFile) {  // if the file is available, write to it:
    logFile.println(cc);
    logFile.close();
  }
}

good news! if I remove the line that removes the file (which is a simple swap file) the command works inside the sketch!

void serverUpdate () {
  Process p;
  cc = getTimeStamp();
  p.runShellCommandAsynchronously("curl -F file=@anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php");
  //p.runShellCommandAsynchronously("rm -f /mnt/sda1/anemoPark.csv ");
  while (p.available() > 0) {
    Serial.println(p.readString());
  }
  while (p.available()) {
    c = p.read();
    cc = cc + c;
  }
  cc += " uploaded on " + getTimeStamp(); //+ " , res=" + result + " , " + cc + " fine log.";
  cc.trim(); // IMPORTANT !!!
  File logFile = FileSystem.open("/mnt/sda1/FTPlog.txt", FILE_APPEND);
  if (logFile) {  // if the file is available, write to it:
    logFile.println(cc);
    logFile.close();
  }
}

don't know why yesterday this wasn't working...

EDIT so, now, how can I check that file transfer is completed? Should I change to runShellCommand synchronously?

Ok! I changed to :

void serverUpdate () {
  Process p;
  cc = getTimeStamp();
  p.runShellCommand("curl -F file=@anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php");
  //  p.runShellCommandAsynchronously("curl -F file=@anemoPark.csv http://ventolone.altervista.org/samplesload/filetodb.php");
  //  p.runShellCommandAsynchronously("rm -f /mnt/sda1/anemoPark.csv ");
  p.runShellCommand("rm -f /mnt/sda1/anemoPark.csv ");
  while (p.available() > 0) {
    Serial.println(p.readString());
  }
  while (p.available()) {
    c = p.read();
    cc = cc + c;
  }
  cc += " uploaded on " + getTimeStamp(); //+ " , res=" + result + " , " + cc + " fine log.";
  cc.trim(); // IMPORTANT !!!
  File logFile = FileSystem.open("/mnt/sda1/FTPlog.txt", FILE_APPEND);
  if (logFile) {  // if the file is available, write to it:
    logFile.println(cc);
    logFile.close();
  }
}

so...not the best we can do, but it is working! For those who will be in Turin, tomorrow: let's have a meeting, we will show you what this code is used for!

See you tomorrow then :)

supermarioprof: so, now, how can I check that file transfer is completed?

runShellCommand returns an int; like all Unix commands a zero is a successful execution. You'd have to read the curl docs for the explanation of non-zero exit codes.

runShellCommandAsynchronously does not return the exit code to the Arduino sketch. If you needed to capture that exit code, I make no guarantees this would work, but you might try something like:

p.runShellCommandAsynchronously("curl -F file=@anemoPark.csv http://foo.bar.com/ ; echo $? > /tmp/x");

The exit code from curl would be saved in the file /tmp/x. But because you never know when the execution of curl completes you'd have to keep re-checking for the presence of the file to know when it completed. Pretty messy so it would only be a good idea to do so if absolutely necessary.