def fishtank(): logger = log.RotatingFile("/var/log/picontroller/logs") sensorAir = temp_sensor.TempSensor.new(name="Room",sensor="/sys/bus/w1/devices/28-0014117fb1ff/w1_slave") sensorTank = temp_sensor.TempSensor.new(name="Tank", sensor="/sys/bus/w1/devices/28-00000676eb5f/w1_slave") pinList = [11, 13, 15, 16] r0 = relay.Relay(pin=pinList[0],name="Relay1") r1 = relay.Relay(pin=pinList[1],name="Relay2") r0.init() r1.init() t0 = timer.Timer('Light1') t0.set(timer.S3,timer.S3,timer.S3,timer.S3,timer.S3,timer.S5,timer.S5) t1 = timer.Timer('Light2') t1.set(timer.S4,timer.S4,timer.S4,timer.S4,timer.S4,timer.S6,timer.S6) webserver.temps.append(sensorAir) webserver.temps.append(sensorTank) webserver.relays.append(r0) webserver.relays.append(r1) webserver.timers.append(t0) webserver.timers.append(t1) webserver.start_server() now = 0 while True: while time.time() < now: time.sleep(1) now = time.time()+60 sensorAir.tick() sensorTank.tick() if t0.on(): r0.turn_relay_on() else: r0.turn_relay_off() if t1.on(): r1.turn_relay_on() else: r1.turn_relay_off() timestamp = datetime.datetime.utcnow().isoformat('T')+"000Z" l = "time:{t}\troom:{r}\ttank:{w}\tlight0:{r0}\tline1:{r1}".format(t=timestamp, r=sensorAir.current_value, w=sensorTank.current_value, r0=r0.current_state, r1=r1.current_state) logger.log(l)
def __init__(self, run, logger): self._run = run self.probe = temperature_probe.Probe() self.relay = relay.Relay() self.int_error = 0 self.logger = logger self.is_active = True
def wait(self): print "myNode : " + self.net.myNode print "Launching server... press Ctrl-C to quit relay mode" try: self.csock, self.addr = self.sock.accept() except KeyboardInterrupt: self.sock.close() return False data = "" while True: try: tmp = self.csock.recv(1024) except: break if not tmp: break data += tmp if self.net.debug: print "received %d bytes data: " % (len(data)) + repr(data) rel = relay.Relay(self.net) rel.parse(data) rel.relay() return True
def Regulator(reg_type): return_value = None if reg_type == 'repeater': return_value = repeater.Repeater() elif reg_type == 'relay': return_value = relay.Relay() else: print('type of regulator is underfined') return return_value
def main(): if len(sys.argv) > 1: state = sys.argv[1] if state not in ('on', 'off'): state = None else: state = None if not state: usage() return initial_state = (state == 'on') a_relay = relay.Relay(initial_state=initial_state)
def fermenter(): logger = log.RotatingFile("/var/log/picontroller/logs") sensorAir = temp_sensor.TempSensor.new(name='temp', sensor='/sys/bus/w1/devices/28-041501b016ff/w1_slave') pinList = [33,35,37] r0 = relay.Relay(pinList[0]) r0.init() webserver.temps.append(sensorAir) webserver.relays.append(r0) webserver.start_server() now = 0 while True: while time.time() < now: time.sleep(1) now = time.time()+60 sensorAir.tick() if sensorAir.current_value < 21.75: if relay_state == 0: relay_state = 1 r0.turn_relay_on() if sensorAir.current_value > 22.00 or last_temp < sensorAir.current_value: relay_state = 0 r0.turn_relay_off() last_temp = sensorAir.current_value timestamp = datetime.datetime.utcnow().isoformat('T')+"000Z" l = "time:{t}\ttemp:{r}\trelay:{r0}".format(t=timestamp, r=sensorAir.current_value, r0=r0.current_state) logger.log(l)
#!/usr/bin/env python # coding:utf-8 import RPi.GPIO as GPIO from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) touch_pin = 22 water_relay_pin = 5 GPIO.setup(touch_pin, GPIO.OUT) GPIO.output(touch_pin, GPIO.LOW) GPIO.setup(touch_pin, GPIO.IN, GPIO.PUD_UP) import relay rp = relay.Relay(water_relay_pin) while 1: try: if GPIO.wait_for_edge(touch_pin, GPIO.RISING): rp.twinkle(0.2, 0.5, 5) except KeyboardInterrupt: break
print "%s Failed to load Module: %s" % (__file__, err) sys.exit(1) #logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.CRITICAL) param = settings.settings() RotQueue = Queue() # define global que for events if param.RPI_Version is not None: import RotaryEncoder encoder = RotaryEncoder.RotaryEncoderWorker(param.A_PIN, param.B_PIN, param.SW_PIN, RotQueue) import relay Relay = relay.Relay(param.R_PIN) import atexit @atexit.register def close_gpio(): # close the gpio port at exit time encoder.Exit() def check_process(procname): if psutil.version_info[0] < 4: return procname in [p.name for p in psutil.process_iter()] else: return procname in [p.name() for p in psutil.process_iter()] class Matter(object):
import relay as r import motion_sensor as ms import light_sensor as ls # Set the different inputs/outputs for the Raspberry Pi modules and sensors. pin_motion_sensor_in = 11 pin_light_sensor_in = 12 pin_relay_out = 7 # Set the correct RPi.GPIO mode. GPIO.setmode(GPIO.BOARD) # Initialize the different classes. motionSensor = ms.MotionSensor(pin_motion_sensor_in) lightSensor = ls.LightSensor(pin_light_sensor_in) relay = r.Relay(pin_relay_out) while 1: if ((relay.lastTimeTurnedOn is not None) and ((relay.lastTimeTurnedOn + timedelta(seconds=5) > datetime.now()))): if (motionSensor.motionDetected): print("Het licht blijft aan, en er is beweging gedetecteerd") relay.lastTimeTurnedOn = datetime.now() relay.turn_on() else: print("Het licht blijft aan") relay.turn_on() else: if (motionSensor.motionDetected): needsLight = lightSensor.is_dark_environment() if (needsLight == True):
def main(): try: wifiInf = raw_input("Enter Wifi interface: ").strip() except: sys.exit(2) # init for net net = OSNetwork(wifiInf) net.macaddr = ''.join( __import__('netifaces').ifaddresses(wifiInf)[17][0] ['addr'].upper().split(':')) net.prefix = prefix net.myNode = net.prefix + "_" + net.macaddr net.default_host = default_host net.default_client = default_client net.default_port = default_port if len(sys.argv) > 1 and sys.argv[1] == 'debug': net.debug = True server_flag = True command = "" while command != "exit": if server_flag: net.set_Adhoc(prefix + "_" + net.macaddr) with Server(net, '0.0.0.0', default_port) as serv: if serv.wait(): continue server_flag = False try: command = raw_input("input command(scan, send, relay, exit): ") except: break if command == "scan": aps = net.get_APs() import parser for ap in aps: if parser.get_prefix(ap) and parser.get_prefix(ap) == prefix: print "SSID: " + ap continue if command == "send": dist = raw_input("input target SSID: ").strip() msg = raw_input("input message: ").strip() import relay rel = relay.Relay(net) rel.send(dist, msg) continue if command == "relay": server_flag = True continue if command != "exit": print "unknown command: " + command print "Bye!"
def __init__(self): for pin in self.pinAssignment: self.relays.append(relay.Relay(pin))
def garage(): logger = log.RotatingFile("/var/log/picontroller/logs") sensorAir = temp_sensor.TempSensor.new(name='AirTemp', sensor="/sys/bus/w1/devices/28-041501b3a6ff/w1_slave") sensorTank = temp_sensor.TempSensor.new(name='TankTemp', sensor="/sys/bus/w1/devices/28-041501ad96ff/w1_slave") sensorDist = dist_sensor.DistSensor.new(sensorTank, echo_pin=13,trig_pin=11, tank_depth=82, name="WaterLevel") pinList = [31,33,35,37] r_airpump = relay.Relay(pin=pinList[0],name='Airpump') r_heater2 = relay.Relay(pin=pinList[1],name='Heater2') r_heater = relay.Relay(pin=pinList[2],name='Heater') r_valve = relay.Relay(pin=pinList[3],name='Valve') r_Active = relay.VirtualRelay(name='Active') r_heater.init() r_airpump.init() r_heater2.init() r_valve.init() r_Active.init() t_airpump = timer.Timer("Airpump") t_airpump.set(timer.S10,timer.S10,timer.S10,timer.S10,timer.S10,timer.S10,timer.S10) webserver.temps.append(sensorAir) webserver.temps.append(sensorTank) webserver.dists.append(sensorDist) webserver.relays.append(r_heater) webserver.relays.append(r_airpump) webserver.relays.append(r_heater2) webserver.relays.append(r_valve) webserver.relays.append(r_Active) webserver.timers.append(t_airpump) webserver.start_server() now = 0 while True: while time.time() < now: time.sleep(1) now = time.time()+60 sensorAir.tick() sensorTank.tick() sensorDist.tick() # VALVE if r_Active.current_state == relay.Relay.ON: if sensorDist.current_value < 55: r_valve.turn_relay_on() if sensorDist.current_value > 62: r_valve.turn_relay_off() # HEATER if sensorTank.current_value > 22: r_heater.turn_relay_off() if sensorTank.current_value < 21: r_heater.turn_relay_on() else: r_heater.turn_relay_off() r_valve.turn_relay_off() # AIRPUMP if t_airpump.on(): r_airpump.turn_relay_on() else: r_airpump.turn_relay_off() timestamp = datetime.datetime.utcnow().isoformat('T')+"000Z" l = "time:{t}\tairtemp:{r}\ttanktemp:{w}\twater:{d}\twatervalve:{r0}\tairpump:{r1}\theater1:{r2}\theater2:{r3}\tactive:{a}".\ format(t=timestamp, r=sensorAir.current_value, w=sensorTank.current_value, d=sensorDist.current_value, r0=r_valve.current_state, r1=r_airpump.current_state, r2=r_heater.current_state, r3=r_heater2.current_state, a=r_Active.current_state) logger.log(l)
def shrimp(): logger = log.RotatingFile("/var/log/picontroller/logs") sensorAir = temp_sensor.TempSensor.new(name='Room', sensor="/sys/bus/w1/devices/28-0315019a7bff/w1_slave") sensorTank = temp_sensor.TempSensor.new(name='Tank', sensor="/sys/bus/w1/devices/28-041501af2dff/w1_slave") pinList = [31,33,35,37] r_heater = relay.Relay(pin=pinList[0],name='Heater') r_fan = relay.Relay(pin=pinList[1],name='Fan') r_light = relay.Relay(pin=pinList[2],name='Light') r_xmas = relay.Relay(pin=pinList[3],name='XMAS') r_heater.init() r_fan.init() r_light.init() r_xmas.init() t_lights = timer.Timer("Lights") t_lights.set(timer.S1,timer.S1,timer.S1,timer.S1,timer.S1,timer.S1,timer.S1) t_xmas = timer.Timer("XMAS") t_xmas.set(timer.ST,timer.ST,timer.ST,timer.ST,timer.ST,timer.ST,timer.ST) webserver.temps.append(sensorAir) webserver.temps.append(sensorTank) webserver.relays.append(r_heater) webserver.relays.append(r_fan) webserver.relays.append(r_light) webserver.relays.append(r_xmas) webserver.timers.append(t_lights) webserver.timers.append(t_xmas) webserver.start_server() now = 0 while True: while time.time() < now: time.sleep(1) now = time.time()+60 sensorAir.tick() sensorTank.tick() # FAN if sensorTank.current_value > 22.8: r_fan.turn_relay_on() if sensorTank.current_value < 22.5: r_fan.turn_relay_off() # HEATER if sensorTank.current_value > 22.5: r_heater.turn_relay_off() if sensorTank.current_value < 22.3: r_heater.turn_relay_on() # LIGHT if t_lights.on(): r_light.turn_relay_on() else: r_light.turn_relay_off() # XMAS Lights if t_xmas.on(): r_xmas.turn_relay_on() else: r_xmas.turn_relay_off() timestamp = datetime.datetime.utcnow().isoformat('T')+"000Z" l = "time:{t}\troom:{r}\ttank:{w}\tlight:{r0}\tfan:{r1}\theater:{r2}\txmas:{r3}".format(t=timestamp, r=sensorAir.current_value, w=sensorTank.current_value, r0=r_light.current_state, r1=r_fan.current_state, r2=r_heater.current_state, r3=r_xmas.current_state) logger.log(l)