Reputation: 620
I am a bash novice and I am struggling with putting it all together.
What I am trying to do is:
1) Set Port (stty)
2) Read from dev/ttyUSB0 - data should look like 000118110000101 (cat or Gawk?)
3) Set read data into a variable eg DATA and create a URL eg http://domain.com/get_data.php?data=$DATA
4) load the URL with wget?
5) Wait for more data from ttyUSB0 (polling or loop?)
I have tried the php DIO extention that does work but is not reliable because it stops/starts for some reason.
ANY suggestions would be much appreciated, I will be very great-full if anyone could advise the best way to do this
Thanks
Brent
Upvotes: 4
Views: 17029
Reputation: 620
This is what I used.
#Set permisions
sudo chmod o+rwx /dev/ttyUSB0
#!/bin/bash
# Port setting
stty -F /dev/ttyUSB0 cs7 cstopb -ixon raw speed 1200
# Loop
while [ 1 ];
do
echo 'LOADING...'
READ=`dd if=/dev/ttyUSB0 count=22 | sed 's/ //g'`
echo $READ
wget http://localhost/BASHtest/test.php?signal=$READ
echo '[PRESS Ctrl + C TO EXIT]'
done
Upvotes: 8
Reputation:
For the first step i would advise to read to a file and then use od to get an octal (there's no binary as far as i can see) representation, because standard awk doesn't cope with NULs (i think gawk too). So after you get the bytes, you pipe it through sed script to change octals to binaries, grab the output with $()
(or apostrophs) and make an URL, which you feed to wget
.
The only problem i can see is blocked/nonblocked read from usb. Please report if there will be one.
Upvotes: 0