Hello, I'm using the runShellCommand() to execute a python script.
I've used this function with simple scripts like the following, and it works well.
hello_world.py
print "Hello World"
I can receive this string on the Arduino side.
But when I try to use the following script it returns nothing.
read_file.py
f = open ('text.txt','r+')
print f.readline()
I've executed this script on the console and it works well, it reads the first line of the text.txt and prints it.
I've noticed this problem happens when I call the open() function, when I don't call it Arduino executes correctly the script. What is doing this open() function that is not working when the script is called from Arduino?
Arduino sketch:
read_file.ino
#include <Process.h>
void setup() {
// Initialize Bridge
delay(60000);
Bridge.begin();
// Initialize Serial
Serial.begin(9600);
// Wait until a Serial Monitor is connected.
while (!Serial);
runPython(); // call python
}
void loop() {
//not used
}
//our Python callback
void runPython() {
Process p; // Create a process and call it "p"
p.runShellCommand("python /mnt/sda2/scripts/read_file.py"); // use CLI commands just like
//inside linux console
// A process output can be read with the stream methods
while (p.available()>0) {
char c = p.read();
Serial.print(c);
}
// Ensure the last bit of data is sent.
Serial.flush();
}