Hello all!
I have created an rs323 loop and connected it to my door. When its closed, loop is closed, when door is open loop is open.
Trying to create two bash scripts, one of which will write to serial, and the other read from it. Consequently if the read pattern is different to what was sent the door would be marked as open.
Write script is relatively easy:
Code:
#/bin/bash
while true
do
sleep 0.1
echo "t" > /dev/ttyS0
done
However reading is a bit more tricky. I ve been trying to improve what I wrote many times, but I keep on getting a few false alarms (currently around 20-30%).
Here is my read code:
Code:
#/bin/bash
tester=0
seq=0
opened=10
while true
do
let "tester += 1"
let "LINE = empty"
read -t 1 LINE < /dev/ttyS0
if [ "$LINE" = "t" ]
then
if [ $opened= "1" ]
then
let "opened= 0" # CLOSED
fi
let "seq = 0"
else
let "seq += 1"
fi
if [ $seq = "5" ]
then
let "opened= 1" # OPEN
fi
done
Any hint or idea of how to create it in a more professional way?