I've seemingly searched many very similar questions but never quite found something to work. I'm trying to use a raspberry pi (2nd gen) to communicate with a Wifi OBDII sensor. I'm able to use the following command
nc -C 192.168.0.10 35000
192.168.0.10 is the car sensor and 35000 the port. It's not that relevant as connecting seems to be fine. Anyways, I can open a nc instance and then type, for example "0145" (a sensor code), and in return I get a value for that sensor back on the output of the nc session (for say, the RPM of my engine). That works fine. What i'd like to do is pipe commands from a text file into the nc session for plotting purposes. So my ideal result would be a constant stream of RPM values and associated times dumped into a text file. I can work from there. However, I don't exactly know how to do that. I've set up a commands.txt which is thousands of lines of "0145" and I'd like to read that file and pass it line by line to nc (I can probably control the sampling interval with sleep), and then read the output and stash those into a text file. I know this issue has something to do with stdin and stdout and piping, but for whatever reason, I haven't been able to quite get it. I am by no means a master at any of those. I'd also like to script the entire process.
Right now, if i run
cat <(echo 0145) - | nc -C 192.168.0.10 35000
that gives me the output in the terminal that I want, but only works for a single value. But as soon as I try to put it into a loop, where I make that 0145 into $commands in the script and get $commands line by line from a txt file, it ceases to work. In fact, it stops working inside any loop or if block even if I leave it as 0145 and dont use a variable.
So, long story short, I want to script sending a txt file line by line to a nc connection, and then I want to extract each response into another file. If it was unscripted, I can open that nc connection and send 0145 every 1 second and get those responses (still dont know how to pass them to a file), but thats hardly efficient. I feel like there should be an easier way to do this. I'm somewhat of a noob but figured id give it a shot here. Any help is greatly appreciated