error correction
This commit is contained in:
parent
371108fd7e
commit
b0a3f6b711
@ -16,17 +16,17 @@ class mqtt:
|
||||
def connect(self):
|
||||
if not self.__is_connected:
|
||||
self.__client.on_connect = self.__on_connect
|
||||
result = self.__client.connect(self.__hostname, self.__port, self.__keepalive)
|
||||
result |= self.__client.loop_start()
|
||||
if 0 == result:
|
||||
self.__is_connected = True
|
||||
return True
|
||||
self.__client.connect(self.__hostname, self.__port, self.__keepalive)
|
||||
self.__client.loop_start()
|
||||
self.__is_connected = True
|
||||
return True
|
||||
return False
|
||||
|
||||
def disconnect(self):
|
||||
if self.__is_connected:
|
||||
self.__client.loop_stop()
|
||||
self.__client.disconnect()
|
||||
self.__is_connected = False
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from gpio import gpio.gpio
|
||||
from gpio.gpio import gpio
|
||||
|
||||
class engine:
|
||||
def __init__(self, gpio_1 = 13, gpio_2 = 19):
|
||||
|
32
src/gate/gate_handler.py
Normal file
32
src/gate/gate_handler.py
Normal file
@ -0,0 +1,32 @@
|
||||
'''
|
||||
Created on Dec 19, 2016
|
||||
|
||||
@author: klaehn
|
||||
'''
|
||||
|
||||
from engine.engine import engine
|
||||
from power_sensor.power_sensor import power_sensor
|
||||
from time import time
|
||||
import numpy as np
|
||||
|
||||
class gate_handler:
|
||||
def __init__(self):
|
||||
self.__engine = engine(13, 19)
|
||||
self.__power_sensor = power_sensor(1, 0x40)
|
||||
self.__max_current_up = 315
|
||||
self.__max_current_down = 280
|
||||
self.__max_time_open = 250
|
||||
self.__max_time_close = 250
|
||||
self.__timeout_open = 0
|
||||
self.__timeout_close = 0
|
||||
return
|
||||
|
||||
def open(self):
|
||||
self.__timeout_open = time() + self.__max_time_open
|
||||
self.__engine.run_up()
|
||||
power = np.array([])
|
||||
timestamps = np.array([])
|
||||
while(time() < self.__max_time_open):
|
||||
timestamps = np.append(timestamps, time())
|
||||
power = np.append(power, self.__power_sensor.power_mw())
|
||||
|
@ -8,7 +8,7 @@ import time
|
||||
|
||||
class gate_guard:
|
||||
def __init__(self):
|
||||
self.__light_read_delay_s = 6
|
||||
self.__light_read_delay_s = 60
|
||||
self.__consequtive_light_reads = 10
|
||||
self.__light_lx_close = 0
|
||||
self.__light_lx_open = 0
|
||||
@ -24,6 +24,7 @@ class gate_guard:
|
||||
self.__comserver.connect()
|
||||
self.__comserver.transmit(topic, payload)
|
||||
self.__comserver.disconnect()
|
||||
self.__gate_state.set_state("close")
|
||||
return None
|
||||
|
||||
def open_gate(self):
|
||||
@ -32,6 +33,7 @@ class gate_guard:
|
||||
self.__comserver.connect()
|
||||
self.__comserver.transmit(topic, payload)
|
||||
self.__comserver.disconnect()
|
||||
self.__gate_state.set_state("open")
|
||||
return None
|
||||
|
||||
def handle_gate_state(self, light_avg=0):
|
||||
@ -39,22 +41,21 @@ class gate_guard:
|
||||
if light_avg <= self.__light_lx_close:
|
||||
self.close_gate()
|
||||
elif self.__gate_state.get_state() == "close":
|
||||
if light_avg >= self.__light_lx_open:
|
||||
if light_avg > self.__light_lx_open:
|
||||
self.open_gate()
|
||||
elif self.__gate_state.get_state() == "unknown":
|
||||
'''TODO: bring gate in a defined position'''
|
||||
|
||||
def run(self):
|
||||
|
||||
if self.__gate_state.get_state() == "unknown":
|
||||
self.handle_gate_state()
|
||||
self.__gate_state.set_state("open")
|
||||
|
||||
try:
|
||||
while True:
|
||||
light_data.push(light_sensor.read())
|
||||
light_avg = light_data.average()
|
||||
if light_avg:
|
||||
print "light average: " + str(light_avg)
|
||||
rd = self.__light_sensor.read()
|
||||
self.__light_data.push(rd)
|
||||
light_avg = self.__light_data.average()
|
||||
if light_avg != None:
|
||||
self.handle_gate_state(light_avg)
|
||||
time.sleep(self.__light_read_delay_s)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user