Bash read with ttyUSB0 and send url

I am starting a bash newbie and I am struggling to put everything together.

I am trying to do the following:

1) Set port (stty)
2) Reading with dev / ttyUSB0 - the data should look like 000118110000101 (cat or Gawk?)
3) Set the read data to a variable, such as DATA, and create a URL, such as http://domain.com/get_data.php?data= $ DATA
4) load url using wget?
5) Wait for more data from ttyUSB0 (poll or loop?)

I tried the php DIO extension, which works, but is not reliable, because for some reason it stops / starts.

ANY suggestions would be greatly appreciated, I will be very pleased if anyone can advise a better way to do this

thanks

Brent

+4
source share
2 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 
+7
source

For the first step, I would advise reading the file and then using od to get the octal (no binary, as far as I can see) representation, because the standard awk does not cope with NUL (I think gawk too). So after you get the bytes, you pass it through a sed script to change the octal to binary, take the output using $() (or apostrophes) and create the URL that you pass to wget .

The only problem I see is locked / not locked, read from usb. Notify if there will be.

0
source

Source: https://habr.com/ru/post/1338987/


All Articles