Difference between revisions of "Controling Homeautomation devices using wifi presence"

From BubbaWiki
Jump to navigation Jump to search
Line 2: Line 2:


This is a guide describing how to set up a device in Homeautomation that is automatically turned on or off based on whether a certain MAC address is connected to B3's wifi or not. This could then be used in the Homeautomation scheduling to turn other devices on or off based on this information.
This is a guide describing how to set up a device in Homeautomation that is automatically turned on or off based on whether a certain MAC address is connected to B3's wifi or not. This could then be used in the Homeautomation scheduling to turn other devices on or off based on this information.
First, copy the text below into
<pre>#!/bin/bash
<pre>#!/bin/bash


Line 40: Line 44:
   fi
   fi


done</pre>
done</pre>  
<br>
<br>  


More text here...<br>
More text here...<br>  
<pre>#!/bin/sh
<pre>#!/bin/sh


Line 71: Line 75:


case "$1" in
case "$1" in
start)
  start)
log_daemon_msg "Starting $DESC" "$NAME"
    log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
    start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
-- $DAEMON_OPTS &gt;/dev/null
      -- $DAEMON_OPTS &gt;/dev/null
log_end_msg "$?"
    log_end_msg "$?"
;;
    ;;
stop)
  stop)
log_daemon_msg "Stopping $DESC" "$NAME"
    log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --oknodo --quiet --exec "$DAEMON_SBIN"
    start-stop-daemon --stop --oknodo --quiet --exec "$DAEMON_SBIN"
log_end_msg "$?"
    log_end_msg "$?"
;;
    ;;
restart|force-reload)
  restart|force-reload)
$0 stop
    $0 stop
sleep 8
    sleep 8
$0 start
    $0 start
;;
    ;;
status)
  status)
status_of_proc "$DAEMON_SBIN" "$NAME"
    status_of_proc "$DAEMON_SBIN" "$NAME"
exit $?
    exit $?
;;
    ;;
*)
  *)
N=/etc/init.d/$NAME
    N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|status}" &gt;&amp;2
    echo "Usage: $N {start|stop|restart|force-reload|status}" &gt;&amp;2
exit 1
    exit 1
;;
    ;;
esac
esac


exit 0
exit 0


</pre>
</pre>  
<br>
<br>  


Finishing text...<br>
Finishing text...<br>

Revision as of 08:13, 29 June 2012

This guide is not finished yet. I'm working on it :-)

This is a guide describing how to set up a device in Homeautomation that is automatically turned on or off based on whether a certain MAC address is connected to B3's wifi or not. This could then be used in the Homeautomation scheduling to turn other devices on or off based on this information.


First, copy the text below into

#!/bin/bash

HomeAutomationUrl="http://192.168.168.1/homeautomation/"

# Devices that affects HomeAutomation
homeDevices[0]="84:00:d2:e4:3b:9f" #Xperia Ray
homeDevices[1]="d0:df:c7:fd:8d:ea" #Galaxy Tab

# HomeAutomation device ids
HomeAutomationDeviceIds[0]="20" #Xperia Ray
HomeAutomationDeviceIds[1]="21" #Galaxy Tab

connected="AP-STA-CONNECTED"
disconnected="AP-STA-DISCONNECTED"

countHomeDevices=${#homeDevices[*]}

date >> /var/log/hostapd.log

for (( i=0; i<=$(( $countHomeDevices -1 )); i++ )); do

  if [ $3 = "${homeDevices[$i]}" ]; then

    connectionState=0

    if [ $2 = $connected ]; then
      connectionState=1
      echo "$3 Connected!" >> /var/log/hostapd.log
    else if [ $2 = $disconnected ]; then
        echo "$3 Disconnected" >> /var/log/hostapd.log
      else
        echo "What happened now?" >> /var/log/hostapd.log
      fi
    fi

    $(wget -O /dev/null -q ""${HomeAutomationUrl}"ajaxinterface.php?do=toggleStatus&status="${connectionState}"&deviceid="${HomeAutomationDeviceIds[$i]}"" )
  fi

done


More text here...

#!/bin/sh

### BEGIN INIT INFO
# Provides: hostapd_cli
# Required-Start: $remote_fs ifup-br0 hostapd
# Required-Stop: $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Utility to trigger events based on connects/disconnects
# Description:
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON_SBIN=/usr/sbin/hostapd_cli
NAME=hostapd_cli
DESC="hostapd cli"
PIDFILE=/var/run/hostapd_cli.pid

[ -x "$DAEMON_SBIN" ] || exit 0

DAEMON_OPTS="-B -a/usr/local/bin/hostapd_log.sh"

. /lib/lsb/init-functions

case "$1" in
  start)
    log_daemon_msg "Starting $DESC" "$NAME"
    start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
      -- $DAEMON_OPTS >/dev/null
    log_end_msg "$?"
    ;;
  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    start-stop-daemon --stop --oknodo --quiet --exec "$DAEMON_SBIN"
    log_end_msg "$?"
    ;;
  restart|force-reload)
    $0 stop
    sleep 8
    $0 start
    ;;
  status)
    status_of_proc "$DAEMON_SBIN" "$NAME"
    exit $?
    ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
    exit 1
    ;;
esac

exit 0


Finishing text...