Tips for sending input to a Yun Process via stdin()?

Is it possible to write to the stdin of an Arduino Yun Linux process launched by the Bridge Process of a sketch?

Context: I have a control and logging application that needs to log data to a Google Drive spreadsheet using Temboo.com. While I have successfully implemented this functionality in the Arduino sketch following Temboo examples, the sketch size exceeds the available AVR memory. To address this issue, I intend to split the functionality: control and data acquisition on the AVR side and Python-Temboo on the Linux side.

To start testing this approach, I created a 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 executed this script via an ssh session and input a series of characters, which successfully resulted in writing to a file:

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

However, I am facing challenges while trying to achieve the same behavior from within the Arduino sketch. The blocking nature of the Process.run() method is preventing successful execution as the process blocks the sketch before allowing writes:

Process p;  // Create a process and name it "p" 
p.begin("python");  // Launch the "Python" command as a process
p.addParameter("/root/stdinFile.py"); // Include the script name for the "python" process
p.run(); // This is blocking! Script hangs 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 attempted to perform the writes prior to p.run(), essentially filling the stdin stream before script execution, but this approach did not yield any desired outcomes either.

Any suggestions or help would be greatly appreciated!

Answer №1

For a more efficient process execution, consider using p.runAsynchronously() in place of p.run(). This method is non-blocking, allowing you to monitor the script's progress with p.running(). Detailed information on the process class can be found at the following link:

https://www.example.com/docs/process-class

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to store a collection of class instances in a serialized format

Is there a way to convert an object that contains a list of objects into JSON format? Error message received: TypeError: Object of type person is not JSON serializable Here's the code snippet in question: import json class person: def __init__( ...

Adding rows together using conditions in the Pandas library

I'm trying to figure out how to sum a subset of rows based on two indices in Pandas. The first index groups the rows, while the second index determines which rows to sum. To illustrate this, let's consider the following dataframe: index1 | index ...

Error: You need to have `accelerate` installed in order to use the `Trainer` with `PyTorch` package

A few months ago, I developed a code to train an NER model which was functioning perfectly. However, when I tried running the same code recently, I encountered this error: ImportError: Using the `Trainer` with `PyTorch` requires `accelerate`: Run `pip inst ...

I am interested in inputting information into a specific tab within a Google Sheet

Using the following code snippet, I can successfully retrieve data from my Gsheet. #AUTHENTICATING THE CREDENTIALS FOR CONNECTING THE SCRIPT TO GSHEET gc = pygsheets.authorize(service_file='client_secret.json' ) # CONNECTING THE GSHEET sh = gc.o ...

The website's reaction to the request for URLs was not what was anticipated

I'm trying to load a website and scrape all of the links, which is usually simple but I encountered an unusual response today: links = WebDriverWait(web, 20).until(EC.presence_of_all_elements_located((By.XPATH,'//a[@href]'))) print("Thi ...

"Need help clicking on a table with multiple classes in Gmail search functionality? I've included a screenshot for reference - please take a look

image description here Need help with clicking on a table with multiple classes, specifically related to Gmail searching. Please refer to the attached screenshot for more details. ...

Deleting a segment of code in HTML with Python

My HTML text is lengthy and follows this structure: <div> <div> <p>Paragraph 1 Lorem ipsum dolor... long text... </p> <p>Paragraph 2 Lorem ipsum dolor... long text... </p> <p>Paragraph ...

Ways to extract information from a table cell located next to a table cell with colspan

As a beginner in web scraping, I am gradually making progress. However, I'm facing a tough challenge with this particular task. My goal is to extract data from the ESPN NBA boxscore website: I aim to scrape the names of players labeled as "DNP" (Did ...

Is there a way to efficiently download a large number of images (70,000) from URLs while adhering to restrictions on simultaneous downloads

I'm feeling a bit lost here. I have this csv file containing two columns: name and picture URL. My goal is to bulk download the 70k images from the file and save them in a folder, renaming each image with the corresponding name from the first column. ...

Obtaining the value of a particular cell and filling in any missing data in a PySpark dataframe

I am currently in the process of transforming a python code into pyspark. My goal is to utilize fillna to replace any missing values with a value from another column within the same dataframe, specifically at index 0. Here is the original python code that ...

The `__builtin__` module in Python is an essential component

When I have a module named Test and need to list all the functions in it, I use the following code: import Test dir(Test) I must import the module to be able to use the functions defined in it. However, all the functions in the __builtin__ module can be ...

Discovering the total number of defeats within a sequence

My data set consists of elements like [0, 0, 0, 1, 2, -1, -2, 5, 8, 4, 5.5]. I am interested in determining how many times an element is less than the one that came before it (excluding the initial zeros which signify missing data). In this instance, the ...

How to halt a pygtk operation

I am currently working on a project that involves creating an application to control the playback of a midi file using pygtk. Here's what I have developed so far: import pygtk pygtk.require('2.0') import gtk import subprocess class Music ...

Using Python Selenium web-driver to hide console windows within a tkinter application

After creating a basic GUI using the tkinter library, I implemented a feature that opens a new thread with Selenium when the user clicks on a button: In the start_button3_callback method: # Initiating a new thread to run the button3_callback function in t ...

What is the best way to transfer information from df ~ to my webpage?

I'm currently working on a pie chart that visualizes the disk space usage on my Linux machine. I need help figuring out how to properly parse this data onto a microservice URL. Any assistance would be greatly appreciated. Here's what I have so f ...

Unlocking documents labeled within a code using Spyder4

I'm facing a challenge with accessing a list of functions stored in a file named functions.py. I need to call these functions in my main program file, but I am struggling to open the file. In Spyder 3, I used to hover over the filename and do ctrl+rig ...

Is it feasible to execute an XHR request and display the result using Selenium?

Is it feasible to execute an XmlHttpRequest using Selenium/Webdriver and display the results in a browser window? If this is achievable, I would appreciate some guidance on how to do so. ...

Is it beneficial to mandate developers to include element IDs for the purpose of creating thorough automated tests?

Currently, I am in the process of writing Selenium tests for a web application that is built using React. However, I am encountering some challenges when it comes to writing tests in Selenium. It seems that many elements do not have unique IDs that can be ...

Setting up Python ARM in a Docker environment can be quite time-consuming due to the

Looking to launch a Docker container containing Python bots that require libraries like pandas, numpy, and matplotlib. While everything runs smoothly in an x86 environment, the process of building the image on an Arm environment is significantly slower. I ...

Is there a different option to use instead of time.sleep() when web scraping with Selenium in Python?

I am currently working on a project that involves scraping prices for specific food items based on different locations across the country. One of the features allows users to enter the name of a city in an input text box and then view a list of available i ...