Script reads BIN0
(binary input 0) on the Conel, SmartWorkx router and displaying it in a console. Can be looged in systemlog as well.
Little modification can be done to log it into the file, in CSV format.
#!/bin/ash
OLD0="-1"
SLEEP_TIME=1
while true
do
/usr/bin/io get bin0
VAL0=$? #get result from io command
if [ "$VAL0" != "$OLD0" ]; then #value changed
if [ "$VAL0" = "0" ]; then #relay closed
# /usr/bin/logger "relay closed" # logging into syslog
echo "`date +%D-%H:%M:%S`, relay closed"
# for a in $EMAIL1 $EMAIL2
elif [ "$VAL0" = "1" ]; then #relay open
# /usr/bin/logger "relay open" # logging into syslog
echo "`date +%D-%H:%M:%S`, relay open"
fi
OLD0=$VAL0
elif [ "$VAL0" == "$OLD0" ]; then
# /usr/bin/logger "no change" # logging into syslog
echo "`date +%D-%H:%M:%S`, no change"
fi
sleep $SLEEP_TIME
done