예제 #1
0
def connect_sensors(sensors, uids, ipcon):
    """
	Creates Bricklet Instances
	:param sensors: connected sensors, as dictionary
	:param uids: bricklets uids, as dictionary
	:param ipcon: ipconnection from tinkerforge
	:return: Dictionary with all instances from connected sensors
	"""
    # Dictionary with all connected sensors
    con_sensors = {}
    for sensor in sensors:
        if sensor == "ambient_light":
            al = BrickletAmbientLightV2(uids["ambient_light"], ipcon)
            con_sensors.update({"ambient_light": al})
        if sensor == "barometer":
            barometer = BrickletBarometer(uids["barometer"], ipcon)
            con_sensors.update({"barometer": barometer})
        if sensor == "humidity":
            humidity = BrickletHumidity(uids["humidity"], ipcon)
            con_sensors.update({"humidity": humidity})
        if sensor == "lcd":
            lcd = BrickletLCD20x4(uids["lcd"], ipcon)
            con_sensors.update({"lcd": lcd})
        if sensor == "moisture":
            moisture = BrickletMoisture(uids["moisture"], ipcon)
            con_sensors.update({"moisture": moisture})
        if sensor == "temperature":
            temperature = BrickletTemperature(uids["temperature"], ipcon)
            con_sensors.update({"temperature": temperature})
        if sensor == "thermocouple":
            thermo = BrickletThermocouple(uids["thermocouple"], ipcon)
            con_sensors.update({"thermocouple": thermo})
    return con_sensors
예제 #2
0
def connect_sensors():
    global al
    global barometer
    global humidity
    global lcd
    global moisture
    global temperature
    global thermo

    if sensors["ambient_light"] == 1:
        al = BrickletAmbientLightV2(UID_AMBIENT, ipcon)
    if sensors["barometer"] == 1:
        barometer = BrickletBarometer(UID_BAROMETER, ipcon)
    if sensors["humidity"] == 1:
        humidity = BrickletHumidity(UID_HUMIDITY, ipcon)
    if sensors["lcd"] == 1:
        lcd = BrickletLCD20x4(UID_LCD, ipcon)
    if sensors["moisture"] == 1:
        moisture = BrickletMoisture(UID_MOISTURE, ipcon)
    if sensors["temperature"] == 1:
        temperature = BrickletTemperature(UID_TEMPERATURE, ipcon)
    if sensors["thermo_couple"] == 1:
        thermo = BrickletThermocouple(UID_THERMO, ipcon)
예제 #3
0
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Moisture Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_moisture import BrickletMoisture

