2 import time, socket, os, stat
3 from datetime import datetime
4 import RPi.GPIO as GPIO
5 GPIO.setmode(GPIO.BOARD)
8 print (datetime.now(),what)
10 def waynesend (conn, what):
14 log("Couldn't send %s" % str(what))
17 # actionsanddelays is a list of pairs: (bool to send, delay in seconds to wait afterwards)
18 def __init__ (self, name, pinnumber, actionsanddelays):
21 self.todo = actionsanddelays
22 GPIO.setup(pinnumber, GPIO.OUT)
23 log ("Pin %d set to be an output pin for %s." % (pinnumber,name))
25 def __call__ (self, conn):
26 for (value,delay) in self.todo:
27 GPIO.output(self.pin, value)
28 log ("%s: Pin %d set to %s." % (self.name,self.pin,str(value)))
34 pinlist = [Pinoutput("open", 12, [(True, 0.3), (False, 5.0)]),
35 Pinoutput("close", 16, [(True, 0.3), (False, 5.0)]),
36 Pinoutput("buzz", 22, [(True, 2.0), (False, 5.0)])]
38 socketname = "/run/tuer.sock"
46 sock = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
49 os.unlink (socketname)
53 sock.bind (socketname)
55 os.chown (socketname, 0, tuergroupid)
56 os.chmod (socketname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
62 pindict[pin.name.encode()] = pin
65 conn, addr = sock.accept()
66 data = conn.recv (128)
67 log("received command: %s" % str(data))
68 pindict.get(data,doNothing)(conn)