ChCh Öffnungsstatus: Unterschied zwischen den Versionen

Aus Chaostreff Chemnitz
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 23: Zeile 23:
ON_TOPIC=" | Status: geöffnet"
ON_TOPIC=" | Status: geöffnet"
OFF_TOPIC=" | Status: geschlossen"
OFF_TOPIC=" | Status: geschlossen"
STATUS_FILE="/home/chch-status/status"
###############
###############


Zeile 37: Zeile 38:
SED=/bin/sed
SED=/bin/sed
ECHO=/bin/echo
ECHO=/bin/echo
MV=/bin/mv
PS=/bin/ps
PS=/bin/ps
SLEEP=/bin/sleep
SLEEP=/bin/sleep
II=/usr/bin/ii
II=/usr/bin/ii
PASSWORD="kommtihrniedrauf"
#################
#################


Zeile 51: Zeile 54:
# RESTART II
# RESTART II
if [ -z "$II_RUNNING" ]; then
if [ -z "$II_RUNNING" ]; then
         $II -n $IRC_USER -i $IRC_PREFIX &
         $II -n $IRC_USER -i $IRC_PREFIX -k $PASSWORD &
         while [ $II_START_TIMEOUT -ge 0 -a ! -a $IRC_SRV_IN ]; do
         while [ $II_START_TIMEOUT -ge 0 -a ! -e $IRC_SRV_IN ]; do
                 II_START_TIMEOUT=$II_START_TIMEOUT-1
                 II_START_TIMEOUT=$(($II_START_TIMEOUT-1))
                 $SLEEP 1
                 $SLEEP 1
         done
         done
         if [ $II_START_TIMEOUT -lt 0 -a ! -a $IRC_SRV_IN ]; then
         if [ $II_START_TIMEOUT -lt 0 -a ! -e $IRC_SRV_IN ]; then
                 exit 1
                 exit 1
         fi
         fi
Zeile 65: Zeile 68:
fi
fi


if [ ! -a $IRC_CHAN_OUT ]; then
$ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN
if [ $? -ne 0 ]; then
        exit 1
fi
 
if [ ! -e $IRC_CHAN_OUT ]; then
         TMP=$JOIN_TIMEOUT
         TMP=$JOIN_TIMEOUT
         while [ $JOIN_TIMEOUT -ge 0 -a ! -a $IRC_CHAN_OUT ]; do
         while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do
                 JOIN_TIMEOUT=$JOIN_TIMEOUT-1
                 JOIN_TIMEOUT=$(($JOIN_TIMEOUT-1))
                 $SLEEP 1
                 $SLEEP 1
         done
         done
         if [ $JOIN_TIMEOUT -lt 0 -a ! -a $IRC_CHAN_OUT ]; then
         if [ $JOIN_TIMEOUT -lt 0 -a ! -e $IRC_CHAN_OUT ]; then
                 $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN
                 $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN
         fi
         fi
         JOIN_TIMEOUT=$TMP
         JOIN_TIMEOUT=$TMP
         while [ $JOIN_TIMEOUT -ge 0 -a ! -a $IRC_CHAN_OUT ]; do
         while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do
                 JOIN_TIMEOUT=$JOIN_TIMEOUT-1
                 JOIN_TIMEOUT=$(($JOIN_TIMEOUT-1))
                 $SLEEP 1
                 $SLEEP 1
         done
         done
         if [ $JOIN_TIMEOUT -lt 0 -a ! -a $IRC_CHAN_OUT ]; then
         if [ $JOIN_TIMEOUT -lt 0 -a ! -e $IRC_CHAN_OUT ]; then
                 exit 1
                 exit 1
         fi
         fi
Zeile 86: Zeile 94:
# FIND OUR LAST STATUS MESSAGE
# FIND OUR LAST STATUS MESSAGE
PREV_MSG=$($CAT $IRC_CHAN_OUT | $CUT -d":" -f2 | $GREP -e "^[0-9]\{2\} <$IRC_USER> $ON_MSG\$\|^[0-9]\{2\} <$IRC_USER> $OFF_MSG\$" | $TAIL -n1 | $GREP -oe "$ON_MSG\|$OFF_MSG")
PREV_MSG=$($CAT $IRC_CHAN_OUT | $CUT -d":" -f2 | $GREP -e "^[0-9]\{2\} <$IRC_USER> $ON_MSG\$\|^[0-9]\{2\} <$IRC_USER> $OFF_MSG\$" | $TAIL -n1 | $GREP -oe "$ON_MSG\|$OFF_MSG")
$TAIL -n 300 $IRC_SRV_OUT > ${IRC_SRV_OUT}_tmp
$MV ${IRC_SRV_OUT}_tmp $IRC_SRV_OUT
CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $GREP -v "[[:alnum:]]*!~[[:alnum:]]*@" | $TAIL -n1 | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I")
CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $GREP -v "[[:alnum:]]*!~[[:alnum:]]*@" | $TAIL -n1 | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I")
CURRENT_STATUS=$($ECHO $CURRENT_TOPIC | $GREP -oe "$ON_TOPIC$\|$OFF_TOPIC$")
CURRENT_STATUS=$($ECHO $CURRENT_TOPIC | $GREP -oe "$ON_TOPIC$\|$OFF_TOPIC$")
Zeile 101: Zeile 111:
fi
fi


