diff --git a/README.md b/README.md index 4fe1855..bdfc66d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/deamon/run b/deamon/run index 002b7bf..d3ba1a4 100755 --- a/deamon/run +++ b/deamon/run @@ -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() @@ -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 = "" diff --git a/deamon/scannereventfilename.txt b/deamon/scannereventfilename.txt index 09edaba..fe9dd19 100644 --- a/deamon/scannereventfilename.txt +++ b/deamon/scannereventfilename.txt @@ -1 +1 @@ -/dev/input/event7 +/dev/input/event2 diff --git a/deamon/supervise/status b/deamon/supervise/status index 737fd27..d00b8df 100644 Binary files a/deamon/supervise/status and b/deamon/supervise/status differ diff --git a/deamon/supervise/status.new b/deamon/supervise/status.new deleted file mode 100644 index e69de29..0000000 diff --git a/powerUSBdevice/99-powerusb.rules b/powerUSBdevice/99-powerusb.rules deleted file mode 100644 index 9d67c6e..0000000 --- a/powerUSBdevice/99-powerusb.rules +++ /dev/null @@ -1 +0,0 @@ -SUBSYSTEM=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="003f", MODE="0666" diff --git a/powerUSBdevice/README b/powerUSBdevice/README deleted file mode 100644 index 65cf3fe..0000000 --- a/powerUSBdevice/README +++ /dev/null @@ -1,5 +0,0 @@ -Permissions - - In order to assign read and write permissions for the PowerUSB device copy 99-powerusb.rules file into /etc/udev/rules.d and unplug and re-plug your device. - - - diff --git a/powerUSBdevice/executable/pwrusbcmd b/powerUSBdevice/executable/pwrusbcmd deleted file mode 100755 index eff7025..0000000 Binary files a/powerUSBdevice/executable/pwrusbcmd and /dev/null differ diff --git a/reset b/reset deleted file mode 100755 index e105359..0000000 Binary files a/reset and /dev/null differ diff --git a/reset.c b/reset.c deleted file mode 100644 index 321c464..0000000 --- a/reset.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include -#include -#include -void main(int argc, char **argv) -{ - const char *filename; - int fd; - filename = argv[1]; - fd = open(filename, O_WRONLY); - ioctl(fd, USBDEVFS_RESET, 0); - close(fd); - return; -} diff --git a/start-gate.sh b/start-gate.sh index e2bc952..c356ace 100755 --- a/start-gate.sh +++ b/start-gate.sh @@ -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 +