Difference between revisions of "Controling Homeautomation devices using wifi presence"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
This guide is not finished yet. I'm working on it :-)<br> | This guide is not finished yet. I'm working on it :-)<br> | ||
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. | |||
<pre>#!/bin/bash | <pre>#!/bin/bash | ||
Line 38: | Line 40: | ||
fi | fi | ||
done | done</pre> | ||
<br> | |||
More text here...<br> | |||
<pre>#!/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 | |||
</pre> | </pre> | ||
<br> | |||
Finishing text...<br> |
Revision as of 07:39, 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.
#!/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...