# SEND MESSAGE IF IT DIFFERS FROM PREVIOUS STATUS
$ECHO -e $TOPIC | $CUT -d: -f2 | $SED -e "s/^[[:space:]]*//" > $STATUS_FILE
if [ "$MSG" != "$PREV_MSG" ]; then
 
        $ECHO -e "$MSG\n" > $IRC_CHAN_IN
if [ ! -z "$CURRENT_TOPIC" ]; then
fi
        # SEND MESSAGE IF IT DIFFERS FROM PREVIOUS STATUS
# SET TOPIC IF IT DIFFERS FROM PREVIOUS ONE
        if [ "$MSG" != "$PREV_MSG" ]; then
if [ "$TOPIC" != "$CURRENT_STATUS" ]; then
                $ECHO -e "$MSG\n" > $IRC_CHAN_IN
        $ECHO -e "/t $CURRENT_TOPIC$TOPIC\n" > $IRC_CHAN_IN
        fi
fi
        # SET TOPIC IF IT DIFFERS FROM PREVIOUS ONE
if [ $? -ne 0 ]; then
        if [ "$TOPIC" != "$CURRENT_STATUS" ]; then
                $ECHO -e "/t $CURRENT_TOPIC$TOPIC\n" > $IRC_CHAN_IN
        fi
        if [ $? -ne 0 ]; then
                exit 1
        fi
else
         exit 1
         exit 1
fi
fi
</pre>
</pre>

Version vom 10. Februar 2013, 14:23 Uhr

Dieses Script wird einmal in der Minute gestartet und prüft das Ring-Signal der seriellen Schnittstelle. Wenn unsere Außenbeleuchtung eingeschaltet wird, gibt es dies im IRC bekannt. Ebenso gibt es das Ausschalten bekannt.

           -| |+    ______            ______
Zuleitung   | |  .-|______|-o-->|--o-|______|-.   R1=R2=1k
LED-Leucht- | o--'    R1    |  D1  |    R3    |   R3=10k
reklame     o-|--.  ______  |      |   +C1-   |   C1=47µ
(ChCh)      | |  o-|______|-'      o----||----o--Pin 5 (GND)
            | |  |    R2           '----------|--Pin 9 (RI)
            | |  '----------------------------'

Der Schriftzug besteht aus einer blauen LED-Lichterkette, die von einer gelochten Kunststoffkonstruktion in Form gehalten wird. Das Netzteil liefert 24V Wechselspannung, welche jedoch im Stecker der Lichterkette (Zusätzlicher Stecker zwischen Netzteil und Zuleitung der Lichterkette) teilweise gleichgerichtet wird. Die oben dargestellte Schaltung halbiert und glättet die Spannung, so dass diese direkt am Seriellen Anschluss eines PCs ausgewertet werden kann.

#! /bin/bash

# USER CONFIG #
IRC_USER="chch"
IRC_CHANNEL="#chaoschemnitz"
IRC_SERVER="irc.freenode.net"
ON_MSG="Wir haben geöffnet."
OFF_MSG="Wir schließen jetzt."
ON_TOPIC=" | Status: geöffnet"
OFF_TOPIC=" | Status: geschlossen"
STATUS_FILE="/home/chch-status/status"
###############

# SYSTEM CONFIG #
II_START_TIMEOUT=10
JOIN_TIMEOUT=10
IRC_PREFIX=/var/irc
PORT="port:000003F8"

CAT=/bin/cat
CUT=/usr/bin/cut
TAIL=/usr/bin/tail
GREP=/bin/grep
SED=/bin/sed
ECHO=/bin/echo
MV=/bin/mv
PS=/bin/ps
SLEEP=/bin/sleep
II=/usr/bin/ii
PASSWORD="kommtihrniedrauf"
#################

