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.
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: