class BildgePump(object):
    def __init__(self,
                 name="",
                 float_pin=21,
                 pump_pin=16,
                 min_duration=1,
                 on_when_floating=True):
        self.name = name
        self.float_pin = float_pin
        self.pump_pin = pump_pin
        self.min_duration = min_duration
        self.on_when_floating = on_when_floating
        self.float_sensor = FloatSensor(name="{name} Sensor".format(name=name),
                                        pin=float_pin,
                                        callback_func=self.float_change)
        self.pump = Pump(self.pump_pin)
        self.float_change(self.float_sensor)

    @property
    def uid(self):
        return self.name.lower().replace(" ", "_")

    def float_change(self, sensor):
        if self.float_state == self.on_when_floating:
            self.pump.on()
        else:
            self.pump.off()

    @property
    def float_state(self):
        return self.float_sensor.value == 0

    @property
    def pump_state(self):
        return self.pump.state
class BildgePump(object):

  def __init__(self, name="", float_pin=21, pump_pin=16, min_duration=1, on_when_floating=True):
    self.name = name
    self.float_pin = float_pin
    self.pump_pin = pump_pin
    self.min_duration = min_duration
    self.on_when_floating = on_when_floating
    self.float_sensor = FloatSensor(name="{name} Sensor".format(name=name), pin=float_pin, callback_func=self.float_change)
    self.pump = Pump(self.pump_pin)
    self.float_change(self.float_sensor)

  @property
  def uid(self):
    return self.name.lower().replace(" ", "_")

  def float_change(self, sensor):
    if self.float_state == self.on_when_floating:
      self.pump.on()
    else:
      self.pump.off()

  @property
  def float_state(self):
    return self.float_sensor.value == 0

  @property
  def pump_state(self):
    return self.pump.state
 def __init__(self,
              name="",
              float_pin=21,
              pump_pin=16,
              min_duration=1,
              on_when_floating=True):
     self.name = name
     self.float_pin = float_pin
     self.pump_pin = pump_pin
     self.min_duration = min_duration
     self.on_when_floating = on_when_floating
     self.float_sensor = FloatSensor(name="{name} Sensor".format(name=name),
                                     pin=float_pin,
                                     callback_func=self.float_change)
     self.pump = Pump(self.pump_pin)
     self.float_change(self.float_sensor)
 def __init__(self, name="", float_pin=21, pump_pin=16, min_duration=1, on_when_floating=True):
   self.name = name
   self.float_pin = float_pin
   self.pump_pin = pump_pin
   self.min_duration = min_duration
   self.on_when_floating = on_when_floating
   self.float_sensor = FloatSensor(name="{name} Sensor".format(name=name), pin=float_pin, callback_func=self.float_change)
   self.pump = Pump(self.pump_pin)
   self.float_change(self.float_sensor)
示例#5
0
import sys
sys.path.append("..")

from timer_utils import *
from actuators import LEDs, Fan, Pump
from sensors import TemperatureAndHumidity, SoilHumidity, Camera
from data_logging import FileLogger
import datetime

leds = LEDs(2, active_high=False)
fan = Fan(3, active_high=False)
pump = Pump(4, active_high=False)
temp_and_hum = TemperatureAndHumidity(20)
soil = SoilHumidity(20)
camera = Camera(20)
print(temp_and_hum)

target_temp = 25
target_soil_hum = 50
last_measurements = {}


def log_sensors(log, *args, **kwargs):
    global last_measurements, temp_and_hum, soil
    print('logging sensors')
    t, h = temp_and_hum.sense()
    s = soil.sense()
    last_measurements = {'temperature': t, 'humidity': h, 'soil_humidity': s}
    log.log(last_measurements)

offlinePublishQueueing = int(config["default"]["offlinePublishQueueing"])
drainingFrequency = int(config["default"]["drainingFrequency"])
connectDisconnectTimeout = int(config["default"]["connectDisconnectTimeout"])
MQTTOperationTimeout = int(config["default"]["MQTTOperationTimeout"])
rootCAPath = config["security"]["rootCA"]
certificatePath = config["security"]["certificate"]
privateKeyPath = config["security"]["privateKey"]
device_id = config["default"]["deviceId"]
topic = config["default"]["topic"]

# initialize sensors and actuators
soil = SoilSensor()
uv = UVSensor()
dht22 = DHT22Sensor()
light = GrowLight()
pump0 = Pump(0)
pump1 = Pump(1)
pump2 = Pump(2)
pump3 = Pump(3)
pump4 = Pump(4)
pump5 = Pump(5)
pump6 = Pump(6)
pump7 = Pump(7)

# initialize AWS IoT MQTT client
client = AWSIoTMQTTClient(device_id)
client.configureEndpoint(endpoint, port)
client.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
client.configureOfflinePublishQueueing(offlinePublishQueueing)
client.configureDrainingFrequency(drainingFrequency)
client.configureConnectDisconnectTimeout(connectDisconnectTimeout)