How to find file size in Arduino YUN ??

Hi,

I am working on Arduino YUN. I am sending data from YUN to my web server. I want to place a check on the size of file before uploading it. Like if my file is of o.5MB then upload otherwise wait. But I am stuck with how to find the size of the file placed in the SD card of my Arduino YUN.

I tries file.size() but it gives me 0 on serial termianl. Help me out.

Thanks.

Sadly, File::size() is not implemented yet.

http://forum.arduino.cc/index.php?topic=188757.msg1397702#msg1397702

Work around:

nano /mnt/sda1/filesize.sh
#!/bin/sh
/bin/ls -l $1 |/usr/bin/awk '{print $5}'
chmod 755 /mnt/sda1/filesize.sh
/mnt/sda1/filesize.sh /mnt/sda1/test.txt

By using bridge you could call filesize.sh, pass file path as argument and get back file size.

Hi,

Thanks for the reply, it got solved. I have another issue, I want to connect to the YUN with my WIFI, I know my pass n ssid. You provided the code in this forum, Can the Yun be programmed to connect automatically to a Wi-fi connection? - Arduino Yún - Arduino Forum .... I copied it and pasted it like that

File script = FileSystem.open("/tmp/setupwifi.sh", FILE_WRITE);
  // Shell script header
  script.print("#!/bin/sh\n");
  script.print("/sbin/uci set  network.lan=interface\n");
  script.print("/sbin/uci set  network.lan.proto=dhcp\n");
  script.print("/sbin/uci delete  network.lan.ipaddr\n");
  script.print("/sbin/uci delete  network.lan.netmask\n");
  script.print("/sbin/uci set wireless.@wifi-iface[0].mode=sta\n");
  script.print("/sbin/uci set wireless.@wifi-iface[0].ssid=XEO\n"); 
  script.print("/sbin/uci set wireless.@wifi-iface[0].encryption=psk\n");
  script.print("/sbin/uci set wireless.@wifi-iface[0].key=pakistan\n");
  script.print("/sbin/uci commit wireless; /sbin/wifi\n");
  script.print("/etc/init.d/network  restart\n");
  script.close();  // close the file

  // Make the script executable
  Process chmod;
  chmod.begin("chmod");      // chmod: change mode
  chmod.addParameter("+x");  // x stays for executable
  chmod.addParameter("/tmp/setupwifi.sh");  // path to the file to make it executable
  chmod.run();

After that I run the script and checked the status like this:

Process myscript;
  myscript.begin("/tmp/setupwifi.sh");
  myscript.run();

  String output = "";

  // read the output of the script
  while (myscript.available()) {
    output += (char)myscript.read();
  }
  // remove the blank spaces at the beginning and the ending of the string
  output.trim();
  Serial.println(output);
  
  Process wifiCheck;  // initialize a new process

  wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");  // command you want to run

  // while there's any characters coming back from the
  // process, print them to the serial monitor:
  while (wifiCheck.available() > 0) {
    char c = wifiCheck.read();
    Serial.print(c);
  }

  Serial.println();
  
  Serial.flush();

But its still not working. The response I am getting is something like that:

Current WiFi configuration
SSID: XEO
Mode: Client
Signal: 0%
Encryption method: -

Am I doing something wrong here. Please let me know.