简体   繁体   中英

How to write to stdin() of a Yun Process?

How do I write to the stdin of an Arduino Yun Linux process that was launched by the Bridge Process of a sketch?

Background: I have an control and logging application that needs to log to a Google Drive spreadsheet through Temboo.com. I have it working from the Arduino sketch as given in the Temboo examples. But my sketch is too large and won't fit in the available AVR memory, so I want to split it: control and data acquisition on the AVR side, and Python-Temboo on the Linux side.

I started testing with this simple Python script stdinFile.py :

import sys
# Read the string from stdin
rowData = sys.stdin.readline()
f = open("blah.txt","w")
f.write(rowData)
f.close
sys.exit(0)

I invoke it from a ssh session and type a bunch of characters. It works: stdin is written to the file!

root@Arduino:~# python /root/stdinFile.py
adsfsadfdsaf
root@Arduino:~# cat blah.txt
adsfsadfdsaf

But how do I do this from the Arduino sketch? The Process.run() method is blocking so this didn't work -- the process blocked the sketch before the writes:

Process p;  // Create a process and call it "p" 
p.begin("python");  // Process to launch the "Python" command
p.addParameter("/root/stdinFile.py"); // Add the script name to "python"
p.run(); // this is blocking! Script stalls here waiting for stdin

char record[]="2015-09-06,21:20:00,F,T,F,F,18.3,18.4,19.3,19.4,30.6,28.6";
for( char * src = record; *src != '\0'; src++) {
    p.write(*src);
}
p.flush();

I also tried doing the writes before the p.run() , in other words, stuffing the stdin stream before the script runs, but that didn't give any results either.

Thanks!

You can try using p.runAsynchronously() instead of p.run(). runAsynchronously() is non-blocking and you can check if the script is still running using p.running(). You can find documentation for the process class in the link below:

https://www.arduino.cc/en/Reference/YunProcessConstructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM