Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash read from ttyUSB0 and send to URL

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

like image 681
afro360 Avatar asked Feb 26 '23 03:02

afro360


1 Answers

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
like image 72
afro360 Avatar answered Mar 05 '23 16:03

afro360