Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Gate-Code

uses https://github.com/branning/hs100 to control wifi smart plug

Requires supervise: https://cr.yp.to/daemontools/supervise.html

needs python evdev module

add a task in crontab:
# Every day at 5am restart the gate so that you make sure the gate is running and also this resets the USB-controlled power strip because sometimes it bugs
0 5 * * * /home/blake/excursion/yassine/start-gate.sh
0 5 * * * ~/Gate-Code/start-gate.sh
16 changes: 8 additions & 8 deletions deamon/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import urllib2
import subprocess
import time
from evdev import InputDevice, ecodes
with open('/home/blake/excursion/yassine/deamon/scannereventfilename.txt') as fevent:
with open('~/Gate-Code/deamon/scannereventfilename.txt') as fevent:
ss=fevent.read().splitlines()[0]
#print(ss)
#quit()
Expand All @@ -21,16 +21,16 @@ for event in dev.read_loop():
#except urllib2.HTTPError:
# data = 401
# pass
print(data)
print("good RFID!!")
# print(data)
# print("good RFID!!")
if data == 200:
with open("/home/blake/excursion/yassine/gatelogs/gate.log", "a") as f:
with open("~/gatelogs/gate.log", "a") as f:
f.write(time.strftime("%Y-%m-%d %H:%M:%S")+" "+rfid+"\n")
subprocess.call(['/home/blake/excursion/yassine/powerUSBdevice/executable/pwrusbcmd', '0', '0', '1'])
subprocess.call(['~/hs100/hs100.sh', 'on'])
subprocess.call(['sleep', '5'])
subprocess.call(['/home/blake/excursion/yassine/powerUSBdevice/executable/pwrusbcmd', '0', '0', '0'])
subprocess.call(['~/hs100/hs100.sh', 'off'])
except:
print("BADDD rfid")
with open("/home/blake/excursion/yassine/gatelogs/gate.log", "a") as f:
# print("BADDD rfid")
with open("~/gatelogs/gate.log", "a") as f:
f.write(time.strftime("%Y-%m-%d %H:%M:%S")+" tag "+rfid+" not in system\n")
rfid = ""
2 changes: 1 addition & 1 deletion deamon/scannereventfilename.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/dev/input/event7
/dev/input/event2
Binary file modified deamon/supervise/status
Binary file not shown.
Empty file removed deamon/supervise/status.new
Empty file.
1 change: 0 additions & 1 deletion powerUSBdevice/99-powerusb.rules

This file was deleted.

5 changes: 0 additions & 5 deletions powerUSBdevice/README

This file was deleted.

Binary file removed powerUSBdevice/executable/pwrusbcmd
Binary file not shown.
Binary file removed reset
Binary file not shown.
15 changes: 0 additions & 15 deletions reset.c

This file was deleted.

32 changes: 18 additions & 14 deletions start-gate.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#!/bin/bash
killall -9 supervise 2>/dev/null # kill the deamon
BUS=$(lsusb | grep '04d8:003f' | awk '{print $2}') # get the bus number for power strip
DEVICE=$(lsusb | grep '04d8:003f' | awk '{print $4}' | sed 's/\([0-9]*\).*/\1/') # get the device number for power strip

touch ~/gatelogs/gate.log #make sure gate log is there
gateIP=$(~/hs100/hs100.sh discover | awk 'NF{ print $NF }') # get smart plug ip

EVENTNUM=$(ls -l /dev/input/by-id/ | grep event | grep -v -i keyboard | awk '{print $11}' | cut -d"/" -f2) # get event number for scanner
if [ -n "${BUS}" ] && [ -n "${EVENTNUM}" ]
if [ -n "${gateIP}" ] && [ -n "${EVENTNUM}" ]
then
# reset the USB-controlled power strip first because it keeps bugging uughhh
echo "Reseting PowerUSB with the following values"
echo "Bus:" $BUS " Device:" $DEVICE " EventNum:" $EVENTNUM
echo xnqpla29 | sudo -S /home/blake/excursion/yassine/reset /dev/bus/usb/$BUS/$DEVICE # reset USB-controlled power strip
echo "Scanner found at EventNum:" $EVENTNUM
echo xnqpla29 | sudo -S chmod 666 /dev/input/$EVENTNUM #get persmission to access scanner
echo /dev/input/$EVENTNUM > /home/blake/excursion/yassine/deamon/scannereventfilename.txt # deamon/run will read this file for the filename
nohup supervise /home/blake/excursion/yassine/deamon &>/dev/null & # this runs the code in deamon/run and keep it running
echo /dev/input/$EVENTNUM > ~/Gate-Code/deamon/scannereventfilename.txt # deamon/run will read this file for the filename

echo "Smart plug found at IP " $gateIP
echo xnqpla29 | sudo -S sed -i "\$ a $gateIP\ths100\n" /etc/hosts #add smart plug to known hosts

nohup supervise ~/Gate-Code/deamon &>/dev/null & # this runs the code in deamon/run and keep it running
fi
if [ -z "${EVENTNUM}" ]
if [ -z "${gateIP}" ]
then
echo "Can't find gate scanner!! Gate scanner probably not plugged" 1>&2
echo "Can't find gate smart plug!! its probably not plugged" 1>&2
exit 1
fi

if [ -z "${BUS}" ]
if [ -z "${EVENTNUM}" ]
then
echo "Can't find BUS number!! USB-controlled power strip probably not plugged" 1>&2
echo "Can't find gate scanner!! Gate scanner probably not plugged" 1>&2
exit 1
fi
fi