IRC_CHAN_IN=$IRC_PREFIX/$IRC_SERVER/$IRC_CHANNEL/in
IRC_CHAN_OUT=$IRC_PREFIX/$IRC_SERVER/$IRC_CHANNEL/out
IRC_SRV_IN=$IRC_PREFIX/$IRC_SERVER/in
IRC_SRV_OUT=$IRC_PREFIX/$IRC_SERVER/out
II_RUNNING=$($PS awx | $GREP "ii" | $GREP "\-n $IRC_USER")
RING=$($CAT /proc/tty/driver/serial | $GREP "$PORT" | $GREP -o "RI")

# RESTART II
if [ -z "$II_RUNNING" ]; then
        $II -n $IRC_USER -i $IRC_PREFIX -k $PASSWORD &
        while [ $II_START_TIMEOUT -ge 0 -a ! -e $IRC_SRV_IN ]; do
                II_START_TIMEOUT=$(($II_START_TIMEOUT-1))
                $SLEEP 1
        done
        if [ $II_START_TIMEOUT -lt 0 -a ! -e $IRC_SRV_IN ]; then
                exit 1
        fi
        $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN
        if [ $? -ne 0 ]; then
                exit 1
        fi
fi

$ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN
if [ $? -ne 0 ]; then
        exit 1
fi

if [ ! -e $IRC_CHAN_OUT ]; then
        TMP=$JOIN_TIMEOUT
        while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do
                JOIN_TIMEOUT=$(($JOIN_TIMEOUT-1))
                $SLEEP 1
        done
        if [ $JOIN_TIMEOUT -lt 0 -a ! -e $IRC_CHAN_OUT ]; then
                $ECHO -e "/j $IRC_CHANNEL\n" > $IRC_SRV_IN
        fi
        JOIN_TIMEOUT=$TMP
        while [ $JOIN_TIMEOUT -ge 0 -a ! -e $IRC_CHAN_OUT ]; do
                JOIN_TIMEOUT=$(($JOIN_TIMEOUT-1))
                $SLEEP 1
        done
        if [ $JOIN_TIMEOUT -lt 0 -a ! -e $IRC_CHAN_OUT ]; then
                exit 1
        fi
fi

# FIND OUR LAST STATUS MESSAGE
PREV_MSG=$($CAT $IRC_CHAN_OUT | $CUT -d":" -f2 | $GREP -e "^[0-9]\{2\} <$IRC_USER> $ON_MSG\$\|^[0-9]\{2\} <$IRC_USER> $OFF_MSG\$" | $TAIL -n1 | $GREP -oe "$ON_MSG\|$OFF_MSG")
$TAIL -n 300 $IRC_SRV_OUT > ${IRC_SRV_OUT}_tmp
$MV ${IRC_SRV_OUT}_tmp $IRC_SRV_OUT
CURRENT_TOPIC=$($ECHO "/TOPIC $IRC_CHANNEL" > $IRC_SRV_IN; $SLEEP 3; $CAT $IRC_SRV_OUT | $GREP -i -e "[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL" | $GREP -v "End of /NAMES list." | $GREP -v "[[:alnum:]]*!~[[:alnum:]]*@" | $TAIL -n1 | $SED -e "s/[0-9]\{4,\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\} $IRC_CHANNEL //I")
CURRENT_STATUS=$($ECHO $CURRENT_TOPIC | $GREP -oe "$ON_TOPIC$\|$OFF_TOPIC$")
if [ ! -z "$CURRENT_STATUS" ]; then
        CURRENT_TOPIC=$($ECHO $CURRENT_TOPIC | $SED -e "s/$CURRENT_STATUS//")
fi

# CHOOSE CORRECT MESSAGE AND TOPIC
if [ -z "$RING" ]; then
        MSG="$OFF_MSG"
        TOPIC="$OFF_TOPIC"
else
        MSG="$ON_MSG"
        TOPIC="$ON_TOPIC"
fi

$ECHO -e $TOPIC | $CUT -d: -f2 | $SED -e "s/^[[:space:]]*//" > $STATUS_FILE

if [ ! -z "$CURRENT_TOPIC" ]; then
        # SEND MESSAGE IF IT DIFFERS FROM PREVIOUS STATUS
        if [ "$MSG" != "$PREV_MSG" ]; then
                $ECHO -e "$MSG\n" > $IRC_CHAN_IN
        fi
        # SET TOPIC IF IT DIFFERS FROM PREVIOUS ONE
        if [ "$TOPIC" != "$CURRENT_STATUS" ]; then
                $ECHO -e "/t $CURRENT_TOPIC$TOPIC\n" > $IRC_CHAN_IN
        fi
        if [ $? -ne 0 ]; then
                exit 1
        fi
else
        exit 1
fi