# Callback function for moisture value reached callback
def cb_moisture_reached(moisture):
    print("Moisture Value: " + str(moisture))

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    m = BrickletMoisture(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get threshold callbacks with a debounce time of 1 second (1000ms)
    m.set_debounce_period(1000)

    # Register moisture value reached callback to function cb_moisture_reached
    m.register_callback(m.CALLBACK_MOISTURE_REACHED, cb_moisture_reached)

    # Configure threshold for moisture value "greater than 200"
    m.set_moisture_callback_threshold(">", 200, 0)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
    def onHeartbeat(self):
        self.HeartbeatCounter = self.HeartbeatCounter + 1
        Domoticz.Debug("onHeartbeat called. Counter=" + str(self.HeartbeatCounter * self.HeartbeatInterval) + " (Heartbeat=" + Parameters["Mode5"] + ")")
        # Flag to check if connected to the master brick
        self.ipConnected = 0

        # check the heartbeatcounter against the heartbeatinterval
        if (self.HeartbeatCounter * self.HeartbeatInterval) % int(Parameters["Mode5"]) == 0:
            # Get the moisture value
            try:
                # Create IP connection
                ipcon = IPConnection()
            
                # Create device objects using the UID as defined in the parameter Mode1
                # The string contains multiple UIDs separated by comma (,). This enables to define more bricklets.
                brickletUIDParam = Parameters["Mode1"]
                Domoticz.Debug("UIDs:" + brickletUIDParam )
                # Split the parameter string into a list of UIDs
                brickletUIDList = brickletUIDParam.split(',')
                # Check the list length (3 because 3 bricklet UIDs) and create the device objects
                if len(brickletUIDList) == 3:
                    mb = BrickletMoisture(brickletUIDList[0], ipcon)
                    sb = BrickletSegmentDisplay4x7(brickletUIDList[1], ipcon)
                    lb = BrickletRGBLED(brickletUIDList[2], ipcon)

                # Connect to brickd using Host and Port
                try:
                    ipcon.connect(Parameters["Address"], int(Parameters["Port"]))
                    self.ipConnected = 1
                    Domoticz.Debug("IP Connection - OK")
                except:
                    Domoticz.Debug("[ERROR] IP Connection failed")

                # Don't use device before ipcon is connected
                if self.ipConnected == 0:
                    Devices[2].Update( nValue=0, sValue="[ERROR] Can not connect to Master Brick. Check settings, correct and restart Domoticz." )
                    Domoticz.Log(Devices[2].sValue)
                    return

                # Get current moisture value
                moisturetf = mb.get_moisture_value()
                Domoticz.Debug("Tinkerforge value:" + str(moisturetf) )
                moisturedom = converttfvalue(moisturetf)
                Domoticz.Debug("Domoticz value:" + str(moisturedom) )

                # Moisture Device and Text Device
                # Update the value - only nValue is used, but mandatory to add an sValue
                Devices[1].Update( nValue=moisturedom, sValue="0")

                # Tinkerforge Bricklet Updates

                # Segment Display set the value between 0(dry) - 100(wet)
                # Inverse the Domoticz moisure value
                moistureled = DOMOTICZMOISTUREDRY - moisturedom
                l = list(str(moistureled))
                # dry
                if  len(l) == 1:
                    segments = (DIGITS[0], DIGITS[0], DIGITS[0], DIGITS[int(l[0])])

                # irrigation advice
                if  len(l) == 2:
                    segments = (DIGITS[0], DIGITS[0], DIGITS[int(l[0])], DIGITS[int(l[1])])

                # adequate
                if  len(l) == 3:
                    segments = (DIGITS[0], DIGITS[int(l[0])], DIGITS[int(l[1])], DIGITS[int(l[2])])

                # not used
                if  len(l) == 4:
                    segments = (DIGITS[int(l[0])], DIGITS[int(l[1])], DIGITS[int(l[2])], DIGITS[int(l[3])])

                # Write the moisture value to the display with full brightness without colon
                sb.set_segments(segments, 7, False)        
                Domoticz.Debug("Segment Display updated")

                # Set the color of the RGB LED indicator
                # The indicator uses own scheme to keep simple: dry < 20; irrigation advice 20-40; wet > 40
                Domoticz.Debug("RGB LED updated. Brightness=" + Parameters["Mode4"])
                lbbrightness = int(Parameters["Mode4"])
                if lbbrightness < RGBBRIGHTNESSMIN:
                    lbbrightness = RGBBRIGHTNESSMIN
                if lbbrightness > RGBBRIGHTNESSMAX:
                    lbbrightness = RGBBRIGHTNESSMIN

                # Turn the LED on with color RGB depending LED value - 0(dry) - 100(wet)
                # dry = RED
                if moistureled < 20:
                    lb.set_rgb_value(lbbrightness, 0, 0)

                # irrigation advice = YELLOW
                if moistureled >= 20 and moistureled <= 40:
                    lb.set_rgb_value(lbbrightness, lbbrightness, 0)
                
                # wet = GREEN
                if moistureled > 40:
                    lb.set_rgb_value(0, lbbrightness, 0)
               
                # Disconnect
                ipcon.disconnect()

                # Log Message
                Devices[2].Update( nValue=0, sValue="Polling OK: TF=" + str(moisturetf)+", Dom="+str(moisturedom)+", LED="+str(moistureled))
                Domoticz.Log(Devices[2].sValue)

            except:
                # Error
                # Important to close the connection - if not, the plugin can not be disabled
                if self.ipConnected == 1:
                    ipcon.disconnect()
            
                Devices[2].Update( nValue=0, sValue="[ERROR] Check settings, correct and restart Domoticz." )
                Domoticz.Log(Devices[2].sValue)
예제 #5
0
 def create_instance(self, uid, ipcon):
     return BrickletMoisture(uid, ipcon)
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Moisture Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_moisture import BrickletMoisture

# Callback function for moisture value callback
def cb_moisture(moisture):
    print("Moisture Value: " + str(moisture))

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    m = BrickletMoisture(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Register moisture value callback to function cb_moisture
    m.register_callback(m.CALLBACK_MOISTURE, cb_moisture)

    # Set period for moisture value callback to 1s (1000ms)
    # Note: The moisture value callback is only called every second
    #       if the moisture value has changed since the last call!
    m.set_moisture_callback_period(1000)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
예제 #7
0
HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Moisture Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_moisture import BrickletMoisture


# Callback function for moisture value callback
def cb_moisture(moisture):
    print("Moisture Value: " + str(moisture))


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    m = BrickletMoisture(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Register moisture value callback to function cb_moisture
    m.register_callback(m.CALLBACK_MOISTURE, cb_moisture)

    # Set period for moisture value callback to 1s (1000ms)
    # Note: The moisture value callback is only called every second
    #       if the moisture value has changed since the last call!
    m.set_moisture_callback_period(1000)

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
예제 #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Moisture Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_moisture import BrickletMoisture

if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    m = BrickletMoisture(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current moisture value
    moisture = m.get_moisture_value()
    print("Moisture Value: " + str(moisture))

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()